From f6201976a653db19739cbc42e91ea27ac790da10 Mon Sep 17 00:00:00 2001 From: MartinBelthle <102529366+MartinBelthle@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:19:12 +0200 Subject: [PATCH] hotfix(service): user connected via tokens cannot create a study (#1757) Co-authored-by: Laurent LAPORTE --- antarest/study/service.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/antarest/study/service.py b/antarest/study/service.py index b9ec491c18..64d5c7d83c 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -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: """