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..dbffdf1f 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -158,7 +158,9 @@ class WorkflowService(object): if field.has_property(Task.FIELD_PROP_HIDE_EXPRESSION) and field.has_validation(Task.FIELD_CONSTRAINT_REQUIRED): if not field.has_property(Task.FIELD_PROP_VALUE_EXPRESSION) or not (hasattr(field, 'default_value')): raise ApiError(code='hidden and required field missing default', - message='Fields that are required but can be hidden must have either a default value or a value_expression') + message='Fields that are required but can be hidden must have either a default value or a value_expression', + task_id='task.id', + task_name=task.get_name()) # If the field is hidden and not required, it should not produce a value. if field.has_property(Task.FIELD_PROP_HIDE_EXPRESSION) and not field.has_validation(Task.FIELD_CONSTRAINT_REQUIRED): @@ -212,7 +214,7 @@ class WorkflowService(object): if not id[0].isalpha(): return False for char in id[1:len(id)]: - if char.isalnum() or char == '_': + if char.isalnum() or char == '_' or char == '.': pass else: return False @@ -510,9 +512,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): diff --git a/tests/data/workflow_form_field_name/workflow_form_field_name.bpmn b/tests/data/workflow_form_field_name/workflow_form_field_name.bpmn index 2794adec..19f08f98 100644 --- a/tests/data/workflow_form_field_name/workflow_form_field_name.bpmn +++ b/tests/data/workflow_form_field_name/workflow_form_field_name.bpmn @@ -1,5 +1,5 @@ - + Flow_0dbfi6t @@ -8,16 +8,16 @@ <H1>Hello</H1> Flow_0dbfi6t - Flow_02rje6r + SequenceFlow_0o1egpu - + - Flow_02rje6r + SequenceFlow_1hytves Flow_1iphrck @@ -40,47 +40,61 @@ Flow_0hbiuz4 + + + SequenceFlow_0o1egpu + SequenceFlow_1hytves + me = {'name': 'my_name'} + + - - - - - - + + - - + + - - + + - - + + - + - + - + - + - + - + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_form_field_name.py b/tests/workflow/test_workflow_form_field_name.py index 655be9a9..0183f866 100644 --- a/tests/workflow/test_workflow_form_field_name.py +++ b/tests/workflow/test_workflow_form_field_name.py @@ -12,3 +12,14 @@ class TestFormFieldName(BaseTest): self.assertEqual(json_data[0]['message'], 'When populating all fields ... Invalid Field name: "user-title". A field ID must begin ' 'with a letter, and can only contain letters, numbers, and "_"') + + def test_form_field_name_with_period(self): + workflow = self.create_workflow('workflow_form_field_name') + + workflow_api = self.get_workflow_api(workflow) + first_task = workflow_api.next_task + self.complete_form(workflow_api, first_task, {}) + + workflow_api = self.get_workflow_api(workflow) + second_task = workflow_api.next_task + self.assertEqual('me.name', second_task.form['fields'][1]['id']) diff --git a/tests/workflow/test_workflow_hidden_required_field.py b/tests/workflow/test_workflow_hidden_required_field.py index fb22f6b9..9c635992 100644 --- a/tests/workflow/test_workflow_hidden_required_field.py +++ b/tests/workflow/test_workflow_hidden_required_field.py @@ -12,6 +12,8 @@ class TestWorkflowHiddenRequiredField(BaseTest): json_data = json.loads(rv.get_data(as_text=True)) self.assertEqual(json_data[0]['code'], 'hidden and required field missing default') + self.assertIn('task_id', json_data[0]) + self.assertIn('task_name', json_data[0]) def test_default_used(self): # If a field is hidden and required, make sure we use the default value