api: publish formdef workflow functions (#8589)
This commit is contained in:
parent
123fc09698
commit
ae14c854da
|
@ -228,11 +228,16 @@ def test_get_user_compat_endpoint(local_user):
|
|||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
|
||||
def test_formdef_list():
|
||||
Role.wipe()
|
||||
role = Role(name='Foo bar')
|
||||
role.store()
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test'
|
||||
formdef.description = 'plop'
|
||||
formdef.keywords = 'mobile, test'
|
||||
formdef.workflow_roles = {'_receiver': str(role.id)}
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
|
@ -246,6 +251,11 @@ def test_formdef_list():
|
|||
assert resp1.json[0]['redirection'] == False
|
||||
assert resp1.json[0]['description'] == 'plop'
|
||||
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
|
||||
|
||||
def test_formdef_list_redirection():
|
||||
FormDef.wipe()
|
||||
|
|
|
@ -288,6 +288,14 @@ class ApiFormdefsDirectory(Directory):
|
|||
# them by popularity
|
||||
formdict['count'] = formdef.data_class().count()
|
||||
|
||||
formdict['functions'] = {}
|
||||
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 []]
|
||||
formdict['functions'][wf_role_id] = workflow_function
|
||||
|
||||
if formdef.category:
|
||||
formdict['category'] = unicode(formdef.category.name, charset)
|
||||
formdict['category_position'] = (formdef.category.position or 0)
|
||||
|
|
Loading…
Reference in New Issue