dropping the "read_only" flag in favor of a "do_engine_steps" flag, which more clearly defines what is happening.
This commit is contained in:
parent
f15626033d
commit
4d11fc04a0
|
@ -622,10 +622,10 @@ paths:
|
|||
description: Set this to true to reset the workflow
|
||||
schema:
|
||||
type: boolean
|
||||
- name: read_only
|
||||
- name: do_engine_steps
|
||||
in: query
|
||||
required: false
|
||||
description: Does not run any automatic or script tasks and should not be used for updates.
|
||||
description: Defaults to true, can be set to false if you are just looking at the workflow not completeing it.
|
||||
schema:
|
||||
type: boolean
|
||||
tags:
|
||||
|
|
|
@ -95,18 +95,18 @@ def delete_workflow_specification(spec_id):
|
|||
session.commit()
|
||||
|
||||
|
||||
def get_workflow(workflow_id, soft_reset=False, hard_reset=False, read_only=False):
|
||||
def get_workflow(workflow_id, soft_reset=False, hard_reset=False, do_engine_steps=True):
|
||||
"""Soft reset will attempt to update to the latest spec without starting over,
|
||||
Hard reset will update to the latest spec and start from the beginning.
|
||||
Read Only will return the workflow in a read only state, without running any
|
||||
engine tasks or logging any events. """
|
||||
workflow_model: WorkflowModel = session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
||||
processor = WorkflowProcessor(workflow_model, soft_reset=soft_reset, hard_reset=hard_reset)
|
||||
if not read_only:
|
||||
if do_engine_steps:
|
||||
processor.do_engine_steps()
|
||||
processor.save()
|
||||
WorkflowService.update_task_assignments(processor)
|
||||
workflow_api_model = WorkflowService.processor_to_workflow_api(processor, read_only=read_only)
|
||||
workflow_api_model = WorkflowService.processor_to_workflow_api(processor)
|
||||
return WorkflowApiSchema().dump(workflow_api_model)
|
||||
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class NavigationItemSchema(ma.Schema):
|
|||
class WorkflowApi(object):
|
||||
def __init__(self, id, status, next_task, navigation,
|
||||
spec_version, is_latest_spec, workflow_spec_id, total_tasks, completed_tasks,
|
||||
last_updated, title, read_only):
|
||||
last_updated, title):
|
||||
self.id = id
|
||||
self.status = status
|
||||
self.next_task = next_task # The next task that requires user input.
|
||||
|
@ -156,14 +156,13 @@ class WorkflowApi(object):
|
|||
self.completed_tasks = completed_tasks
|
||||
self.last_updated = last_updated
|
||||
self.title = title
|
||||
self.read_only = read_only
|
||||
|
||||
class WorkflowApiSchema(ma.Schema):
|
||||
class Meta:
|
||||
model = WorkflowApi
|
||||
fields = ["id", "status", "next_task", "navigation",
|
||||
"workflow_spec_id", "spec_version", "is_latest_spec", "total_tasks", "completed_tasks",
|
||||
"last_updated", "title", "read_only"]
|
||||
"last_updated", "title"]
|
||||
unknown = INCLUDE
|
||||
|
||||
status = EnumField(WorkflowStatus)
|
||||
|
@ -174,7 +173,7 @@ class WorkflowApiSchema(ma.Schema):
|
|||
def make_workflow(self, data, **kwargs):
|
||||
keys = ['id', 'status', 'next_task', 'navigation',
|
||||
'workflow_spec_id', 'spec_version', 'is_latest_spec', "total_tasks", "completed_tasks",
|
||||
"last_updated", "title", "read_only"]
|
||||
"last_updated", "title"]
|
||||
filtered_fields = {key: data[key] for key in keys}
|
||||
filtered_fields['next_task'] = TaskSchema().make_task(data['next_task'])
|
||||
return WorkflowApi(**filtered_fields)
|
||||
|
|
|
@ -216,7 +216,7 @@ class WorkflowService(object):
|
|||
return ''.join(random.choice(letters) for i in range(string_length))
|
||||
|
||||
@staticmethod
|
||||
def processor_to_workflow_api(processor: WorkflowProcessor, next_task=None, read_only=False):
|
||||
def processor_to_workflow_api(processor: WorkflowProcessor, next_task=None):
|
||||
"""Returns an API model representing the state of the current workflow, if requested, and
|
||||
possible, next_task is set to the current_task."""
|
||||
|
||||
|
@ -260,8 +260,7 @@ class WorkflowService(object):
|
|||
total_tasks=len(navigation),
|
||||
completed_tasks=processor.workflow_model.completed_tasks,
|
||||
last_updated=processor.workflow_model.last_updated,
|
||||
title=spec.display_name,
|
||||
read_only=read_only
|
||||
title=spec.display_name
|
||||
)
|
||||
if not next_task: # The Next Task can be requested to be a certain task, useful for parallel tasks.
|
||||
# This may or may not work, sometimes there is no next task to complete.
|
||||
|
|
|
@ -308,13 +308,13 @@ class BaseTest(unittest.TestCase):
|
|||
db.session.commit()
|
||||
return approval
|
||||
|
||||
def get_workflow_api(self, workflow, soft_reset=False, hard_reset=False, read_only=False, user_uid="dhf8r"):
|
||||
def get_workflow_api(self, workflow, soft_reset=False, hard_reset=False, do_engine_steps=True, user_uid="dhf8r"):
|
||||
user = session.query(UserModel).filter_by(uid=user_uid).first()
|
||||
self.assertIsNotNone(user)
|
||||
rv = self.app.get(f'/v1.0/workflow/{workflow.id}'
|
||||
f'?soft_reset={str(soft_reset)}'
|
||||
f'&hard_reset={str(hard_reset)}'
|
||||
f'&read_only={str(read_only)}',
|
||||
f'&do_engine_steps={str(do_engine_steps)}',
|
||||
headers=self.logged_in_headers(user),
|
||||
content_type="application/json")
|
||||
self.assert_success(rv)
|
||||
|
|
|
@ -43,11 +43,11 @@ class TestTasksApi(BaseTest):
|
|||
"""
|
||||
self.assertTrue(str.startswith(task.documentation, expected_docs))
|
||||
|
||||
def test_get_read_only_workflow(self):
|
||||
def test_get_workflow_without_running_engine_steps(self):
|
||||
# Set up a new workflow
|
||||
workflow = self.create_workflow('two_forms')
|
||||
# get the first form in the two form workflow.
|
||||
workflow_api = self.get_workflow_api(workflow, read_only=True)
|
||||
workflow_api = self.get_workflow_api(workflow, do_engine_steps=False)
|
||||
|
||||
# There should be no task event logs related to the workflow at this point.
|
||||
task_events = session.query(TaskEventModel).filter(TaskEventModel.workflow_id == workflow.id).all()
|
||||
|
@ -57,8 +57,8 @@ class TestTasksApi(BaseTest):
|
|||
# current task should be the start event.
|
||||
self.assertEqual("Start", workflow_api.next_task.name)
|
||||
|
||||
# the workflow_api should have a read_only attribute set to true
|
||||
self.assertEquals(True, workflow_api.read_only)
|
||||
def test_get_form_for_previously_completed_task(self):
|
||||
"""Assure we can look at previously completed steps without moving the token for the workflow."""
|
||||
|
||||
|
||||
def test_two_forms_task(self):
|
||||
|
|
Loading…
Reference in New Issue