File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -483,7 +483,7 @@ def get_user(
483483 "In order to get user, at least one of username, email, or user_id must be specified"
484484 )
485485
486- query = session .query (User )
486+ query = session .query (User ). filter ( User . application_id == application_id )
487487
488488 if username is not None :
489489 username = cast (str , username )
@@ -498,16 +498,17 @@ def get_user(
498498 if user_id is not None :
499499 query = query .filter (User .id == user_id )
500500
501- if application_id is not None :
502- query = query .filter (User .application_id == application_id )
503-
504- user = query .first ()
505- if user is None :
501+ users = query .all ()
502+ if len (users ) == 0 :
506503 raise UserNotFound (
507- f"Did not find user with filters username={ username } , normalized_email={ normalized_email } "
504+ f"Did not find user with filters username={ username } , normalized_email={ normalized_email } , id={ user_id } and application_id={ application_id } "
505+ )
506+ if len (users ) > 1 :
507+ raise Exception (
508+ f"Too many results for user with filters username={ username } , normalized_email={ normalized_email } , id={ user_id } and application_id={ application_id } "
508509 )
509510
510- return user
511+ return users [ 0 ]
511512
512513
513514def update_user (
Original file line number Diff line number Diff line change @@ -371,8 +371,17 @@ async def get_user_handler(
371371 """
372372 Get current user.
373373 """
374- user_id = current_user .id
375- user = actions .get_user (session = db_session , user_id = user_id )
374+ try :
375+ user = actions .get_user (
376+ session = db_session ,
377+ user_id = current_user .id ,
378+ application_id = current_user .application_id ,
379+ )
380+ except actions .UserNotFound :
381+ raise HTTPException (status_code = 404 , detail = "User not found" )
382+ except Exception :
383+ logger .error ("Unhandled error" )
384+ raise HTTPException (status_code = 500 )
376385
377386 return user
378387
You can’t perform that action at this time.
0 commit comments