workflows: add parameter to set custom from address in email action (#10175)

This commit is contained in:
Frédéric Péters 2017-03-02 15:25:56 +01:00
parent 12124f14ab
commit 63c3fdd4d5
2 changed files with 30 additions and 3 deletions

View File

@ -672,6 +672,24 @@ def test_email(pub):
get_response().process_after_jobs()
assert emails.count() == 0
# custom from email
emails.empty()
item.to = [role1.id]
item.custom_from = 'foobar@localhost'
item.perform(formdata)
get_response().process_after_jobs()
assert emails.count() == 1
assert emails.get('foobar').get('from') == 'foobar@localhost'
# custom from email (computed)
emails.empty()
item.to = [role1.id]
item.custom_from = '="foobar@localhost"'
item.perform(formdata)
get_response().process_after_jobs()
assert emails.count() == 1
assert emails.get('foobar').get('from') == 'foobar@localhost'
def test_webservice_call(pub):
pub.substitutions.feed(MockSubstitutionVariables())

View File

@ -1953,6 +1953,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
to = []
subject = None
body = None
custom_from = None
comment = None
@ -1991,7 +1992,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
return _('Send mail (not completed)')
def get_parameters(self):
return ('to', 'subject', 'body')
return ('to', 'subject', 'body', 'custom_from')
def fill_admin_form(self, form):
self.add_parameters_widgets(form, self.get_parameters())
@ -2014,6 +2015,10 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
value=self.body, cols=80, rows=10,
validation_function=ComputedExpressionWidget.validate_ezt,
hint=_('Available variables: url, url_status, details, name, number, comment, field_NAME'))
if 'custom_from' in parameters:
form.add(ComputedExpressionWidget, '%scustom_from' % prefix,
title=_('Custom From Address'), value=self.custom_from,
advanced=not(bool(self.custom_from)))
def get_body_parameter_view_value(self):
return htmltext('<pre class="wrapping-pre">%s</pre>') % self.body
@ -2082,14 +2087,18 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
if not addresses:
return
email_from = None
if self.custom_from:
email_from = self.compute(self.custom_from)
if len(addresses) > 1:
emails.email(mail_subject, mail_body, email_rcpt=None,
bcc=addresses,
bcc=addresses, email_from=email_from,
exclude_current_user=False,
fire_and_forget=True)
else:
emails.email(mail_subject, mail_body, email_rcpt=addresses,
exclude_current_user=False,
email_from=email_from, exclude_current_user=False,
fire_and_forget=True)
register_item_class(SendmailWorkflowStatusItem)