-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): update workflow sharing commands after changes (#692)
- Loading branch information
1 parent
5e4d12b
commit 292827d
Showing
3 changed files
with
46 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected],[email protected]``: list workflows shared with either bob@cern.ch or cecile@cern.ch | ||
\t - ``--shared-with [email protected]``: list workflows shared with [email protected] | ||
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters