diff --git a/docs/openapi.json b/docs/openapi.json index a977c6bb..9cb5f26e 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -3077,6 +3077,139 @@ "summary": "Share a workflow with another user." } }, + "/api/workflows/{workflow_id_or_name}/share-status": { + "get": { + "description": "This resource returns the share status of a given workflow.", + "operationId": "get_workflow_share_status", + "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" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Request succeeded. The response contains the share status of the workflow.", + "examples": { + "application/json": { + "shared_with": [ + { + "user_email": "bob@example.org", + "valid_until": "2022-11-24T23:59:59" + } + ], + "workflow_id": "256b25f4-4cfb-4684-b7a8-73872ef455a1", + "workflow_name": "mytest.1" + } + }, + "schema": { + "properties": { + "shared_with": { + "items": { + "properties": { + "user_email": { + "type": "string" + }, + "valid_until": { + "type": "string", + "x-nullable": true + } + }, + "type": "object" + }, + "type": "array" + }, + "workflow_id": { + "type": "string" + }, + "workflow_name": { + "type": "string" + } + }, + "type": "object" + } + }, + "401": { + "description": "Request failed. User not signed in.", + "examples": { + "application/json": { + "message": "User not signed in." + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + }, + "403": { + "description": "Request failed. Credentials are invalid or revoked.", + "examples": { + "application/json": { + "message": "Token not valid." + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + }, + "404": { + "description": "Request failed. Workflow does not exist.", + "examples": { + "application/json": { + "message": "Workflow mytest.1 does not exist." + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + }, + "500": { + "description": "Request failed. Internal server error.", + "examples": { + "application/json": { + "message": "Something went wrong." + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + } + } + }, + "summary": "Get the share status of a workflow." + } + }, "/api/workflows/{workflow_id_or_name}/specification": { "get": { "description": "This resource returns the REANA workflow specification used to start the workflow run. Resource is expecting a workflow UUID.", diff --git a/reana_server/rest/workflows.py b/reana_server/rest/workflows.py index 80fabbdb..9d9bdaaa 100644 --- a/reana_server/rest/workflows.py +++ b/reana_server/rest/workflows.py @@ -3557,3 +3557,132 @@ def unshare_workflow(workflow_id_or_name, user, user_email_to_unshare_with): except Exception as e: logging.exception(str(e)) return jsonify({"message": str(e)}), 500 + + +@blueprint.route("/workflows//share-status", methods=["GET"]) +@signin_required() +def get_workflow_share_status(workflow_id_or_name, user): + r"""Get the share status of a workflow. + + --- + get: + summary: Get the share status of a workflow. + description: >- + This resource returns the share status of a given workflow. + operationId: get_workflow_share_status + 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 + responses: + 200: + description: >- + Request succeeded. The response contains the share status of the workflow. + schema: + type: object + properties: + workflow_id: + type: string + workflow_name: + type: string + shared_with: + type: array + items: + type: object + properties: + user_email: + type: string + valid_until: + type: string + x-nullable: true + examples: + application/json: + { + "workflow_id": "256b25f4-4cfb-4684-b7a8-73872ef455a1", + "workflow_name": "mytest.1", + "shared_with": [ + { + "user_email": "bob@example.org", + "valid_until": "2022-11-24T23:59:59" + } + ] + } + 401: + description: >- + Request failed. User not signed in. + schema: + type: object + properties: + message: + type: string + examples: + application/json: + { + "message": "User not signed in." + } + 403: + description: >- + Request failed. Credentials are invalid or revoked. + schema: + type: object + properties: + message: + type: string + examples: + application/json: + { + "message": "Token not valid." + } + 404: + description: >- + Request failed. Workflow does not exist. + schema: + type: object + properties: + message: + type: string + examples: + application/json: + { + "message": "Workflow mytest.1 does not exist." + } + 500: + description: >- + Request failed. Internal server error. + schema: + type: object + properties: + message: + type: string + examples: + application/json: + { + "message": "Something went wrong." + } + """ + try: + share_status_params = { + "workflow_id_or_name": workflow_id_or_name, + "user_id": str(user.id_), + } + + response, http_response = current_rwc_api_client.api.get_workflow_share_status( + **share_status_params + ).result() + + return jsonify(response), 200 + except HTTPError as e: + logging.exception(str(e)) + return jsonify(e.response.json()), e.response.status_code + except Exception as e: + logging.exception(str(e)) + return jsonify({"message": str(e)}), 500