diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py index 7a11b7092..432d54ddf 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/task.py @@ -130,6 +130,8 @@ class Task: parent: str | None = None, event_definition: dict[str, Any] | None = None, error_message: str | None = None, + assigned_user_group_identifier: str | None = None, + potential_owner_usernames: str | None = None, ): self.id = id self.name = name @@ -155,6 +157,8 @@ class Task: self.process_model_display_name = process_model_display_name self.form_schema = form_schema self.form_ui_schema = form_ui_schema + self.assigned_user_group_identifier = assigned_user_group_identifier + self.potential_owner_usernames = potential_owner_usernames self.multi_instance_type = multi_instance_type # Some tasks have a repeat behavior. self.multi_instance_count = multi_instance_count # This is the number of times the task could repeat. @@ -200,6 +204,8 @@ class Task: "parent": self.parent, "event_definition": self.event_definition, "error_message": self.error_message, + "assigned_user_group_identifier": self.assigned_user_group_identifier, + "potential_owner_usernames": self.potential_owner_usernames, } @classmethod diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index b9aa42674..e3c1db7bc 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -74,6 +74,7 @@ class ReactJsonSchemaSelectOption(TypedDict): enum: list[str] +# this is currently not used by the Frontend def task_list_my_tasks( process_instance_id: int | None = None, page: int = 1, per_page: int = 100 ) -> flask.wrappers.Response: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py index 94c6bb247..9639aa5ee 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -15,6 +15,7 @@ from SpiffWorkflow.bpmn.specs.event_definitions import TimerEventDefinition # t from SpiffWorkflow.task import Task as SpiffTask # type: ignore from spiffworkflow_backend import db from spiffworkflow_backend.exceptions.api_error import ApiError +from spiffworkflow_backend.models.group import GroupModel from spiffworkflow_backend.models.human_task import HumanTaskModel from spiffworkflow_backend.models.process_instance import ProcessInstanceApi from spiffworkflow_backend.models.process_instance import ProcessInstanceModel @@ -546,6 +547,20 @@ class ProcessInstanceService: except UserDoesNotHaveAccessToTaskError: can_complete = False + # if the current user cannot complete the task then find out who can + assigned_user_group_identifier = None + potential_owner_usernames = None + if can_complete is False: + human_task = HumanTaskModel.query.filter_by(task_id=task_guid).first() + if human_task is not None: + if human_task.lane_assignment_id is not None: + group = GroupModel.query.filter_by(id=human_task.lane_assignment_id).first() + if group is not None: + assigned_user_group_identifier = group.identifier + elif len(human_task.potential_owners) > 0: + user_list = [u.email for u in human_task.potential_owners] + potential_owner_usernames = ",".join(user_list) + parent_id = None if spiff_task.parent: parent_id = spiff_task.parent.id @@ -576,6 +591,8 @@ class ProcessInstanceService: parent=parent_id, event_definition=serialized_task_spec.get("event_definition"), error_message=error_message, + assigned_user_group_identifier=assigned_user_group_identifier, + potential_owner_usernames=potential_owner_usernames, ) return task diff --git a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx index 7e4b4c54e..994d5efee 100644 --- a/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInterstitial.tsx @@ -179,9 +179,22 @@ export default function ProcessInterstitial({ } if (!myTask.can_complete && HUMAN_TASK_TYPES.includes(myTask.type)) { + let message = 'This next task is assigned to a different person or team.'; + if (myTask.assigned_user_group_identifier) { + message = `This next task is assigned to group: ${myTask.assigned_user_group_identifier}.`; + } else if (myTask.potential_owner_usernames) { + let potentialOwnerArray = myTask.potential_owner_usernames.split(','); + if (potentialOwnerArray.length > 2) { + potentialOwnerArray = potentialOwnerArray.slice(0, 2).concat(['...']); + } + message = `This next task is assigned to user(s): ${potentialOwnerArray.join( + ', ' + )}.`; + } + return inlineMessage( '', - `This next task is assigned to a different person or team. There is no action for you to take at this time.` + `${message} There is no action for you to take at this time.` ); } if (shouldRedirectToTask(myTask)) {