workflows: handle computed roles in dispatch xml import (#20327)

This commit is contained in:
Thomas NOËL 2017-11-28 14:15:46 +01:00
parent bb1f118155
commit 41bd08e8d2
2 changed files with 23 additions and 1 deletions

View File

@ -9,7 +9,8 @@ from wcs import publisher
from wcs.workflows import (Workflow, CommentableWorkflowStatusItem,
WorkflowCriticalityLevel, WorkflowBackofficeFieldsFormDef,
SendmailWorkflowStatusItem, SendSMSWorkflowStatusItem)
SendmailWorkflowStatusItem, SendSMSWorkflowStatusItem,
WorkflowImportError)
from wcs.wf.wscall import WebserviceCallStatusItem
from wcs.wf.dispatch import DispatchWorkflowStatusItem
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
@ -99,6 +100,22 @@ def test_action_dispatch(pub):
# checks role id is imported as integer
assert(wf2.possible_status[0].items[0].role_id == '5')
pub.cfg['sp'] = {'idp-manage-roles': True}
# now roles are managed: cannot create them
dispatch.role_id = 'unknown'
with pytest.raises(WorkflowImportError, match=r'.*Unknown referenced role.*'):
wf2 = assert_import_export_works(wf)
# but allow computed roles
dispatch.role_id = '=form_var_bar'
wf2 = assert_import_export_works(wf)
assert(wf2.possible_status[0].items[0].role_id == '=form_var_bar')
dispatch.role_id = 'Role {{ form_var_foo }}'
wf2 = assert_import_export_works(wf)
assert(wf2.possible_status[0].items[0].role_id == 'Role {{ form_var_foo }}')
dispatch.role_id = 'Role [form_var_foo]'
wf2 = assert_import_export_works(wf)
assert(wf2.possible_status[0].items[0].role_id == 'Role [form_var_foo]')
def test_status_actions_named_role(pub):
wf = Workflow(name='status')

View File

@ -888,6 +888,11 @@ class XmlSerialisable(object):
if role.name == value:
return role.id
# if a computed value is possible and value looks like
# an expression, use it
if value.startswith('=') or Template.is_template_string(value):
return value
# if the roles are managed by the idp, don't try further.
if get_publisher() and get_cfg('sp', {}).get('idp-manage-roles') is True:
raise WorkflowImportError(N_('Unknown referenced role (%s)'), (value,))