diff --git a/crc/api/workflow.py b/crc/api/workflow.py index a0fcb877..adb83abf 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -105,7 +105,13 @@ def drop_workflow_spec_library(spec_id, library_id): def validate_workflow_specification(spec_id, study_id=None, test_until=None): try: - WorkflowService.raise_if_disabled(spec_id, study_id) + master_spec = WorkflowSpecService().master_spec + if study_id is not None: + study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first() + statuses = WorkflowProcessor.run_master_spec(master_spec, study_model) + if spec_id in statuses and statuses[spec_id]['status'] == 'disabled': + raise ApiError(code='disabled_workflow', + message=f"This workflow is disabled. {statuses[spec_id]['message']}") WorkflowService.test_spec(spec_id, study_id, test_until) WorkflowService.test_spec(spec_id, study_id, test_until, required_only=True) except ApiError as ae: diff --git a/crc/services/file_system_service.py b/crc/services/file_system_service.py index 8d23997d..27ef49e2 100644 --- a/crc/services/file_system_service.py +++ b/crc/services/file_system_service.py @@ -43,6 +43,7 @@ class FileSystemService(object): else: category_path = FileSystemService.category_path(spec.category_id) return category_path + @staticmethod def workflow_path(spec: WorkflowSpecInfo): if spec.is_master_spec: diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 6b3355dc..dda225bd 100755 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -124,16 +124,6 @@ class WorkflowService(object): workflow_model.study_id, str(e))) - @staticmethod - def raise_if_disabled(spec_id, study_id): - """Raise an exception if the workflow is not enabled and can not be executed.""" - if study_id is not None: - study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first() - status = StudyService._get_study_status(study_model) - if spec_id in status and status[spec_id]['status'] == 'disabled': - raise ApiError(code='disabled_workflow', - message=f"This workflow is disabled. {status[spec_id]['message']}") - @staticmethod @timeit def test_spec(spec_id, validate_study_id=None, test_until=None, required_only=False): diff --git a/tests/test_tasks_api.py b/tests/test_tasks_api.py index 9c14ee8e..5699565b 100644 --- a/tests/test_tasks_api.py +++ b/tests/test_tasks_api.py @@ -189,7 +189,9 @@ class TestTasksApi(BaseTest): # Modify the specification, with a major change that alters the flow and can't be deserialized # effectively, if it uses the latest spec files. file_path = os.path.join(app.root_path, '..', 'tests', 'data', 'two_forms', 'modified', 'two_forms_struc_mod.bpmn') - self.replace_file(workflow.workflow_spec, "two_forms.bpmn", file_path) + self.workflow_spec_service.scan_file_system() + spec = self.workflow_spec_service.get_spec('two_forms') + self.replace_file(spec, "two_forms.bpmn", file_path) # This should use the original workflow spec, and just move to the next task workflow_api_2 = self.get_workflow_api(workflow) diff --git a/tests/workflow/test_workflow_spec_validation_api.py b/tests/workflow/test_workflow_spec_validation_api.py index e2d1a6ee..19a94510 100644 --- a/tests/workflow/test_workflow_spec_validation_api.py +++ b/tests/workflow/test_workflow_spec_validation_api.py @@ -121,7 +121,7 @@ class TestWorkflowSpecValidation(BaseTest): self.assertEqual(1, len(errors)) self.assertEqual("invalid_field_type", errors[0]['code']) - @patch('crc.services.study_service.StudyService._get_study_status') + @patch('crc.services.workflow_processor.WorkflowProcessor.run_master_spec') def test_disabled_spec_validation(self, mock_status): """A disabled workflow spec should fail validation""" app.config['PB_ENABLED'] = True