api: export roles associated to a formdata (#8485)
This commit is contained in:
parent
ade043ea2a
commit
18e4eafc20
|
@ -67,6 +67,45 @@ Le contenu ainsi obtenu est le suivant :
|
|||
"liste": "lalettre@example.com"
|
||||
}
|
||||
}
|
||||
},
|
||||
"roles": {
|
||||
"_receiver": [
|
||||
{
|
||||
"emails_to_members": false,
|
||||
"name": "Agents traitants",
|
||||
"text": "",
|
||||
"emails": [],
|
||||
"slug": "agents-traitants",
|
||||
"details": "",
|
||||
"id": "1",
|
||||
"allows_backoffice_access": true
|
||||
}
|
||||
],
|
||||
"concerned": [
|
||||
{
|
||||
"emails_to_members": false,
|
||||
"name": "Agents traitants",
|
||||
"text": "",
|
||||
"emails": [],
|
||||
"slug": "agents-traitants",
|
||||
"details": "",
|
||||
"id": "1",
|
||||
"allows_backoffice_access": true
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"emails_to_members": false,
|
||||
"name": "Agents traitants",
|
||||
"text": "",
|
||||
"emails": [],
|
||||
"slug": "agents-traitants",
|
||||
"details": "",
|
||||
"name": "test",
|
||||
"id": "1",
|
||||
"allows_backoffice_access": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
</code>
|
||||
|
@ -75,6 +114,15 @@ Le contenu ainsi obtenu est le suivant :
|
|||
Seuls les champs ayant un <em>nom de variable</em> sont exportés dans <code>fields</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Concernant les rôles et fonctions de workflow, les différents intervenants sont
|
||||
listés dans l'attribut <code>roles</code>, en différentes séries qui vont
|
||||
dépendre de fonctions attachées au workflow. Deux séries sont particulières,
|
||||
la série <code>concerned</code> reprend les rôles concernés par la demande et
|
||||
la série <code>actions</code> reprend les rôles disposant d'une capacité
|
||||
d'action sur la demande.
|
||||
</p>
|
||||
|
||||
<note>
|
||||
<p>
|
||||
Il est bien sûr nécessaire de disposer des autorisations nécessaires pour
|
||||
|
|
|
@ -17,6 +17,7 @@ from wcs.roles import Role
|
|||
from wcs.formdef import FormDef
|
||||
from wcs.categories import Category
|
||||
from wcs.data_sources import NamedDataSource
|
||||
from wcs.workflows import Workflow
|
||||
from wcs import fields
|
||||
from wcs.api import sign_url
|
||||
|
||||
|
@ -410,6 +411,8 @@ def test_formdata(pub, local_user):
|
|||
Role.wipe()
|
||||
role = Role(name='test')
|
||||
role.store()
|
||||
another_role = Role(name='another')
|
||||
another_role.store()
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test'
|
||||
|
@ -421,7 +424,13 @@ def test_formdata(pub, local_user):
|
|||
fields.ItemField(id='4', label='foobar5', varname='item',
|
||||
data_source={'type': 'foobar'}),
|
||||
]
|
||||
formdef.workflow_roles = {'_receiver': role.id}
|
||||
workflow = Workflow.get_default_workflow()
|
||||
workflow.roles['_foobar'] = 'Foobar'
|
||||
workflow.id = '2'
|
||||
workflow.store()
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.workflow_roles = {'_receiver': role.id,
|
||||
'_foobar': another_role.id}
|
||||
formdef.store()
|
||||
item_field = formdef.fields[4]
|
||||
|
||||
|
@ -442,6 +451,8 @@ def test_formdata(pub, local_user):
|
|||
formdata.data, item_field.id)
|
||||
formdata.user_id = local_user.id
|
||||
formdata.just_created()
|
||||
formdata.status = 'wf-new'
|
||||
formdata.evolution[-1].status = 'wf-new'
|
||||
formdata.store()
|
||||
|
||||
resp = get_app(pub).get(
|
||||
|
@ -469,6 +480,12 @@ def test_formdata(pub, local_user):
|
|||
assert resp.json['fields']['item'] == 'foo'
|
||||
assert resp.json['fields']['item_raw'] == '1'
|
||||
assert resp.json['fields']['item_structured'] == {'id': '1', 'text': 'foo', 'more': 'XXX'}
|
||||
assert resp.json['workflow']['status']['name'] == 'New'
|
||||
|
||||
assert [x.get('id') for x in resp.json['roles']['_receiver']] == [str(role.id)]
|
||||
assert [x.get('id') for x in resp.json['roles']['_foobar']] == [str(another_role.id)]
|
||||
assert [x.get('id') for x in resp.json['roles']['concerned']] == [str(role.id), str(another_role.id)]
|
||||
assert [x.get('id') for x in resp.json['roles']['actions']] == [str(role.id)]
|
||||
|
||||
def test_user_forms(pub, local_user):
|
||||
FormDef.wipe()
|
||||
|
@ -478,6 +495,7 @@ def test_user_forms(pub, local_user):
|
|||
fields.StringField(id='0', label='foobar', varname='foobar'),
|
||||
fields.StringField(id='1', label='foobar2'),]
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
resp = get_app(pub).get(sign_uri('/api/user/forms', user=local_user))
|
||||
assert len(resp.json) == 0
|
||||
|
|
|
@ -601,6 +601,28 @@ class FormData(StorableObject):
|
|||
if self.workflow_data:
|
||||
data['workflow']['data'] = self.workflow_data
|
||||
|
||||
# add a roles dictionary, with workflow functions and two special
|
||||
# entries for concerned/actions roles.
|
||||
data['roles'] = {}
|
||||
workflow_roles = {}
|
||||
if self.formdef.workflow_roles:
|
||||
workflow_roles.update(self.formdef.workflow_roles)
|
||||
if self.workflow_roles:
|
||||
workflow_roles.update(self.workflow_roles)
|
||||
for workflow_role in workflow_roles:
|
||||
data['roles'][workflow_role] = workflow_roles.get(workflow_role)
|
||||
data['roles']['concerned'] = self.get_concerned_roles()
|
||||
data['roles']['actions'] = self.get_actions_roles()
|
||||
|
||||
for role_key in data['roles']:
|
||||
# exclude special _submitter value
|
||||
role_list = [x for x in data['roles'][role_key] if x != '_submitter']
|
||||
# get role objects
|
||||
role_list = [Role.get(x, ignore_errors=True) for x in role_list]
|
||||
# export as json dicts
|
||||
role_list = [x.get_json_export_dict() for x in role_list if x is not None]
|
||||
data['roles'][role_key] = role_list
|
||||
|
||||
return data
|
||||
|
||||
def export_to_json(self, include_files=True):
|
||||
|
|
Loading…
Reference in New Issue