Add is_admin_workflow attribute to WorkflowApi and WorkflowApiSchema

Set is_admin_workflow when we instantiate WorkflowApi in WorkflowService.processor_to_workflow_api
This commit is contained in:
mike cullerton 2022-05-24 15:57:08 -04:00
parent 132a140d5a
commit 2c083f73a8
2 changed files with 7 additions and 4 deletions

View File

@ -213,7 +213,7 @@ class DocumentDirectory(object):
class WorkflowApi(object):
def __init__(self, id, status, next_task, navigation,
workflow_spec_id, total_tasks, completed_tasks,
last_updated, is_review, title, study_id, state):
last_updated, is_review, title, study_id, state, is_admin_workflow=False):
self.id = id
self.status = status
self.next_task = next_task # The next task that requires user input.
@ -226,6 +226,7 @@ class WorkflowApi(object):
self.is_review = is_review
self.study_id = study_id or ''
self.state = state
self.is_admin_workflow = is_admin_workflow
class WorkflowApiSchema(ma.Schema):
@ -233,7 +234,7 @@ class WorkflowApiSchema(ma.Schema):
model = WorkflowApi
fields = ["id", "status", "next_task", "navigation",
"workflow_spec_id", "total_tasks", "completed_tasks",
"last_updated", "is_review", "title", "study_id", "state"]
"last_updated", "is_review", "title", "study_id", "state", "is_admin_workflow"]
unknown = INCLUDE
status = EnumField(WorkflowStatus)
@ -245,7 +246,7 @@ class WorkflowApiSchema(ma.Schema):
def make_workflow(self, data, **kwargs):
keys = ['id', 'status', 'next_task', 'navigation',
'workflow_spec_id', "total_tasks", "completed_tasks",
"last_updated", "is_review", "title", "study_id", "state"]
"last_updated", "is_review", "title", "study_id", "state", "is_admin_workflow"]
filtered_fields = {key: data[key] for key in keys}
filtered_fields['next_task'] = TaskSchema().make_task(data['next_task'])
return WorkflowApi(**filtered_fields)

View File

@ -664,6 +664,7 @@ class WorkflowService(object):
WorkflowService.update_navigation(navigation, processor)
spec_service = WorkflowSpecService()
spec = spec_service.get_spec(processor.workflow_spec_id)
is_admin_workflow = WorkflowService.is_in_admin_category(processor.workflow_spec_id)
workflow_api = WorkflowApi(
id=processor.get_workflow_id(),
status=processor.get_status(),
@ -676,7 +677,8 @@ class WorkflowService(object):
is_review=spec.is_review,
title=spec.display_name,
study_id=processor.workflow_model.study_id or None,
state=processor.workflow_model.state
state=processor.workflow_model.state,
is_admin_workflow=is_admin_workflow
)
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.