feat: add initial notification support

* Add updated recipe notification

* Add recipe deleted notification

* Add notifications translations

* Shopping lists full c/u/d notifications

* Add categories c/u/d notifications

* Deal with None values in translation provider

* Add tag c/u/d notifications

* Add cookbook c/u/d notifications

* use single key pairs for consistency with frontend

* change dependency injection strategy

* use generic update messages

* use service to manage url generation server-side

* use new strategies for messages

* fix translator

Co-authored-by: Miroito <alban.vachette@gmail.com>
This commit is contained in:
Hayden
2022-05-21 10:23:55 -08:00
committed by GitHub
parent 841b560abc
commit b2066dfe72
12 changed files with 244 additions and 24 deletions

View File

@@ -0,0 +1 @@
from .url_constructors import *

View File

@@ -0,0 +1,36 @@
from pydantic import UUID4
from mealie.core.config import get_app_settings
def _base_or(base_url: str | None) -> str:
if base_url is None:
settings = get_app_settings()
return settings.BASE_URL
return base_url
def recipe_url(recipe_slug: str, base_url: str | None) -> str:
base = _base_or(base_url)
return f"{base}/recipe/{recipe_slug}"
def shopping_list_url(shopping_list_id: UUID4 | str, base_url: str | None) -> str:
base = _base_or(base_url)
return f"{base}/shopping-list/{shopping_list_id}"
def tag_url(tag_slug: str, base_url: str | None) -> str:
base = _base_or(base_url)
return f"{base}/recipes/tags/{tag_slug}"
def category_url(category_slug: str, base_url: str | None) -> str:
base = _base_or(base_url)
return f"{base}/recipes/categories/{category_slug}"
def tool_url(tool_slug: str, base_url: str | None) -> str:
base = _base_or(base_url)
return f"{base}/recipes/tool/{tool_slug}"

View File

@@ -17,10 +17,10 @@ class RegistrationService:
logger: Logger
repos: AllRepositories
def __init__(self, logger: Logger, db: AllRepositories, t: Translator):
def __init__(self, logger: Logger, db: AllRepositories, translator: Translator):
self.logger = logger
self.repos = db
self.t = t
self.t = translator.t
def _create_new_user(self, group: GroupInDB, new_group: bool) -> PrivateUser:
new_user = UserIn(
@@ -58,9 +58,9 @@ class RegistrationService:
self.registration = registration
if self.repos.users.get_by_username(registration.username):
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t.t("exceptions.username-conflict-error")})
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t("exceptions.username-conflict-error")})
elif self.repos.users.get(registration.email, "email"):
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t.t("exceptions.email-conflict-error")})
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t("exceptions.email-conflict-error")})
self.logger.info(f"Registering user {registration.username}")
token_entry = None