workflows: add custom handling for computed email destinations (#13935)

This commit is contained in:
Frédéric Péters 2016-11-12 17:11:16 +01:00
parent 62c0b5bd62
commit 76f31806c0
2 changed files with 33 additions and 2 deletions

View File

@ -7,7 +7,8 @@ from quixote import cleanup
from wcs import publisher
from wcs.workflows import (Workflow, CommentableWorkflowStatusItem,
WorkflowCriticalityLevel, WorkflowBackofficeFieldsFormDef)
WorkflowCriticalityLevel, WorkflowBackofficeFieldsFormDef,
SendmailWorkflowStatusItem)
from wcs.wf.wscall import WebserviceCallStatusItem
from wcs.wf.dispatch import DispatchWorkflowStatusItem
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
@ -441,6 +442,24 @@ def test_display_message_action():
wf2 = assert_import_export_works(wf, include_id=True)
def test_sendmail_other_destination():
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
sendmail = SendmailWorkflowStatusItem()
sendmail.to = ['_submitter']
st1.items.append(sendmail)
sendmail.parent = st1
Role.wipe()
wf2 = assert_import_export_works(wf)
assert Role.count() == 0
sendmail.to = ['_submitter', '=form_var_plop', '[form_var_plop]', 'foobar@localhost']
wf2 = assert_import_export_works(wf)
assert Role.count() == 0
assert wf2.possible_status[0].items[0].to == sendmail.to
def test_criticality_level():
wf = Workflow(name='criticality level')
wf.criticality_levels = [

View File

@ -1953,10 +1953,22 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem):
comment = None
def _get_role_id_from_xml(self, elem, charset, include_id=False):
# override to allow for destination set with computed values.
if elem is None:
return None
value = elem.text.encode(charset)
if value.startswith('=') or '@' in value or '[' in value:
return value
return super(SendmailWorkflowStatusItem, self)._get_role_id_from_xml(
elem, charset, include_id=include_id)
def render_list_of_roles_or_emails(self, roles):
t = []
for r in roles:
if r.startswith('='):
if r.startswith('=') or '[' in r:
t.append(_('computed value'))
elif '@' in r:
t.append(r)