mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-22 12:48:25 +00:00
Rendering proper content & organizing file structure for email tests
This commit is contained in:
parent
c730a7b1ec
commit
2ce2dc73b5
@ -29,6 +29,9 @@ class LdapModel(db.Model):
|
|||||||
affiliation=", ".join(entry.uvaPersonIAMAffiliation),
|
affiliation=", ".join(entry.uvaPersonIAMAffiliation),
|
||||||
sponsor_type=", ".join(entry.uvaPersonSponsoredType))
|
sponsor_type=", ".join(entry.uvaPersonSponsoredType))
|
||||||
|
|
||||||
|
def proper_name(self):
|
||||||
|
return f'{self.display_name} - ({self.uid})'
|
||||||
|
|
||||||
|
|
||||||
class LdapSchema(SQLAlchemyAutoSchema):
|
class LdapSchema(SQLAlchemyAutoSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -22,12 +22,14 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def do_task_validate_only(self, task, *args, **kwargs):
|
def do_task_validate_only(self, task, *args, **kwargs):
|
||||||
self.get_emails(task, args)
|
self.get_subject(task, args)
|
||||||
|
self.get_users_info(task, args)
|
||||||
|
self.get_content(task, {})
|
||||||
|
|
||||||
def do_task(self, task, *args, **kwargs):
|
def do_task(self, task, *args, **kwargs):
|
||||||
subject = self.get_subject(task, args)
|
subject = self.get_subject(task, args)
|
||||||
recipients = self.get_emails(task, args)
|
recipients, display_keys = self.get_users_info(task, args)
|
||||||
content = self.get_content(task)
|
content = self.get_content(task, display_keys)
|
||||||
if recipients:
|
if recipients:
|
||||||
send_mail(
|
send_mail(
|
||||||
subject=subject,
|
subject=subject,
|
||||||
@ -37,18 +39,20 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||||||
content_html=content
|
content_html=content
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_emails(self, task, args):
|
def get_users_info(self, task, args):
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
raise ApiError(code="missing_argument",
|
raise ApiError(code="missing_argument",
|
||||||
message="Email script requires at least one argument. The "
|
message="Email script requires at least one argument. The "
|
||||||
"name of the variable in the task data that contains user"
|
"name of the variable in the task data that contains user"
|
||||||
"id to process. Multiple arguments are accepted.")
|
"id to process. Multiple arguments are accepted.")
|
||||||
emails = []
|
emails = []
|
||||||
|
display_keys = {}
|
||||||
for arg in args[1:]:
|
for arg in args[1:]:
|
||||||
uid = task.workflow.script_engine.evaluate_expression(task, arg)
|
uid = task.workflow.script_engine.evaluate_expression(task, arg)
|
||||||
user_info = LdapService.user_info(uid)
|
user_info = LdapService.user_info(uid)
|
||||||
email = user_info.email_address
|
email = user_info.email_address
|
||||||
emails.append(user_info.email_address)
|
emails.append(user_info.email_address)
|
||||||
|
display_keys[arg] = user_info.proper_name()
|
||||||
if not isinstance(email, str):
|
if not isinstance(email, str):
|
||||||
raise ApiError(code="invalid_argument",
|
raise ApiError(code="invalid_argument",
|
||||||
message="The Email script requires at least 1 UID argument. The "
|
message="The Email script requires at least 1 UID argument. The "
|
||||||
@ -56,7 +60,7 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||||||
" user ids to process. This must point to an array or a string, but "
|
" user ids to process. This must point to an array or a string, but "
|
||||||
"it currently points to a %s " % emails.__class__.__name__)
|
"it currently points to a %s " % emails.__class__.__name__)
|
||||||
|
|
||||||
return emails
|
return emails, display_keys
|
||||||
|
|
||||||
def get_subject(self, task, args):
|
def get_subject(self, task, args):
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
@ -74,9 +78,9 @@ Email Subject ApprvlApprvr1 PIComputingID
|
|||||||
|
|
||||||
return subject
|
return subject
|
||||||
|
|
||||||
def get_content(self, task):
|
def get_content(self, task, display_keys):
|
||||||
content = task.task_spec.documentation
|
content = task.task_spec.documentation
|
||||||
template = Template(content)
|
template = Template(content)
|
||||||
rendered = template.render({'approver': 'Bossman', 'not_here': 22})
|
rendered = template.render(display_keys)
|
||||||
|
|
||||||
return rendered
|
return rendered
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<bpmn:incoming>Flow_1xlrgne</bpmn:incoming>
|
<bpmn:incoming>Flow_1xlrgne</bpmn:incoming>
|
||||||
</bpmn:endEvent>
|
</bpmn:endEvent>
|
||||||
<bpmn:scriptTask id="Activity_0s5v97n" name="Email Recipients">
|
<bpmn:scriptTask id="Activity_0s5v97n" name="Email Recipients">
|
||||||
<bpmn:documentation>Email content to be delivered to {{ approver }}</bpmn:documentation>
|
<bpmn:documentation>Email content to be delivered to {{ ApprvlApprvr1 }}</bpmn:documentation>
|
||||||
<bpmn:incoming>Flow_08n2npe</bpmn:incoming>
|
<bpmn:incoming>Flow_08n2npe</bpmn:incoming>
|
||||||
<bpmn:outgoing>Flow_1xlrgne</bpmn:outgoing>
|
<bpmn:outgoing>Flow_1xlrgne</bpmn:outgoing>
|
||||||
<bpmn:script>Email Subject ApprvlApprvr1 PIComputingID</bpmn:script>
|
<bpmn:script>Email Subject ApprvlApprvr1 PIComputingID</bpmn:script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user