From a204aeb92a64bb3d9104d94bc8419ca3c60e21f0 Mon Sep 17 00:00:00 2001 From: Elizabeth Esswein Date: Sun, 18 Dec 2022 10:44:42 -0500 Subject: [PATCH] allow marking task complete without executing --- .../src/spiffworkflow_backend/api.yml | 87 +++++++++++++------ .../routes/process_api_blueprint.py | 24 +++++ .../services/process_instance_processor.py | 14 +++ .../src/routes/ProcessInstanceShow.tsx | 25 +++++- 4 files changed, 120 insertions(+), 30 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 6def7f2cd..0249f930e 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -861,33 +861,6 @@ paths: schema: $ref: "#/components/schemas/OkTrue" - /send-event/{modified_process_model_identifier}/{process_instance_id}: - parameters: - - name: modified_process_model_identifier - in: path - required: true - description: The modified id of an existing process model - schema: - type: string - - name: process_instance_id - in: path - required: true - description: The unique id of the process instance - schema: - type: string - post: - operationId: spiffworkflow_backend.routes.process_api_blueprint.send_bpmn_event - summary: Send a BPMN event to the process - tags: - - Process Instances - responses: - "200": - description: Event Sent Successfully - content: - application/json: - schema: - $ref: "#/components/schemas/Workflow" - /process-instances/reports: parameters: - name: page @@ -1279,6 +1252,66 @@ paths: schema: $ref: "#/components/schemas/Workflow" + /send-event/{modified_process_model_identifier}/{process_instance_id}: + parameters: + - name: modified_process_model_identifier + in: path + required: true + description: The modified id of an existing process model + schema: + type: string + - name: process_instance_id + in: path + required: true + description: The unique id of the process instance + schema: + type: string + post: + operationId: spiffworkflow_backend.routes.process_api_blueprint.send_bpmn_event + summary: Send a BPMN event to the process + tags: + - Process Instances + responses: + "200": + description: Event Sent Successfully + content: + application/json: + schema: + $ref: "#/components/schemas/Workflow" + + /task-complete/{modified_process_model_identifier}/{process_instance_id}/{task_id}: + parameters: + - name: modified_process_model_identifier + in: path + required: true + description: The modified id of an existing process model + schema: + type: string + - name: process_instance_id + in: path + required: true + description: The unique id of the process instance + schema: + type: string + - name: task_id + in: path + required: true + description: The unique id of the task. + schema: + type: string + post: + operationId: spiffworkflow_backend.routes.process_api_blueprint.mark_task_complete + summary: Mark a task complete without executing it + tags: + - Process Instances + responses: + "200": + description: Event Sent Successfully + content: + application/json: + schema: + $ref: "#/components/schemas/Workflow" + /service-tasks: get: tags: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index fe178c961..af92bb324 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -2170,6 +2170,30 @@ def send_bpmn_event( ) +def mark_task_complete( + modified_process_model_identifier: str, + process_instance_id: str, + task_id: str, + body: Dict, +) -> Response: + process_instance = ProcessInstanceModel.query.filter( + ProcessInstanceModel.id == int(process_instance_id) + ).first() + if process_instance: + processor = ProcessInstanceProcessor(process_instance) + processor.mark_task_complete(task_id) + else: + raise ApiError( + error_code="send_bpmn_event_error", + message=f"Could not skip Task {task_id} in Instance {process_instance_id}", + ) + return Response( + json.dumps(ProcessInstanceModelSchema().dump(process_instance)), + status=200, + mimetype="application/json", + ) + + def commit_and_push_to_git(message: str) -> None: """Commit_and_push_to_git.""" if current_app.config["GIT_COMMIT_ON_SAVE"]: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index f06d0c17d..31d42773d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -17,6 +17,7 @@ from typing import Optional from typing import Tuple from typing import TypedDict from typing import Union +from uuid import UUID import dateparser import pytz @@ -706,6 +707,8 @@ class ProcessInstanceProcessor: db.session.commit() def serialize_task_spec(self, task_spec: SpiffTask) -> Any: + # The task spec is NOT actually a SpiffTask, it is the task spec attached to a SpiffTask + # Not sure why mypy accepts this but whatever. return self._serializer.spec_converter.convert(task_spec) def send_bpmn_event(self, event_data: dict[str, Any]) -> None: @@ -719,6 +722,17 @@ class ProcessInstanceProcessor: self.bpmn_process_instance.catch(event_definition) self.do_engine_steps(save=True) + def mark_task_complete(self, task_id: str) -> None: + spiff_task = self.bpmn_process_instance.get_task(UUID(task_id)) + spiff_task._set_state(TaskState.COMPLETED) + self.bpmn_process_instance.last_task = spiff_task + for child in spiff_task.children: + child.task_spec._update(child) + current_app.logger.info( + f"Task {spiff_task.task_spec.name} of process instance {self.process_instance_model.id} skipped" + ) + self.do_engine_steps(save=True) + @staticmethod def get_parser() -> MyCustomParser: """Get_parser.""" diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index 6df404ec9..8c625d2a9 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -546,6 +546,16 @@ export default function ProcessInstanceShow() { }); }; + const markTaskComplete = () => { + const taskToUse: any = taskToDisplay; + HttpService.makeCallToBackend({ + path: `/task-complete/${modifiedProcessModelId}/${params.process_instance_id}/${taskToUse.id}`, + httpMethod: 'POST', + successCallback: saveTaskDataResult, + failureCallback: saveTaskDataFailure, + }); + }; + const taskDataButtons = (task: any) => { const buttons = []; @@ -584,7 +594,7 @@ export default function ProcessInstanceShow() { ); buttons.push( ); @@ -616,12 +626,21 @@ export default function ProcessInstanceShow() { if (canSendEvent(task)) { buttons.push( ); + } else { + buttons.push( + + ); } } }