api: expose backoffice_submission and submission_channel in formdata (#9515)
This commit is contained in:
parent
0632245289
commit
2f0caaaa68
|
@ -106,6 +106,10 @@ Le contenu ainsi obtenu est le suivant :
|
|||
"allows_backoffice_access": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"submission": {
|
||||
"backoffice": false,
|
||||
"channel": "Web"
|
||||
}
|
||||
}
|
||||
</code>
|
||||
|
@ -123,6 +127,12 @@ la série <code>actions</code> reprend les rôles disposant d'une capacité
|
|||
d'action sur la demande.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
L'information sur l'origine de la demande, si la saisie a eu lieu depuis le
|
||||
backoffice et quel était le canal d'origine de la demande, est disponible
|
||||
dans l'attribut <code>submission</code>.
|
||||
</p>
|
||||
|
||||
<note>
|
||||
<p>
|
||||
Il est bien sûr nécessaire de disposer des autorisations nécessaires pour
|
||||
|
|
|
@ -551,6 +551,7 @@ def test_formdata(pub, local_user):
|
|||
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 resp.json['submission']['channel'] == 'Web'
|
||||
|
||||
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)]
|
||||
|
@ -681,6 +682,10 @@ def test_api_list_formdata(pub, local_user):
|
|||
formdata.jump_status('new')
|
||||
else:
|
||||
formdata.jump_status('finished')
|
||||
if i%7 == 0:
|
||||
formdata.backoffice_submission = True
|
||||
formdata.submission_channel = 'mail'
|
||||
|
||||
formdata.store()
|
||||
|
||||
# check access is denied if the user has not the appropriate role
|
||||
|
@ -703,6 +708,11 @@ def test_api_list_formdata(pub, local_user):
|
|||
assert 'fields' in resp.json[0]
|
||||
assert 'file' not in resp.json[0]['fields'] # no file export in full lists
|
||||
|
||||
assert [x for x in resp.json if x['fields']['foobar'] == 'FOO BAR 0'][0]['submission']['backoffice'] is True
|
||||
assert [x for x in resp.json if x['fields']['foobar'] == 'FOO BAR 0'][0]['submission']['channel'] == 'Mail'
|
||||
assert [x for x in resp.json if x['fields']['foobar'] == 'FOO BAR 1'][0]['submission']['backoffice'] is False
|
||||
assert [x for x in resp.json if x['fields']['foobar'] == 'FOO BAR 1'][0]['submission']['channel'] == 'Web'
|
||||
|
||||
# check filtered results
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/list?filter-foobar3=foo', user=local_user))
|
||||
assert len(resp.json) == 8
|
||||
|
|
|
@ -672,6 +672,11 @@ class FormData(StorableObject):
|
|||
role_list = [x.get_json_export_dict() for x in role_list if x is not None]
|
||||
data['roles'][role_key] = role_list
|
||||
|
||||
data['submission'] = {
|
||||
'backoffice': self.backoffice_submission,
|
||||
'channel': self.get_submission_channel_label(),
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
def export_to_json(self, include_files=True):
|
||||
|
|
Loading…
Reference in New Issue