Skip to content

Commit

Permalink
Explicitly set avatar_url in the user object
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Sep 4, 2024
1 parent 4fd807c commit 9fbc9c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/app/domain/accounts/controllers/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/app/domain/accounts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9fbc9c0

Please sign in to comment.