allow marking task complete without executing

This commit is contained in:
Elizabeth Esswein 2022-12-18 10:44:42 -05:00
parent 8d8f766d45
commit 54426b19bf
4 changed files with 120 additions and 30 deletions

View File

@ -861,33 +861,6 @@ paths:
schema: schema:
$ref: "#/components/schemas/OkTrue" $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: /process-instances/reports:
parameters: parameters:
- name: page - name: page
@ -1279,6 +1252,66 @@ paths:
schema: schema:
$ref: "#/components/schemas/Workflow" $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: /service-tasks:
get: get:
tags: tags:

View File

@ -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: def commit_and_push_to_git(message: str) -> None:
"""Commit_and_push_to_git.""" """Commit_and_push_to_git."""
if current_app.config["GIT_COMMIT_ON_SAVE"]: if current_app.config["GIT_COMMIT_ON_SAVE"]:

View File

@ -17,6 +17,7 @@ from typing import Optional
from typing import Tuple from typing import Tuple
from typing import TypedDict from typing import TypedDict
from typing import Union from typing import Union
from uuid import UUID
import dateparser import dateparser
import pytz import pytz
@ -706,6 +707,8 @@ class ProcessInstanceProcessor:
db.session.commit() db.session.commit()
def serialize_task_spec(self, task_spec: SpiffTask) -> Any: 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) return self._serializer.spec_converter.convert(task_spec)
def send_bpmn_event(self, event_data: dict[str, Any]) -> None: 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.bpmn_process_instance.catch(event_definition)
self.do_engine_steps(save=True) 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 @staticmethod
def get_parser() -> MyCustomParser: def get_parser() -> MyCustomParser:
"""Get_parser.""" """Get_parser."""

View File

@ -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 taskDataButtons = (task: any) => {
const buttons = []; const buttons = [];
@ -584,7 +594,7 @@ export default function ProcessInstanceShow() {
); );
buttons.push( buttons.push(
<Button <Button
data-qa="create-script-unit-test-button" data-qa="cancel-task-data-edit-button"
onClick={cancelUpdatingTask} onClick={cancelUpdatingTask}
> >
Cancel Cancel
@ -592,7 +602,7 @@ export default function ProcessInstanceShow() {
); );
} else if (selectingEvent) { } else if (selectingEvent) {
buttons.push( buttons.push(
<Button data-qa="create-script-unit-test-button" onClick={sendEvent}> <Button data-qa="send-event-button" onClick={sendEvent}>
Send Send
</Button> </Button>
); );
@ -616,12 +626,21 @@ export default function ProcessInstanceShow() {
if (canSendEvent(task)) { if (canSendEvent(task)) {
buttons.push( buttons.push(
<Button <Button
data-qa="create-script-unit-test-button" data-qa="select-event-button"
onClick={() => setSelectingEvent(true)} onClick={() => setSelectingEvent(true)}
> >
Send Event Send Event
</Button> </Button>
); );
} else {
buttons.push(
<Button
data-qa="mark-task-complete-button"
onClick={() => markTaskComplete()}
>
Mark Complete
</Button>
);
} }
} }
} }