only return the tasks for the given bpmn process omitting tasks for call activities (#1562)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-05-16 18:29:53 +00:00 committed by GitHub
parent c23cf38c33
commit afd598bb8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 10 deletions

View File

@ -377,19 +377,21 @@ def _process_instance_task_list(
This is how we know what the state of each task is and how to color things. This is how we know what the state of each task is and how to color things.
""" """
bpmn_process_ids = [] bpmn_process_ids = []
bpmn_process = None
if bpmn_process_guid: if bpmn_process_guid:
bpmn_process = BpmnProcessModel.query.filter_by(guid=bpmn_process_guid).first() bpmn_process = BpmnProcessModel.query.filter_by(guid=bpmn_process_guid).first()
if bpmn_process is None: else:
raise ApiError( bpmn_process = process_instance.bpmn_process
error_code="bpmn_process_not_found",
message=(
f"Cannot find a bpmn process with guid '{bpmn_process_guid}' for process instance '{process_instance.id}'"
),
status_code=400,
)
bpmn_processes = TaskService.bpmn_process_and_descendants([bpmn_process]) if bpmn_process is None:
bpmn_process_ids = [p.id for p in bpmn_processes] raise ApiError(
error_code="bpmn_process_not_found",
message=(f"Cannot find a bpmn process with guid '{bpmn_process_guid}' for process instance '{process_instance.id}'"),
status_code=400,
)
bpmn_processes = TaskService.bpmn_process_and_descendants([bpmn_process])
bpmn_process_ids = [p.id for p in bpmn_processes]
task_model_query = db.session.query(TaskModel).filter( task_model_query = db.session.query(TaskModel).filter(
TaskModel.process_instance_id == process_instance.id, TaskModel.process_instance_id == process_instance.id,

View File

@ -10,6 +10,7 @@ from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore
from SpiffWorkflow.exceptions import WorkflowException # type: ignore from SpiffWorkflow.exceptions import WorkflowException # type: ignore
from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.task import Task as SpiffTask # type: ignore
from SpiffWorkflow.util.task import TaskState # type: ignore from SpiffWorkflow.util.task import TaskState # type: ignore
from sqlalchemy import and_
from sqlalchemy import asc from sqlalchemy import asc
from spiffworkflow_backend.exceptions.error import TaskMismatchError from spiffworkflow_backend.exceptions.error import TaskMismatchError
@ -565,6 +566,17 @@ class TaskService:
direct_children = BpmnProcessModel.query.filter( direct_children = BpmnProcessModel.query.filter(
BpmnProcessModel.direct_parent_process_id.in_(bpmn_process_ids) # type: ignore BpmnProcessModel.direct_parent_process_id.in_(bpmn_process_ids) # type: ignore
).all() ).all()
direct_children = (
BpmnProcessModel.query.join(TaskModel, TaskModel.guid == BpmnProcessModel.guid)
.join(TaskDefinitionModel, TaskDefinitionModel.id == TaskModel.task_definition_id)
.filter(
and_(
TaskDefinitionModel.typename == "SubWorkflowTask",
TaskModel.bpmn_process_id.in_(bpmn_process_ids), # type: ignore
)
)
.all()
)
if len(direct_children) > 0: if len(direct_children) > 0:
return bpmn_processes + cls.bpmn_process_and_descendants(direct_children) return bpmn_processes + cls.bpmn_process_and_descendants(direct_children)
return bpmn_processes return bpmn_processes