From ec16313ffff73fb12b73a3b80952c349b97cedeb Mon Sep 17 00:00:00 2001 From: "Janet L. Goldstein" <jgoldste@nrao.edu> Date: Wed, 12 Jan 2022 16:45:41 -0700 Subject: [PATCH] WS-858: fix bugs in `create_follow_on_capability_request`. TODO next: fix unit test --- .../services/capability-request.service.ts | 3 +- .../capability/views/capability_request.py | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/web/src/app/workspaces/services/capability-request.service.ts b/apps/web/src/app/workspaces/services/capability-request.service.ts index e59f035d1..b9400abf4 100644 --- a/apps/web/src/app/workspaces/services/capability-request.service.ts +++ b/apps/web/src/app/workspaces/services/capability-request.service.ts @@ -113,8 +113,7 @@ export class CapabilityRequestService { } /** - * Add file to latest version of capability request - * + * Add file to selected capability request version * @param requestId ID of request whose latest version will receive the file * @param filename Name of file * @param content Content of file diff --git a/services/capability/capability/views/capability_request.py b/services/capability/capability/views/capability_request.py index 3a7cf0454..e59e74d62 100644 --- a/services/capability/capability/views/capability_request.py +++ b/services/capability/capability/views/capability_request.py @@ -21,6 +21,8 @@ File containing definitions for the other half of the capability side of the Workspaces REST API, concerning capability requests """ +# pylint: disable=E0401 + import json from capability.views.capability_version import submit_capability_version @@ -127,31 +129,40 @@ def create_follow_on_capability_request(request: Request) -> Response: URL: capability/request/{request_id}/followon/{followon_type} :param request: POST request + :param version: version of the request for which we want to create a follow-on request :return: 200 OK response with JSON-formatted info of newly created capability request or 400 response (HTTPBadRequest) if expected parameters not given or 412 response (HTTPPreconditionFailed) if capability with given name does not exist and thus cannot be requested """ - request_id = request.matchdict["request_id"] followon_type = request.matchdict["followon_type"] + request_id = request.matchdict["request_id"] + capability_info = request.capability_info + capability_request = capability_info.lookup_capability_request(request_id) - capability_request = request.capability_info.lookup_capability_request(request_id) - parameters = capability_request.current_version.parameters + current_version = capability_request.current_version + parameters = current_version.parameters user_email = parameters["user_email"] + version_number = request.matchdict["version"] - previous_workflow_id = capability_request.current_execution.current_workflow_request_id - + previous_workflow_id = current_version.current_execution.current_workflow_request_id metadata_content = request.workflow_service.retrieve_file_content( followon_type, previous_workflow_id, "metadata.json" ) - metadata = json.loads(metadata_content) cms_path = metadata["destinationDirectory"] + "/working" sdm_id = metadata["fileSetIds"][0] if isinstance(metadata["fileSetIds"], list) else metadata["fileSetIds"] new_capability_request = request.capability_info.create_capability_request( - followon_type, parameters={"cms_path": cms_path, "sdmId": sdm_id, "user_email": user_email} + followon_type=followon_type, + parameters={ + "user_email": user_email, + "version": version_number, + "previous_workflow_request_id": previous_workflow_id, + "sdm_id": sdm_id, + "cms_path": cms_path, + }, ) return Response(json_body=new_capability_request.__json__()) @@ -172,6 +183,12 @@ def edit_capability_request(request: Request) -> Response: @view_config(route_name="create_and_submit_capability_request", renderer="json") def create_and_submit_capability_request(request: Request) -> Response: + """ + Pyramid view to create and submit a capability request + + :param request: dummy POST request + :return: + """ response = create_capability_request(request) capability_request = request.capability_info.lookup_capability_request(response.json_body["id"]) request.matchdict = { -- GitLab