diff --git a/reana_client/api/client.py b/reana_client/api/client.py index bd702073..8263feba 100644 --- a/reana_client/api/client.py +++ b/reana_client/api/client.py @@ -1306,9 +1306,7 @@ def share_workflow( """ try: share_params = { - "workflow_id_or_name": workflow, "user_email_to_share_with": user_email_to_share_with, - "access_token": access_token, } if message: @@ -1318,7 +1316,9 @@ def share_workflow( share_params["valid_until"] = valid_until (response, http_response) = current_rs_api_client.api.share_workflow( - **share_params + workflow_id_or_name=workflow, + share_details=share_params, + access_token=access_token, ).result() if http_response.status_code == 200: diff --git a/reana_client/cli/workflow.py b/reana_client/cli/workflow.py index 9c1d4b3d..66d4fe65 100644 --- a/reana_client/cli/workflow.py +++ b/reana_client/cli/workflow.py @@ -168,13 +168,13 @@ def workflow_sharing_group(ctx): "--shared-by", "shared_by", default=None, - help="List workflows shared by the specified user(s).", + help="List workflows shared by the specified user.", ) @click.option( "--shared-with", "shared_with", default=None, - help="List workflows shared with the specified user(s).", + help="List workflows shared with the specified user.", ) @add_access_token_options @add_pagination_options @@ -215,7 +215,7 @@ def workflows_list( # noqa: C901 \t - ``--shared-by anybody``: list workflows shared with you by anybody.\n \t - ``--shared-with anybody``: list your shared workflows exclusively.\n \t - ``--shared-with nobody``: list your unshared workflows exclusively.\n - \t - ``--shared-with bob@cern.ch,cecile@cern.ch``: list workflows shared with either bob@cern.ch or cecile@cern.ch + \t - ``--shared-with bob@cern.ch``: list workflows shared with bob@cern.ch Examples:\n \t $ reana-client list --all\n @@ -332,7 +332,7 @@ def workflows_list( # noqa: C901 if header == "shared_by": value = workflow.get("owner_email") if header == "shared_with": - value = workflow.get("shared_with") + value = ", ".join(workflow.get("shared_with", [])) if not value: value = workflow.get(header) row.append(value) @@ -1628,37 +1628,24 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412 unshare_errors = [] unshared_users = [] - if workflow: + for user in users: try: - for user in users: - try: - logging.info(f"Unsharing workflow {workflow} with user {user}") - unshare_workflow(workflow, user, access_token) - unshared_users.append(user) - except Exception as e: - unshare_errors.append( - f"Failed to unshare {workflow} with {user}: {str(e)}" - ) - logging.debug(traceback.format_exc()) + logging.info(f"Unsharing workflow {workflow} with user {user}") + unshare_workflow(workflow, user, access_token) + unshared_users.append(user) except Exception as e: + unshare_errors.append(f"Failed to unshare {workflow} with {user}: {str(e)}") logging.debug(traceback.format_exc()) - logging.debug(str(e)) - display_message( - "An error occurred while unsharing workflow:\n{}".format(str(e)), - msg_type="error", - ) - if unshared_users: - display_message( - f"{workflow} is no longer shared with {', '.join(unshared_users)}", - msg_type="success", - ) - if unshare_errors: - for error in unshare_errors: - display_message(error, msg_type="error") - - else: - display_message(f"Cannot find workflow {workflow}", msg_type="error") + if unshared_users: + display_message( + f"{workflow} is no longer shared with {', '.join(unshared_users)}", + msg_type="success", + ) + if unshare_errors: + for error in unshare_errors: + display_message(error, msg_type="error") + sys.exit(1) @workflow_sharing_group.command("share-status") @@ -1667,7 +1654,7 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412 @add_access_token_options @click.option( "--format", - "_format", + "format_", multiple=True, default=None, help="Format output according to column titles or column " @@ -1682,7 +1669,7 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412 ) @click.pass_context def share_workflow_status( - ctx, workflow, _format, output_format, access_token + ctx, workflow, format_, output_format, access_token ): # noqa D412 """Show with whom a workflow is shared. @@ -1697,33 +1684,6 @@ def share_workflow_status( try: sharing_status = get_workflow_sharing_status(workflow, access_token) - - if sharing_status: - shared_with = sharing_status.get("shared_with", []) - - if shared_with: - headers = ["user_email", "valid_until"] - data = [ - [ - entry["user_email"], - ( - entry["valid_until"] - if entry["valid_until"] is not None - else "-" - ), - ] - for entry in shared_with - ] - - display_formatted_output(data, headers, _format, output_format) - else: - display_message( - f"Workflow {workflow} is not shared with anyone.", msg_type="info" - ) - else: - display_message( - f"Workflow {workflow} is not shared with anyone.", msg_type="info" - ) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) @@ -1733,3 +1693,21 @@ def share_workflow_status( ), msg_type="error", ) + sys.exit(1) + + shared_with = sharing_status.get("shared_with", []) + if shared_with: + headers = ["user_email", "valid_until"] + data = [ + [ + entry["user_email"], + (entry["valid_until"] if entry["valid_until"] is not None else "-"), + ] + for entry in shared_with + ] + + display_formatted_output(data, headers, format_, output_format) + else: + display_message( + f"Workflow {workflow} is not shared with anyone.", msg_type="info" + ) diff --git a/setup.py b/setup.py index 18603f85..37d7213f 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,9 @@ "sphinx-click>=1.0.4", ], "tests": [ - "pytest-reana>=0.95.0a2,<0.96.0", + "pytest-reana>=0.95.0a4,<0.96.0", + "reana-commons[kubernetes]>=0.95.0a3,<0.96.0", + "reana-commons[kubernetes] @ git+https://github.com/reanahub/reana-commons.git@master", ], } @@ -40,7 +42,8 @@ "click>=7", "pathspec==0.9.0", "jsonpointer>=2.0", - "reana-commons[yadage,snakemake,cwl]>=0.95.0a2,<0.96.0", + "reana-commons[yadage,snakemake,cwl]>=0.95.0a3,<0.96.0", + "reana-commons[yadage,snakemake,cwl] @ git+https://github.com/reanahub/reana-commons.git@master", "tablib>=0.12.1,<0.13", "werkzeug>=0.14.1 ; python_version<'3.10'", "werkzeug>=0.15.0 ; python_version>='3.10'",