feat: additional events dispatch (#1999)
* formatting * add new user type * add registration event * publish events on new mealplan * update UI for supported types + type updates
This commit is contained in:
parent
c33b14e3d2
commit
fc92c39b7c
5 changed files with 177 additions and 124 deletions
|
@ -3,7 +3,7 @@
|
|||
<BaseDialog
|
||||
v-model="deleteDialog"
|
||||
color="error"
|
||||
:title="$t('general.confirm')"
|
||||
:title="$tc('general.confirm')"
|
||||
:icon="$globals.icons.alertCircle"
|
||||
@confirm="deleteNotifier(deleteTargetId)"
|
||||
>
|
||||
|
@ -35,8 +35,6 @@
|
|||
</div>
|
||||
</BasePageTitle>
|
||||
|
||||
<BannerExperimental issue="https://github.com/hay-kot/mealie/issues/833" />
|
||||
|
||||
<BaseButton create @click="createDialog = true" />
|
||||
<v-expansion-panels v-if="notifiers" class="mt-2">
|
||||
<v-expansion-panel v-for="(notifier, index) in notifiers" :key="index" class="my-2 left-border rounded">
|
||||
|
@ -59,36 +57,38 @@
|
|||
|
||||
<v-divider></v-divider>
|
||||
<p class="pt-4">What events should this notifier subscribe to?</p>
|
||||
<template v-for="(opt, idx) in optionsKeys">
|
||||
<div class="notifier-options">
|
||||
<section v-for="sec in optionsSections" :key="sec.id">
|
||||
<h4>
|
||||
{{ sec.text }}
|
||||
</h4>
|
||||
<v-checkbox
|
||||
v-if="!opt.divider"
|
||||
:key="'option-' + idx"
|
||||
v-for="opt in sec.options"
|
||||
:key="opt.key"
|
||||
v-model="notifiers[index].options[opt.key]"
|
||||
hide-details
|
||||
dense
|
||||
:label="opt.text"
|
||||
></v-checkbox>
|
||||
<div v-else :key="'divider-' + idx" class="mt-4">
|
||||
{{ opt.text }}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<v-card-actions class="py-0">
|
||||
<v-spacer></v-spacer>
|
||||
<BaseButtonGroup
|
||||
:buttons="[
|
||||
{
|
||||
icon: $globals.icons.delete,
|
||||
text: $t('general.delete'),
|
||||
text: $tc('general.delete'),
|
||||
event: 'delete',
|
||||
},
|
||||
{
|
||||
icon: $globals.icons.testTube,
|
||||
text: $t('general.test'),
|
||||
text: $tc('general.test'),
|
||||
event: 'test',
|
||||
},
|
||||
{
|
||||
icon: $globals.icons.save,
|
||||
text: $t('general.save'),
|
||||
text: $tc('general.save'),
|
||||
event: 'save',
|
||||
},
|
||||
]"
|
||||
|
@ -110,12 +110,14 @@ import { GroupEventNotifierCreate, GroupEventNotifierOut } from "~/lib/api/types
|
|||
|
||||
interface OptionKey {
|
||||
text: string;
|
||||
key: string;
|
||||
key: keyof GroupEventNotifierOut["options"];
|
||||
}
|
||||
|
||||
interface OptionDivider {
|
||||
divider: true;
|
||||
|
||||
interface OptionSection {
|
||||
id: number;
|
||||
text: string;
|
||||
options: OptionKey[];
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
|
@ -173,11 +175,11 @@ export default defineComponent({
|
|||
// Options Definitions
|
||||
const { i18n } = useContext();
|
||||
|
||||
const optionsKeys: (OptionKey | OptionDivider)[] = [
|
||||
const optionsSections: OptionSection[] = [
|
||||
{
|
||||
divider: true,
|
||||
id: 1,
|
||||
text: "Recipe Events",
|
||||
},
|
||||
options: [
|
||||
{
|
||||
text: i18n.t("general.create") as string,
|
||||
key: "recipeCreated",
|
||||
|
@ -190,42 +192,32 @@ export default defineComponent({
|
|||
text: i18n.t("general.delete") as string,
|
||||
key: "recipeDeleted",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "User Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
text: "User Events",
|
||||
options: [
|
||||
{
|
||||
text: "When a new user joins your group",
|
||||
key: "userSignup",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "Data Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
text: "When a new data migration is completed",
|
||||
key: "dataMigrations",
|
||||
},
|
||||
{
|
||||
text: "When a data export is completed",
|
||||
key: "dataExport",
|
||||
},
|
||||
{
|
||||
text: "When a data import is completed",
|
||||
key: "dataImport",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
id: 3,
|
||||
text: "Mealplan Events",
|
||||
},
|
||||
options: [
|
||||
{
|
||||
text: "When a user in your group creates a new mealplan",
|
||||
key: "mealplanEntryCreated",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "Shopping List Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
text: "Shopping List Events",
|
||||
options: [
|
||||
{
|
||||
text: i18n.t("general.create") as string,
|
||||
key: "shoppingListCreated",
|
||||
|
@ -238,10 +230,12 @@ export default defineComponent({
|
|||
text: i18n.t("general.delete") as string,
|
||||
key: "shoppingListDeleted",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "Cookbook Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
text: "Cookbook Events",
|
||||
options: [
|
||||
{
|
||||
text: i18n.t("general.create") as string,
|
||||
key: "cookbookCreated",
|
||||
|
@ -254,10 +248,12 @@ export default defineComponent({
|
|||
text: i18n.t("general.delete") as string,
|
||||
key: "cookbookDeleted",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "Tag Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
text: "Tag Events",
|
||||
options: [
|
||||
{
|
||||
text: i18n.t("general.create") as string,
|
||||
key: "tagCreated",
|
||||
|
@ -270,10 +266,12 @@ export default defineComponent({
|
|||
text: i18n.t("general.delete") as string,
|
||||
key: "tagDeleted",
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
text: "Category Events",
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
text: "Category Events",
|
||||
options: [
|
||||
{
|
||||
text: i18n.t("general.create") as string,
|
||||
key: "categoryCreated",
|
||||
|
@ -286,14 +284,16 @@ export default defineComponent({
|
|||
text: i18n.t("general.delete") as string,
|
||||
key: "categoryDeleted",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
openDelete,
|
||||
optionsKeys,
|
||||
notifiers,
|
||||
createNotifierData,
|
||||
optionsSections,
|
||||
deleteNotifier,
|
||||
testNotifier,
|
||||
saveNotifier,
|
||||
|
@ -305,3 +305,11 @@ export default defineComponent({
|
|||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.notifier-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -5,7 +5,8 @@ from fastapi import APIRouter, Depends, HTTPException
|
|||
|
||||
from mealie.core.exceptions import mealie_registered_exceptions
|
||||
from mealie.repos.repository_meals import RepositoryMeals
|
||||
from mealie.routes._base import BaseUserController, controller
|
||||
from mealie.routes._base import controller
|
||||
from mealie.routes._base.base_controllers import BaseCrudController
|
||||
from mealie.routes._base.mixins import HttpRepo
|
||||
from mealie.schema import mapper
|
||||
from mealie.schema.meal_plan import CreatePlanEntry, ReadPlanEntry, SavePlanEntry, UpdatePlanEntry
|
||||
|
@ -14,12 +15,13 @@ from mealie.schema.meal_plan.plan_rules import PlanRulesDay
|
|||
from mealie.schema.recipe.recipe import Recipe
|
||||
from mealie.schema.response.pagination import PaginationQuery
|
||||
from mealie.schema.response.responses import ErrorResponse
|
||||
from mealie.services.event_bus_service.event_types import EventMealplanCreatedData, EventTypes
|
||||
|
||||
router = APIRouter(prefix="/groups/mealplans", tags=["Groups: Mealplans"])
|
||||
|
||||
|
||||
@controller(router)
|
||||
class GroupMealplanController(BaseUserController):
|
||||
class GroupMealplanController(BaseCrudController):
|
||||
@cached_property
|
||||
def repo(self) -> RepositoryMeals:
|
||||
return self.repos.meals.by_group(self.group_id)
|
||||
|
@ -117,7 +119,21 @@ class GroupMealplanController(BaseUserController):
|
|||
@router.post("", response_model=ReadPlanEntry, status_code=201)
|
||||
def create_one(self, data: CreatePlanEntry):
|
||||
data = mapper.cast(data, SavePlanEntry, group_id=self.group.id)
|
||||
return self.mixins.create_one(data)
|
||||
result = self.mixins.create_one(data)
|
||||
|
||||
self.publish_event(
|
||||
event_type=EventTypes.mealplan_entry_created,
|
||||
document_data=EventMealplanCreatedData(
|
||||
mealplan_id=result.id,
|
||||
recipe_id=data.recipe_id,
|
||||
recipe_name=result.recipe.name if result.recipe else None,
|
||||
recipe_slug=result.recipe.slug if result.recipe else None,
|
||||
date=data.date,
|
||||
),
|
||||
message=f"Mealplan entry created for {data.date} for {data.entry_type}",
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@router.get("/{item_id}", response_model=ReadPlanEntry)
|
||||
def get_one(self, item_id: int):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from fastapi import APIRouter, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from mealie.core.config import get_app_settings
|
||||
from mealie.repos.all_repositories import get_repositories
|
||||
|
@ -6,6 +6,8 @@ from mealie.routes._base import BasePublicController, controller
|
|||
from mealie.schema.response import ErrorResponse
|
||||
from mealie.schema.user.registration import CreateUserRegistration
|
||||
from mealie.schema.user.user import UserOut
|
||||
from mealie.services.event_bus_service.event_bus_service import EventBusService
|
||||
from mealie.services.event_bus_service.event_types import EventTypes, EventUserSignupData
|
||||
from mealie.services.user_services.registration_service import RegistrationService
|
||||
|
||||
router = APIRouter(prefix="/register")
|
||||
|
@ -13,6 +15,8 @@ router = APIRouter(prefix="/register")
|
|||
|
||||
@controller(router)
|
||||
class RegistrationController(BasePublicController):
|
||||
event_bus: EventBusService = Depends(EventBusService.create)
|
||||
|
||||
@router.post("", response_model=UserOut, status_code=status.HTTP_201_CREATED)
|
||||
def register_new_user(self, data: CreateUserRegistration):
|
||||
settings = get_app_settings()
|
||||
|
@ -29,4 +33,13 @@ class RegistrationController(BasePublicController):
|
|||
self.translator,
|
||||
)
|
||||
|
||||
return registration_service.register_user(data)
|
||||
result = registration_service.register_user(data)
|
||||
|
||||
self.event_bus.dispatch(
|
||||
integration_id="registration",
|
||||
group_id=result.group_id,
|
||||
event_type=EventTypes.user_signup,
|
||||
document_data=EventUserSignupData(username=result.username, email=result.email),
|
||||
)
|
||||
|
||||
return result
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import uuid
|
||||
from datetime import datetime
|
||||
from datetime import date, datetime
|
||||
from enum import Enum, auto
|
||||
from typing import Any
|
||||
|
||||
|
@ -57,6 +57,8 @@ class EventTypes(Enum):
|
|||
class EventDocumentType(Enum):
|
||||
generic = "generic"
|
||||
|
||||
user = "user"
|
||||
|
||||
category = "category"
|
||||
cookbook = "cookbook"
|
||||
mealplan = "mealplan"
|
||||
|
@ -82,6 +84,23 @@ class EventDocumentDataBase(MealieModel):
|
|||
...
|
||||
|
||||
|
||||
class EventMealplanCreatedData(EventDocumentDataBase):
|
||||
document_type = EventDocumentType.mealplan
|
||||
operation = EventOperation.create
|
||||
mealplan_id: int
|
||||
date: date
|
||||
recipe_id: UUID4 | None
|
||||
recipe_name: str | None
|
||||
recipe_slug: str | None
|
||||
|
||||
|
||||
class EventUserSignupData(EventDocumentDataBase):
|
||||
document_type = EventDocumentType.user
|
||||
operation = EventOperation.create
|
||||
username: str
|
||||
email: str
|
||||
|
||||
|
||||
class EventCategoryData(EventDocumentDataBase):
|
||||
document_type = EventDocumentType.category
|
||||
category_id: UUID4
|
||||
|
|
|
@ -70,7 +70,6 @@ class RegistrationService:
|
|||
if registration.group:
|
||||
new_group = True
|
||||
group = self._register_new_group()
|
||||
|
||||
elif registration.group_token and registration.group_token != "":
|
||||
token_entry = self.repos.group_invite_tokens.get_one(registration.group_token)
|
||||
if not token_entry:
|
||||
|
@ -88,9 +87,7 @@ class RegistrationService:
|
|||
user = self._create_new_user(group, new_group)
|
||||
|
||||
if new_group and registration.seed_data:
|
||||
|
||||
seeder_service = SeederService(self.repos, user, group)
|
||||
|
||||
seeder_service.seed_foods(registration.locale)
|
||||
seeder_service.seed_labels(registration.locale)
|
||||
seeder_service.seed_units(registration.locale)
|
||||
|
|
Loading…
Reference in a new issue