From 43ca6aafe1cc624280aabf404ee57668a6c1ebbd Mon Sep 17 00:00:00 2001 From: Yuri Chiucconi Date: Tue, 24 Sep 2024 12:59:16 +0200 Subject: [PATCH] improve check --- fractal_server/app/routes/api/v1/_aux_functions.py | 7 +++++-- fractal_server/app/routes/api/v2/_aux_functions.py | 7 +++++-- fractal_server/app/routes/api/v2/task_collection_custom.py | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fractal_server/app/routes/api/v1/_aux_functions.py b/fractal_server/app/routes/api/v1/_aux_functions.py index f807276be0..0535cdab74 100644 --- a/fractal_server/app/routes/api/v1/_aux_functions.py +++ b/fractal_server/app/routes/api/v1/_aux_functions.py @@ -368,8 +368,11 @@ async def _get_task_check_owner( ), ) else: - verify_user_has_settings(user) - owner = user.username or user.settings.slurm_user + if user.username: + owner = user.username + else: + verify_user_has_settings(user) + owner = user.settings.slurm_user if owner != task.owner: raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, diff --git a/fractal_server/app/routes/api/v2/_aux_functions.py b/fractal_server/app/routes/api/v2/_aux_functions.py index 9631346ea3..6d114f02bf 100644 --- a/fractal_server/app/routes/api/v2/_aux_functions.py +++ b/fractal_server/app/routes/api/v2/_aux_functions.py @@ -363,8 +363,11 @@ async def _get_task_check_owner( ), ) else: - verify_user_has_settings(user) - owner = user.username or user.settings.slurm_user + if user.username: + owner = user.username + else: + verify_user_has_settings(user) + owner = user.settings.slurm_user if owner != task.owner: raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, diff --git a/fractal_server/app/routes/api/v2/task_collection_custom.py b/fractal_server/app/routes/api/v2/task_collection_custom.py index 3b242ded82..fcbe03b2b1 100644 --- a/fractal_server/app/routes/api/v2/task_collection_custom.py +++ b/fractal_server/app/routes/api/v2/task_collection_custom.py @@ -113,8 +113,11 @@ async def collect_task_custom( package_root = Path(task_collect.package_root) # Set task.owner attribute - verify_user_has_settings(user) - owner = user.username or user.settings.slurm_user + if user.username: + owner = user.username + else: + verify_user_has_settings(user) + owner = user.settings.slurm_user if owner is None: raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,