misc: allow global actions for submitters (#22228)

This commit is contained in:
Frédéric Péters 2018-03-03 16:05:46 +01:00
parent 952655c044
commit b8fa1798fd
2 changed files with 53 additions and 1 deletions

View File

@ -4060,6 +4060,10 @@ def test_form_custom_select_template(pub):
assert '<!-- backoffice: False -->' in resp.body
def test_form_status_appearance_keywords(pub):
create_user(pub)
formdef = create_formdef()
formdef.data_class().wipe()
formdef = create_formdef()
formdef.fields = [
fields.ItemField(id='1', label='select', type='item',
@ -4088,3 +4092,48 @@ def test_form_status_appearance_keywords(pub):
resp = get_app(pub).get('/test/')
assert 'class="quixote foobar plop"' in resp.body
def test_user_global_action(pub):
user = create_user(pub)
workflow = Workflow.get_default_workflow()
workflow.id = '2'
action = workflow.add_global_action('FOOBAR')
register_comment = action.append_item('register-comment')
register_comment.comment = 'HELLO WORLD GLOBAL ACTION'
jump = action.append_item('jump')
jump.status = 'finished'
trigger = action.triggers[0]
workflow.store()
formdef = FormDef()
formdef.name = 'test global action'
formdef.fields = []
formdef.workflow_id = workflow.id
formdef.workflow_roles = {}
formdef.store()
formdef.data_class().wipe()
app = login(get_app(pub), username='foo', password='foo')
resp = app.get(formdef.get_url())
resp = resp.form.submit('submit')
resp = resp.form.submit('submit')
assert formdef.data_class().count() == 1
formdata = formdef.data_class().select()[0]
resp = app.get(formdata.get_url())
assert not 'button-action-1' in resp.body
trigger.roles = ['_submitter']
workflow.store()
resp = app.get(formdata.get_url())
assert 'button-action-1' in resp.form.fields
resp = resp.form.submit('button-action-1')
resp = app.get(formdata.get_url())
assert 'HELLO WORLD GLOBAL ACTION' in resp.body
assert formdef.data_class().get(formdata.id).status == 'wf-finished'

View File

@ -402,8 +402,11 @@ class Workflow(StorableObject):
for action in self.global_actions or []:
for trigger in action.triggers or []:
if isinstance(trigger, WorkflowGlobalActionManualTrigger):
if '_submitter' in (trigger.roles or []) and formdata.is_submitter(user):
actions.append(action)
break
roles = [get_role_translation(formdata, x)
for x in (trigger.roles or [])]
for x in (trigger.roles or []) if x != '_submitter']
if set(roles).intersection(user.roles or []):
actions.append(action)
break