Handling incoming values from processor
This commit is contained in:
parent
e947f40ec7
commit
4db815a999
|
@ -28,8 +28,9 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||
self.get_content(task, {})
|
||||
|
||||
def do_task(self, task, *args, **kwargs):
|
||||
subject = self.get_subject(task, args)
|
||||
recipients, display_keys = self.get_users_info(task, args)
|
||||
args = [arg for arg in args if type(arg) == str]
|
||||
subject, subject_index = self.get_subject(task, args)
|
||||
recipients, display_keys = self.get_users_info(task, args, subject_index)
|
||||
content, content_html = self.get_content(task, display_keys)
|
||||
if recipients:
|
||||
send_mail(
|
||||
|
@ -40,7 +41,7 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||
content_html=content_html
|
||||
)
|
||||
|
||||
def get_users_info(self, task, args):
|
||||
def get_users_info(self, task, args, subject_index):
|
||||
if len(args) < 1:
|
||||
raise ApiError(code="missing_argument",
|
||||
message="Email script requires at least one argument. The "
|
||||
|
@ -48,7 +49,7 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||
"id to process. Multiple arguments are accepted.")
|
||||
emails = []
|
||||
display_keys = {}
|
||||
for arg in args[1:]:
|
||||
for arg in args[subject_index+1:]:
|
||||
uid = task.workflow.script_engine.evaluate_expression(task, arg)
|
||||
user_info = LdapService.user_info(uid)
|
||||
email = user_info.email_address
|
||||
|
@ -69,15 +70,27 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||
message="Email script requires at least one subject argument. The "
|
||||
"name of the variable in the task data that contains subject"
|
||||
" to process. Multiple arguments are accepted.")
|
||||
subject = task.workflow.script_engine.evaluate_expression(task, args[0])
|
||||
if not isinstance(subject, str):
|
||||
raise ApiError(code="invalid_argument",
|
||||
message="The Email script requires 1 argument. The "
|
||||
"the name of the variable in the task data that contains user"
|
||||
"ids to process. This must point to an array or a string, but "
|
||||
"it currently points to a %s " % subject.__class__.__name__)
|
||||
|
||||
return subject
|
||||
subject_index = 0
|
||||
subject = args[subject_index]
|
||||
if subject.startswith('"') and not subject.endswith('"'):
|
||||
# Multi-word subject
|
||||
subject_index += 1
|
||||
next_word = args[subject_index]
|
||||
while not next_word.endswith('"'):
|
||||
subject = ' '.join((subject, next_word))
|
||||
subject_index += 1
|
||||
next_word = args[subject_index]
|
||||
subject = ' '.join((subject, next_word))
|
||||
subject = subject.replace('"', '')
|
||||
if not isinstance(subject, str):
|
||||
raise ApiError(code="invalid_argument",
|
||||
message="The Email script requires 1 argument. The "
|
||||
"the name of the variable in the task data that contains user"
|
||||
"ids to process. This must point to an array or a string, but "
|
||||
"it currently points to a %s " % subject.__class__.__name__)
|
||||
|
||||
return subject, subject_index
|
||||
|
||||
def get_content(self, task, display_keys):
|
||||
content = task.task_spec.documentation
|
||||
|
|
|
@ -60,7 +60,7 @@ class CustomBpmnScriptEngine(BpmnScriptEngine):
|
|||
"does not properly implement the CRC Script class.",
|
||||
task=task)
|
||||
if task.workflow.data[WorkflowProcessor.VALIDATION_PROCESS_KEY]:
|
||||
"""If this is running a validation, and not a normal process, then we want to
|
||||
"""If this is running a validation, and not a normal process, then we want to
|
||||
mimic running the script, but not make any external calls or database changes."""
|
||||
klass().do_task_validate_only(task, study_id, workflow_id, *commands[1:])
|
||||
else:
|
||||
|
|
|
@ -19,7 +19,7 @@ Email content to be delivered to {{ ApprvlApprvr1 }}
|
|||
---</bpmn:documentation>
|
||||
<bpmn:incoming>Flow_08n2npe</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_1xlrgne</bpmn:outgoing>
|
||||
<bpmn:script>Email Subject ApprvlApprvr1 PIComputingID</bpmn:script>
|
||||
<bpmn:script>Email "Camunda Email Subject" ApprvlApprvr1 PIComputingID</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_1synsig" sourceRef="StartEvent_1" targetRef="Activity_1l9vih3" />
|
||||
<bpmn:sequenceFlow id="Flow_1xlrgne" sourceRef="Activity_0s5v97n" targetRef="Event_0izrcj4" />
|
||||
|
|
|
@ -11,22 +11,26 @@ from crc import db
|
|||
class TestEmailScript(BaseTest):
|
||||
|
||||
def test_do_task(self):
|
||||
self.load_example_data()
|
||||
self.create_reference_document()
|
||||
# self.load_example_data()
|
||||
# self.create_reference_document()
|
||||
workflow = self.create_workflow('email')
|
||||
processor = WorkflowProcessor(workflow)
|
||||
task = processor.next_task()
|
||||
# TODO: Replace with proper `complete_form` method from test_tasks
|
||||
processor.complete_task(task)
|
||||
task = processor.next_task()
|
||||
task.data = {
|
||||
'PIComputingID': 'dhf8r',
|
||||
'ApprvlApprvr1': 'lb3dp',
|
||||
'Subject': 'Email Script needs your help'
|
||||
}
|
||||
|
||||
script = Email()
|
||||
script.do_task(task, 'Subject', 'PIComputingID', 'ApprvlApprvr1')
|
||||
# processor = WorkflowProcessor(workflow)
|
||||
# task = processor.next_task()
|
||||
# TODO: Replace with proper `complete_form` method from test_tasks
|
||||
# processor.complete_task(task)
|
||||
# task = processor.next_task()
|
||||
task_data = {
|
||||
'PIComputingID': 'dhf8r',
|
||||
'ApprvlApprvr1': 'lb3dp'
|
||||
}
|
||||
task = self.get_workflow_api(workflow).next_task
|
||||
|
||||
self.complete_form(workflow, task, task_data)
|
||||
|
||||
|
||||
# script = Email()
|
||||
# script.do_task(task, 'Subject', 'PIComputingID', 'ApprvlApprvr1')
|
||||
|
||||
# TODO: Add proper assertions
|
||||
self.assertTrue(True)
|
||||
|
|
|
@ -61,14 +61,14 @@ class TestFileService(BaseTest):
|
|||
|
||||
# Archive the file
|
||||
file_models = FileService.get_workflow_files(workflow_id=workflow.id)
|
||||
self.assertEquals(1, len(file_models))
|
||||
self.assertEqual(1, len(file_models))
|
||||
file_model = file_models[0]
|
||||
file_model.archived = True
|
||||
db.session.add(file_model)
|
||||
|
||||
# Assure that the file no longer comes back.
|
||||
file_models = FileService.get_workflow_files(workflow_id=workflow.id)
|
||||
self.assertEquals(0, len(file_models))
|
||||
self.assertEqual(0, len(file_models))
|
||||
|
||||
# Add the file again with different data
|
||||
FileService.add_workflow_file(workflow_id=workflow.id,
|
||||
|
|
|
@ -91,7 +91,6 @@ class TestFilesApi(BaseTest):
|
|||
content_type='multipart/form-data', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
|
||||
|
||||
def test_archive_file_no_longer_shows_up(self):
|
||||
self.load_example_data()
|
||||
self.create_reference_document()
|
||||
|
@ -109,21 +108,16 @@ class TestFilesApi(BaseTest):
|
|||
self.assert_success(rv)
|
||||
rv = self.app.get('/v1.0/file?workflow_id=%s' % workflow.id, headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
self.assertEquals(1, len(json.loads(rv.get_data(as_text=True))))
|
||||
self.assertEqual(1, len(json.loads(rv.get_data(as_text=True))))
|
||||
|
||||
file_model = db.session.query(FileModel).filter(FileModel.workflow_id == workflow.id).all()
|
||||
self.assertEquals(1, len(file_model))
|
||||
self.assertEqual(1, len(file_model))
|
||||
file_model[0].archived = True
|
||||
db.session.commit()
|
||||
|
||||
rv = self.app.get('/v1.0/file?workflow_id=%s' % workflow.id, headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
self.assertEquals(0, len(json.loads(rv.get_data(as_text=True))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
self.assertEqual(0, len(json.loads(rv.get_data(as_text=True))))
|
||||
|
||||
def test_set_reference_file(self):
|
||||
file_name = "irb_document_types.xls"
|
||||
|
@ -285,8 +279,8 @@ class TestFilesApi(BaseTest):
|
|||
.filter(ApprovalModel.status == ApprovalStatus.PENDING.value)\
|
||||
.filter(ApprovalModel.study_id == workflow.study_id).all()
|
||||
|
||||
self.assertEquals(1, len(approvals))
|
||||
self.assertEquals(1, len(approvals[0].approval_files))
|
||||
self.assertEqual(1, len(approvals))
|
||||
self.assertEqual(1, len(approvals[0].approval_files))
|
||||
|
||||
|
||||
def test_change_primary_bpmn(self):
|
||||
|
|
Loading…
Reference in New Issue