From c1ad29f51886cc69cdf03d4a5a0a62e7da10279e Mon Sep 17 00:00:00 2001 From: jasquat Date: Tue, 20 Dec 2022 14:58:15 -0500 Subject: [PATCH] set the completed by user on human task w/ burnettk --- .../services/process_instance_processor.py | 12 ++++++++---- .../services/process_instance_service.py | 2 +- .../unit/test_process_instance_processor.py | 5 ++++- 3 files changed, 13 insertions(+), 6 deletions(-) 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 753e3cd00..24dbd497b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -573,10 +573,9 @@ class ProcessInstanceProcessor: ) return details_model - def save_spiff_step_details(self, human_task: HumanTaskModel) -> None: + def save_spiff_step_details(self) -> None: """SaveSpiffStepDetails.""" details_model = self.spiff_step_details() - # details_model.lane_assignment_id = human_task.lane_assignment_id db.session.add(details_model) db.session.commit() @@ -1180,11 +1179,16 @@ class ProcessInstanceProcessor: ) return user_tasks # type: ignore - def complete_task(self, task: SpiffTask, human_task: HumanTaskModel) -> None: + def complete_task( + self, task: SpiffTask, human_task: HumanTaskModel, user: UserModel + ) -> None: """Complete_task.""" self.increment_spiff_step() self.bpmn_process_instance.complete_task_from_id(task.id) - self.save_spiff_step_details(human_task) + human_task.completed_by_user_id = user.id + db.session.add(human_task) + db.session.commit() + self.save_spiff_step_details() def get_data(self) -> dict[str, Any]: """Get_data.""" 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 7eee445a5..e933eda91 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -210,7 +210,7 @@ class ProcessInstanceService: dot_dct = ProcessInstanceService.create_dot_dict(data) spiff_task.update_data(dot_dct) # ProcessInstanceService.post_process_form(spiff_task) # some properties may update the data store. - processor.complete_task(spiff_task, human_task) + processor.complete_task(spiff_task, human_task, user=user) processor.do_engine_steps(save=True) @staticmethod diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py index 100651ef5..1a96ca882 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py @@ -179,6 +179,7 @@ class TestProcessInstanceProcessor(BaseTest): ProcessInstanceService.complete_form_task( processor, spiff_task, {}, initiator_user, human_task ) + assert human_task.completed_by_user_id == initiator_user.id assert len(process_instance.human_tasks) == 1 human_task = process_instance.human_tasks[0] @@ -198,6 +199,7 @@ class TestProcessInstanceProcessor(BaseTest): ProcessInstanceService.complete_form_task( processor, spiff_task, {}, finance_user_three, human_task ) + assert human_task.completed_by_user_id == finance_user_three.id assert len(process_instance.human_tasks) == 1 human_task = process_instance.human_tasks[0] assert human_task.lane_assignment_id is None @@ -215,6 +217,7 @@ class TestProcessInstanceProcessor(BaseTest): ProcessInstanceService.complete_form_task( processor, spiff_task, {}, finance_user_four, human_task ) + assert human_task.completed_by_user_id == finance_user_four.id assert len(process_instance.human_tasks) == 1 human_task = process_instance.human_tasks[0] assert human_task.lane_assignment_id is None @@ -250,7 +253,7 @@ class TestProcessInstanceProcessor(BaseTest): with_db_and_bpmn_file_cleanup: None, with_super_admin_user: UserModel, ) -> None: - """Test_sets_permission_correctly_on_human_task_when_using_dict.""" + """Test_does_not_recreate_human_tasks_on_multiple_saves.""" self.create_process_group( client, with_super_admin_user, "test_group", "test_group" )