forked from reanahub/reana-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow): add share-remove command (reanahub#692)
Adds a new command to the CLI to unshare a workflow. Closes reanahub#681
- Loading branch information
1 parent
f7b53e7
commit 20caca3
Showing
4 changed files
with
136 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -1536,3 +1536,64 @@ def workflow_share_add( | |
|
||
if share_errors: | ||
sys.exit(1) | ||
|
||
|
||
@workflow_sharing_group.command("share-remove") | ||
@check_connection | ||
@add_workflow_option | ||
@add_access_token_options | ||
@click.option( | ||
"-u", | ||
"--user", | ||
"users", | ||
multiple=True, | ||
help="Users to unshare the workflow with.", | ||
required=True, | ||
) | ||
@click.pass_context | ||
def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412 | ||
"""Unshare a workflow. | ||
The `share-remove` command allows for unsharing a workflow. The workflow | ||
will no longer be visible to the users with whom it was shared. | ||
Example: | ||
$ reana-client share-remove -w myanalysis.42 --user [email protected] | ||
""" | ||
from reana_client.api.client import unshare_workflow | ||
|
||
unshare_errors = [] | ||
unshared_users = [] | ||
|
||
if workflow: | ||
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()) | ||
except Exception as 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") |
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 |
---|---|---|
|
@@ -1049,3 +1049,38 @@ def test_share_add_workflow(): | |
) | ||
assert result.exit_code == 0 | ||
assert response["message"] in result.output | ||
|
||
|
||
def test_share_remove_workflow(): | ||
"""Test share-remove workflows.""" | ||
status_code = 200 | ||
response = { | ||
"message": "is no longer shared with", | ||
"workflow_id": "string", | ||
"workflow_name": "string", | ||
} | ||
env = {"REANA_SERVER_URL": "localhost"} | ||
mock_http_response, mock_response = Mock(), Mock() | ||
mock_http_response.status_code = status_code | ||
mock_response = response | ||
reana_token = "000000" | ||
runner = CliRunner(env=env) | ||
with runner.isolation(): | ||
with patch( | ||
"reana_client.api.client.current_rs_api_client", | ||
make_mock_api_client("reana-server")(mock_response, mock_http_response), | ||
): | ||
result = runner.invoke( | ||
cli, | ||
[ | ||
"share-remove", | ||
"-t", | ||
reana_token, | ||
"--workflow", | ||
"test-workflow.1", | ||
"--user", | ||
"[email protected]", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
assert response["message"] in result.output |