mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-06 22:15:22 +02:00
Feature/user photo storage (#877)
* add default assets for user profile * add recipe avatar * change user_id to UUID * add profile image upload * setup image cache keys * cleanup tests and add image tests * purge user data on delete * new user repository tests * add user_id validator for int -> UUID conversion * delete depreciated route * force set content type * refactor tests to use temp directory * validate parent exists before createing * set user_id to correct type * update instruction id * reset primary key on migration
This commit is contained in:
parent
a2f8f27193
commit
ea7c4771ee
64 changed files with 433 additions and 181 deletions
|
@ -1,8 +1,9 @@
|
|||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import UUID4
|
||||
|
||||
|
||||
class SetPermissions(CamelModel):
|
||||
user_id: int
|
||||
user_id: UUID4
|
||||
can_manage: bool = False
|
||||
can_invite: bool = False
|
||||
can_organize: bool = False
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
from uuid import UUID, uuid4
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from pydantic import UUID4, BaseModel, Field, validator
|
||||
from pydantic.utils import GetterDict
|
||||
from slugify import slugify
|
||||
|
||||
|
@ -63,8 +63,8 @@ class CreateRecipe(CamelModel):
|
|||
class RecipeSummary(CamelModel):
|
||||
id: Optional[int]
|
||||
|
||||
user_id: int = 0
|
||||
group_id: UUID = Field(default_factory=uuid4)
|
||||
user_id: UUID4 = Field(default_factory=uuid4)
|
||||
group_id: UUID4 = Field(default_factory=uuid4)
|
||||
|
||||
name: Optional[str]
|
||||
slug: str = ""
|
||||
|
@ -109,6 +109,12 @@ class RecipeSummary(CamelModel):
|
|||
return uuid4()
|
||||
return group_id
|
||||
|
||||
@validator("user_id", always=True, pre=True)
|
||||
def validate_user_id(user_id: list[Any]):
|
||||
if isinstance(user_id, int):
|
||||
return uuid4()
|
||||
return user_id
|
||||
|
||||
|
||||
class Recipe(RecipeSummary):
|
||||
recipe_ingredient: Optional[list[RecipeIngredient]] = []
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
|||
from uuid import UUID
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import UUID4
|
||||
|
||||
|
||||
class UserBase(CamelModel):
|
||||
|
@ -20,7 +21,7 @@ class RecipeCommentCreate(CamelModel):
|
|||
|
||||
|
||||
class RecipeCommentSave(RecipeCommentCreate):
|
||||
user_id: int
|
||||
user_id: UUID4
|
||||
|
||||
|
||||
class RecipeCommentUpdate(CamelModel):
|
||||
|
@ -33,7 +34,7 @@ class RecipeCommentOut(RecipeCommentCreate):
|
|||
recipe_id: int
|
||||
created_at: datetime
|
||||
update_at: datetime
|
||||
user_id: int
|
||||
user_id: UUID4
|
||||
user: UserBase
|
||||
|
||||
class Config:
|
||||
|
|
|
@ -32,7 +32,7 @@ class LongLiveTokenOut(LoingLiveTokenIn):
|
|||
|
||||
|
||||
class CreateToken(LoingLiveTokenIn):
|
||||
parent_id: int
|
||||
user_id: UUID4
|
||||
token: str
|
||||
|
||||
class Config:
|
||||
|
@ -88,10 +88,11 @@ class UserIn(UserBase):
|
|||
|
||||
|
||||
class UserOut(UserBase):
|
||||
id: int
|
||||
id: UUID4
|
||||
group: str
|
||||
group_id: UUID4
|
||||
tokens: Optional[list[LongLiveTokenOut]]
|
||||
cache_key: str
|
||||
favorite_recipes: Optional[list[str]] = []
|
||||
|
||||
class Config:
|
||||
|
@ -127,6 +128,15 @@ class PrivateUser(UserOut):
|
|||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@staticmethod
|
||||
def get_directory(user_id: UUID4) -> Path:
|
||||
user_dir = get_app_dirs().USER_DIR / str(user_id)
|
||||
user_dir.mkdir(parents=True, exist_ok=True)
|
||||
return user_dir
|
||||
|
||||
def directory(self) -> Path:
|
||||
return PrivateUser.get_directory(self.id)
|
||||
|
||||
|
||||
class UpdateGroup(GroupBase):
|
||||
id: UUID4
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import UUID4
|
||||
|
||||
from .user import PrivateUser
|
||||
|
||||
|
@ -18,7 +19,7 @@ class ResetPassword(ValidateResetToken):
|
|||
|
||||
|
||||
class SavePasswordResetToken(CamelModel):
|
||||
user_id: int
|
||||
user_id: UUID4
|
||||
token: str
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue