Skip to content

Commit

Permalink
api.main: PUT '/user/profile' endpoint improvments
Browse files Browse the repository at this point in the history
Update handler name for PUT `/user/profile/<username>`
endpoint.
Add proper docstring for the handler.
Also, make `email` field optional in the request query
parameter in case user does not want to update it.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia authored and gctucker committed Oct 10, 2023
1 parent b7a0f8f commit c627c2a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ async def get_user_by_id(
@app.put('/user/profile/{username}', response_model=User,
response_model_include={"profile"},
response_model_by_alias=False)
async def put_user(
async def put_user_profile(
username: str,
password: Password,
email: str,
email: str = None,
groups: List[str] = Query([]),
current_user: User = Depends(get_user)):
"""Update user"""
"""Update own user profile
The handler will only allow users to update its own profile.
Adding itself to 'admin' group is not allowed."""
if str(current_user.profile.username) != username:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
Expand All @@ -262,7 +264,7 @@ async def put_user(
profile=UserProfile(
username=username,
hashed_password=hashed_password,
email=email,
email=email if email else current_user.profile.email,
groups=group_obj if group_obj else current_user.profile.groups
)))
await pubsub.publish_cloudevent('user', {'op': 'updated',
Expand Down

0 comments on commit c627c2a

Please sign in to comment.