Removing extra index when parsing users info

This commit is contained in:
Carlos Lopez 2020-06-18 12:53:50 -06:00
parent 4db815a999
commit e6d74aaa1a
3 changed files with 15 additions and 10 deletions

View File

@ -14,7 +14,7 @@ from crc.services.mails import send_test_email
def render_markdown(data, template):
"""
Provides a quick way to very that a Jinja markdown template will work properly on a given json
Provides a quick way to very that a Jinja markdown template will work properly on a given json
data structure. Useful for folks that are building these markdown templates.
"""
try:

View File

@ -29,8 +29,8 @@ Email Subject ApprvlApprvr1 PIComputingID
def do_task(self, task, *args, **kwargs):
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)
subject = self.get_subject(task, args)
recipients, display_keys = self.get_users_info(task, args)
content, content_html = self.get_content(task, display_keys)
if recipients:
send_mail(
@ -41,7 +41,7 @@ Email Subject ApprvlApprvr1 PIComputingID
content_html=content_html
)
def get_users_info(self, task, args, subject_index):
def get_users_info(self, task, args):
if len(args) < 1:
raise ApiError(code="missing_argument",
message="Email script requires at least one argument. The "
@ -49,8 +49,13 @@ Email Subject ApprvlApprvr1 PIComputingID
"id to process. Multiple arguments are accepted.")
emails = []
display_keys = {}
for arg in args[subject_index+1:]:
uid = task.workflow.script_engine.evaluate_expression(task, arg)
for arg in args:
try:
uid = task.workflow.script_engine.evaluate_expression(task, arg)
except Exception as e:
app.logger.error(f'Workflow engines could not parse {arg}')
app.logger.error(str(e))
continue
user_info = LdapService.user_info(uid)
email = user_info.email_address
emails.append(user_info.email_address)
@ -90,7 +95,7 @@ Email Subject ApprvlApprvr1 PIComputingID
"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
return subject
def get_content(self, task, display_keys):
content = task.task_spec.documentation

View File

@ -175,9 +175,6 @@ Your random fact is:
<bpmndi:BPMNShape id="UserTask_186s7tw_di" bpmnElement="Task_User_Select_Type">
<dc:Bounds x="270" y="210" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ScriptTask_10keafb_di" bpmnElement="Task_Get_Fact_From_API">
<dc:Bounds x="470" y="210" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0u1cgrf_di" bpmnElement="EndEvent_0u1cgrf">
<dc:Bounds x="692" y="232" width="36" height="36" />
</bpmndi:BPMNShape>
@ -187,6 +184,9 @@ Your random fact is:
<bpmndi:BPMNShape id="TextAnnotation_1234e5n_di" bpmnElement="TextAnnotation_1234e5n">
<dc:Bounds x="570" y="120" width="100" height="68" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ScriptTask_10keafb_di" bpmnElement="Task_Get_Fact_From_API">
<dc:Bounds x="470" y="210" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Association_1cfasjp_di" bpmnElement="Association_1cfasjp">
<di:waypoint x="344" y="210" />
<di:waypoint x="359" y="184" />