From e1179abfbcd516144f61a1772de73b7bbdaac3e2 Mon Sep 17 00:00:00 2001 From: Daan Rosendal Date: Fri, 15 Dec 2023 12:03:20 +0100 Subject: [PATCH] feat(utils): add permission error for getting workflows (#216) Closes reanahub/reana-server#651, closes reanahub/reana-server#650 --- reana_db/utils.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/reana_db/utils.py b/reana_db/utils.py index ea82be1..2358157 100644 --- a/reana_db/utils.py +++ b/reana_db/utils.py @@ -223,12 +223,22 @@ def _get_workflow_by_name(workflow_name, user_uuid, include_shared_workflows=Fal ) if not workflow: - raise ValueError( - "REANA_WORKON is set to {0}, but " - "that workflow does not exist. " - "Please set your REANA_WORKON environment " - "variable appropriately.".format(workflow_name) - ) + workflow = Workflow.query.filter_by(name=workflow_name).first() + + if workflow: + raise PermissionError( + "You are unauthorised to perform this action on workflow {0}.".format( + workflow_name + ) + ) + else: + raise ValueError( + "REANA_WORKON is set to {0}, but " + "that workflow does not exist. " + "Please set your REANA_WORKON environment " + "variable appropriately.".format(workflow_name) + ) + return workflow @@ -264,12 +274,22 @@ def _get_workflow_by_uuid(workflow_uuid, user_uuid, include_shared_workflows=Fal ).first() if not workflow: - raise ValueError( - "REANA_WORKON is set to {0}, but " - "that workflow does not exist. " - "Please set your REANA_WORKON environment " - "variable appropriately.".format(workflow_uuid) - ) + workflow = Workflow.query.filter_by(id_=workflow_uuid).first() + + if workflow: + raise PermissionError( + "You are unauthorised to perform this action on workflow {0}.".format( + workflow_uuid + ) + ) + else: + raise ValueError( + "REANA_WORKON is set to {0}, but " + "that workflow does not exist. " + "Please set your REANA_WORKON environment " + "variable appropriately.".format(workflow_uuid) + ) + return workflow