diff --git a/src/app/domain/accounts/controllers/access.py b/src/app/domain/accounts/controllers/access.py index 1cbed0b3..6a0dd818 100644 --- a/src/app/domain/accounts/controllers/access.py +++ b/src/app/domain/accounts/controllers/access.py @@ -17,6 +17,7 @@ from app.domain.accounts.guards import auth, requires_active_user from app.domain.accounts.schemas import AccountLogin, AccountRegister, User from app.domain.accounts.services import RoleService, UserService +from app.domain.accounts.utils import get_signed_user_profile_pic_url class AccessController(Controller): @@ -108,4 +109,9 @@ async def signup( ) async def profile(self, request: Request, current_user: UserModel, users_service: UserService) -> User: """User Profile.""" - return users_service.to_schema(current_user, schema_type=User) + # Workaround due to https://github.com/jcrist/msgspec/issues/673 + # advanced alchemy to_schema uses `cast` to convert dict to schema + # object, which does not call `__post_init__` + user = users_service.to_schema(current_user, schema_type=User) + user.avatar_url = get_signed_user_profile_pic_url(user.id) + return user diff --git a/src/app/domain/accounts/schemas.py b/src/app/domain/accounts/schemas.py index 459cbbb1..370e37ad 100644 --- a/src/app/domain/accounts/schemas.py +++ b/src/app/domain/accounts/schemas.py @@ -71,11 +71,11 @@ class User(CamelizedBaseStruct): teams: list[UserTeam] = [] roles: list[UserRole] = [] oauth_accounts: list[OauthAccount] = [] - profile_pic_url: str | None = None + avatar_url: str | None = None def __post_init__(self): """Build a profile pic url from company url.""" - self.profile_pic_url = get_signed_user_profile_pic_url(self.id) + self.avatar_url = get_signed_user_profile_pic_url(self.id) class UserCreate(CamelizedBaseStruct):