api: fix return of role associated to a workflow function (#8601)

This commit is contained in:
Frédéric Péters 2015-10-11 16:29:37 +02:00
parent caf87ecc34
commit 0d4f07d56f
2 changed files with 9 additions and 5 deletions

View File

@ -230,6 +230,7 @@ def test_get_user_compat_endpoint(local_user):
def test_formdef_list():
Role.wipe()
role = Role(name='Foo bar')
role.id = '14'
role.store()
FormDef.wipe()
@ -253,9 +254,8 @@ def test_formdef_list():
assert resp1.json[0]['keywords'] == ['mobile', 'test']
assert resp1.json[0]['functions'].keys() == ['_receiver']
assert resp1.json[0]['functions']['_receiver']['label'] == 'Recipient'
assert len(resp1.json[0]['functions']['_receiver']['roles']) == 1
assert resp1.json[0]['functions']['_receiver']['roles'][0]['slug'] == role.slug
assert resp1.json[0]['functions']['_receiver']['roles'][0]['name'] == role.name
assert resp1.json[0]['functions']['_receiver']['role']['slug'] == role.slug
assert resp1.json[0]['functions']['_receiver']['role']['name'] == role.name
def test_formdef_list_redirection():
FormDef.wipe()

View File

@ -292,8 +292,12 @@ class ApiFormdefsDirectory(Directory):
formdef_workflow_roles = formdef.workflow_roles or {}
for (wf_role_id, wf_role_label) in formdef.workflow.roles.items():
workflow_function = {'label': wf_role_label}
workflow_function['roles'] = [Role.get(x).get_json_export_dict()
for x in formdef_workflow_roles.get(wf_role_id) or []]
role_id = formdef_workflow_roles.get(wf_role_id)
if role_id:
try:
workflow_function['role'] = Role.get(role_id).get_json_export_dict()
except KeyError:
pass
formdict['functions'][wf_role_id] = workflow_function
if formdef.category: