From ff8a44a7b1e030aab260a71f808e0ea69d03134e Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 16 Feb 2021 12:42:59 -0500 Subject: [PATCH] Make sure we always have a current user, even if the very first task is a script task. --- crc/services/workflow_processor.py | 10 ++++++++++ crc/services/workflow_service.py | 3 --- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crc/services/workflow_processor.py b/crc/services/workflow_processor.py index 92e8d68b..4eb7b027 100644 --- a/crc/services/workflow_processor.py +++ b/crc/services/workflow_processor.py @@ -22,10 +22,12 @@ from crc import session, app from crc.api.common import ApiError from crc.models.file import FileDataModel, FileModel, FileType from crc.models.task_event import TaskEventModel +from crc.models.user import UserModelSchema from crc.models.workflow import WorkflowStatus, WorkflowModel, WorkflowSpecDependencyFile from crc.scripts.script import Script from crc.services.file_service import FileService from crc import app +from crc.services.user_service import UserService class CustomBpmnScriptEngine(BpmnScriptEngine): @@ -167,10 +169,18 @@ class WorkflowProcessor(object): spec = None self.workflow_spec_id = workflow_model.workflow_spec_id + try: self.bpmn_workflow = self.__get_bpmn_workflow(workflow_model, spec, validate_only) self.bpmn_workflow.script_engine = self._script_engine + if UserService.has_user(): + current_user = UserService.current_user(allow_admin_impersonate=True) + current_user_data = UserModelSchema().dump(current_user) + tasks = self.bpmn_workflow.get_tasks(SpiffTask.READY) + for task in tasks: + task.data['current_user'] = current_user_data + if self.WORKFLOW_ID_KEY not in self.bpmn_workflow.data: if not workflow_model.id: session.add(workflow_model) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index f8fe759e..ba20ad3d 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -510,9 +510,6 @@ class WorkflowService(object): # not be a previously completed MI Task. if add_docs_and_forms: task.data = spiff_task.data - if UserService.has_user(): - current_user = UserService.current_user(allow_admin_impersonate=True) - task.data['current_user'] = UserModelSchema().dump(current_user) if hasattr(spiff_task.task_spec, "form"): task.form = spiff_task.task_spec.form for i, field in enumerate(task.form.fields):