Skip to content

Commit

Permalink
hotfix(service): user connected via tokens cannot create a study (#1757)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurent LAPORTE <[email protected]>
  • Loading branch information
MartinBelthle and laurent-laporte-pro authored Oct 10, 2023
1 parent f6a4615 commit f620197
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,15 +641,20 @@ def create_study(

def get_user_name(self, params: RequestParameters) -> str:
"""
Args: params : Request parameters
Retrieves the name of a user based on the provided request parameters.
Returns: The user's name
Args:
params: The request parameters which includes user information.
Returns:
Returns the user's name or, if the logged user is a "bot"
(i.e., an application's token), it returns the token's author name.
"""
author = "Unknown"
if params.user:
if curr_user := self.user_service.get_user(params.user.id, params):
author = curr_user.to_dto().name
return author
user_id = params.user.impersonator if params.user.type == "bots" else params.user.id
if curr_user := self.user_service.get_user(user_id, params):
return curr_user.to_dto().name
return "Unknown"

def get_study_synthesis(self, study_id: str, params: RequestParameters) -> FileStudyTreeConfigDTO:
"""
Expand Down

0 comments on commit f620197

Please sign in to comment.