feat(backend): migrate site-settings to groups (#673)

* feat(frontend):  add user registration page (WIP)

* feat(backend):  add user registration (WIP)

* test(backend):  add validator testing for registration schema

* feat(backend):  continued work on user sign-up

* feat(backend):  add signup flow and user/group settings

* test(backend):  user-creation tests and small refactor of existing tests

* fix(backend):  fix failing group tests

* style: 🎨 fix lint issues

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-09-05 22:05:29 -08:00
committed by GitHub
parent e179dcdb10
commit 3c504e7048
63 changed files with 1665 additions and 841 deletions

View File

@@ -0,0 +1,25 @@
from fastapi_camelcase import CamelModel
class UpdateGroupPreferences(CamelModel):
private_group: bool = False
first_day_of_week: int = 0
# Recipe Defaults
recipe_public: bool = True
recipe_show_nutrition: bool = False
recipe_show_assets: bool = False
recipe_landscape_view: bool = False
recipe_disable_comments: bool = False
recipe_disable_amount: bool = False
class CreateGroupPreferences(UpdateGroupPreferences):
group_id: int
class ReadGroupPreferences(CreateGroupPreferences):
id: int
class Config:
orm_mode = True

View File

@@ -0,0 +1,29 @@
from fastapi_camelcase import CamelModel
from pydantic import validator
from pydantic.types import constr
class CreateUserRegistration(CamelModel):
group: str = None
group_token: str = None
email: constr(to_lower=True, strip_whitespace=True)
username: constr(to_lower=True, strip_whitespace=True)
password: str
password_confirm: str
advanced: bool = False
private: bool = False
@validator("password_confirm")
@classmethod
def passwords_match(cls, value, values):
if "password" in values and value != values["password"]:
raise ValueError("passwords do not match")
return value
@validator("group_token", always=True)
@classmethod
def group_or_token(cls, value, values):
if bool(value) is False and bool(values["group"]) is False:
raise ValueError("group or group_token must be provided")
return value

View File

@@ -6,8 +6,8 @@ from pydantic.types import constr
from pydantic.utils import GetterDict
from mealie.core.config import settings
from mealie.db.models.group import Group
from mealie.db.models.users import User
from mealie.schema.group.group_preferences import ReadGroupPreferences
from mealie.schema.recipe import RecipeSummary
from ..meal_plan import MealPlanOut, ShoppingListOut
@@ -50,8 +50,9 @@ class UserBase(CamelModel):
username: Optional[str]
full_name: Optional[str] = None
email: constr(to_lower=True, strip_whitespace=True)
admin: bool
admin: bool = False
group: Optional[str]
advanced: bool = False
favorite_recipes: Optional[list[str]] = []
class Config:
@@ -128,16 +129,11 @@ class GroupInDB(UpdateGroup):
users: Optional[list[UserOut]]
mealplans: Optional[list[MealPlanOut]]
shopping_lists: Optional[list[ShoppingListOut]]
preferences: Optional[ReadGroupPreferences] = None
class Config:
orm_mode = True
@classmethod
def getter_dict(_cls, orm_model: Group):
return {
**GetterDict(orm_model),
}
class LongLiveTokenInDB(CreateToken):
id: int