Skip to content

Commit

Permalink
feat(rest): add unshare_workflow endpoint (reanahub#658)
Browse files Browse the repository at this point in the history
Adds a new endpoint to unshare a workflow.

Closes reanahub/reana-client#681
  • Loading branch information
DaanRosendal committed Mar 20, 2024
1 parent b528ea8 commit f17f763
Show file tree
Hide file tree
Showing 2 changed files with 355 additions and 0 deletions.
183 changes: 183 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3869,6 +3869,189 @@
"summary": "Set status of a workflow."
}
},
"/api/workflows/{workflow_id_or_name}/unshare": {
"post": {
"description": "This resource unshares a workflow with another user. This resource is expecting a workflow UUID and some parameters.",
"operationId": "unshare_workflow",
"parameters": [
{
"description": "The API access_token of workflow owner.",
"in": "query",
"name": "access_token",
"required": false,
"type": "string"
},
{
"description": "Required. Workflow UUID or name.",
"in": "path",
"name": "workflow_id_or_name",
"required": true,
"type": "string"
},
{
"description": "Required. User to unshare the workflow with.",
"in": "query",
"name": "user_email_to_unshare_with",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Request succeeded. The workflow has been unshared with the user.",
"examples": {
"application/json": {
"message": "The workflow has been unshared with the user.",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac",
"workflow_name": "mytest.1"
}
},
"schema": {
"properties": {
"message": {
"type": "string"
},
"workflow_id": {
"type": "string"
},
"workflow_name": {
"type": "string"
}
},
"type": "object"
}
},
"400": {
"description": "Request failed. The incoming data specification seems malformed.",
"examples": {
"application/json": {
"errors": [
"Missing data for required field."
],
"message": "Malformed request."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
},
"type": "object"
}
},
"403": {
"description": "Request failed. User is not allowed to unshare the workflow.",
"examples": {
"application/json": {
"errors": [
"User is not allowed to unshare the workflow."
]
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
},
"type": "object"
}
},
"404": {
"description": "Request failed. Workflow does not exist or user does not exist.",
"examples": {
"application/json": {
"errors": [
"Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
],
"message": "Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
},
"type": "object"
}
},
"409": {
"description": "Request failed. The workflow is not shared with the user.",
"examples": {
"application/json": {
"errors": [
"The workflow is not shared with the user."
],
"message": "The workflow is not shared with the user."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
},
"type": "object"
}
},
"500": {
"description": "Request failed. Internal controller error.",
"examples": {
"application/json": {
"errors": [
"Internal controller error."
],
"message": "Internal controller error."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
},
"type": "object"
}
}
},
"summary": "Unshare a workflow with another user."
}
},
"/api/workflows/{workflow_id_or_name}/workspace": {
"get": {
"description": "This resource retrieves the file list of a workspace, given its workflow UUID.",
Expand Down
172 changes: 172 additions & 0 deletions reana_server/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3359,3 +3359,175 @@ def share_workflow(workflow_id_or_name, user):
except Exception as e:
logging.exception(str(e))
return jsonify({"message": str(e)}), 500


@blueprint.route("/workflows/<workflow_id_or_name>/unshare", methods=["POST"])
@use_kwargs(
{
"user_email_to_unshare_with": fields.String(),
}
)
@signin_required()
def unshare_workflow(workflow_id_or_name, user, user_email_to_unshare_with):
r"""Unshare a workflow with another user.
---
post:
summary: Unshare a workflow with another user.
description: >-
This resource unshares a workflow with another user.
This resource is expecting a workflow UUID and some parameters.
operationId: unshare_workflow
produces:
- application/json
parameters:
- name: access_token
in: query
description: The API access_token of workflow owner.
required: false
type: string
- name: workflow_id_or_name
in: path
description: Required. Workflow UUID or name.
required: true
type: string
- name: user_email_to_unshare_with
in: query
description: >-
Required. User to unshare the workflow with.
required: true
type: string
responses:
200:
description: >-
Request succeeded. The workflow has been unshared with the user.
schema:
type: object
properties:
message:
type: string
workflow_id:
type: string
workflow_name:
type: string
examples:
application/json:
{
"message": "The workflow has been unshared with the user.",
"workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac",
"workflow_name": "mytest.1"
}
400:
description: >-
Request failed. The incoming data specification seems malformed.
schema:
type: object
properties:
message:
type: string
errors:
type: array
items:
type: string
examples:
application/json:
{
"message": "Malformed request.",
"errors": ["Missing data for required field."]
}
403:
description: >-
Request failed. User is not allowed to unshare the workflow.
schema:
type: object
properties:
message:
type: string
errors:
type: array
items:
type: string
examples:
application/json:
{
"errors": ["User is not allowed to unshare the workflow."]
}
404:
description: >-
Request failed. Workflow does not exist or user does not exist.
schema:
type: object
properties:
message:
type: string
errors:
type: array
items:
type: string
examples:
application/json:
{
"message": "Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does
not exist",
"errors": ["Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does
not exist"]
}
409:
description: >-
Request failed. The workflow is not shared with the user.
schema:
type: object
properties:
message:
type: string
errors:
type: array
items:
type: string
examples:
application/json:
{
"message": "The workflow is not shared with the user.",
"errors": ["The workflow is not shared with the user."]
}
500:
description: >-
Request failed. Internal controller error.
schema:
type: object
properties:
message:
type: string
errors:
type: array
items:
type: string
examples:
application/json:
{
"message": "Internal controller error.",
"errors": ["Internal controller error."]
}
"""
try:
unshare_params = {
"workflow_id_or_name": workflow_id_or_name,
"user_email_to_unshare_with": user_email_to_unshare_with,
"user_id": str(user.id_),
}

response, http_response = current_rwc_api_client.api.unshare_workflow(
**unshare_params
).result()

return jsonify(response), 200
except HTTPError as e:
logging.exception(str(e))
return jsonify(e.response.json()), e.response.status_code
except ValueError as e:
# In case of invalid workflow name / UUID
logging.exception(str(e))
return jsonify({"message": str(e)}), 403
except Exception as e:
logging.exception(str(e))
return jsonify({"message": str(e)}), 500

0 comments on commit f17f763

Please sign in to comment.