api: add parameter to include disabled formdefs (#43630)
This commit is contained in:
parent
48389550d7
commit
87f8beb331
|
@ -81,6 +81,11 @@ par « popularité » en ajoutant un paramètre <code>include-count=on</code>.
|
|||
différentes entrées disposeront alors d'une clé <code>count</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
La liste retournée inclura les formulaires désactivés en ajoutant le paramètre
|
||||
<code>include-disabled=on</code>.
|
||||
</p>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
|
|
@ -1083,6 +1083,14 @@ def test_categories_formdefs(pub, local_user):
|
|||
formdef2.store()
|
||||
formdef2.data_class().wipe()
|
||||
|
||||
formdef2 = FormDef()
|
||||
formdef2.name = 'test disabled'
|
||||
formdef2.category_id = category.id
|
||||
formdef2.fields = []
|
||||
formdef2.disabled = True
|
||||
formdef2.store()
|
||||
formdef2.data_class().wipe()
|
||||
|
||||
resp = get_app(pub).get('/api/categories/category/formdefs/')
|
||||
resp2 = get_app(pub).get('/category/json')
|
||||
assert resp.json == resp2.json
|
||||
|
@ -1100,6 +1108,10 @@ def test_categories_formdefs(pub, local_user):
|
|||
assert resp.json['data'][0]['url'] == 'http://example.net/test/'
|
||||
assert resp.json['data'][0]['count'] == 0
|
||||
|
||||
resp = get_app(pub).get('/api/categories/category/formdefs/?include-disabled=on')
|
||||
assert len(resp.json['data']) == 3
|
||||
assert resp.json['data'][2]['title'] == 'test disabled'
|
||||
|
||||
get_app(pub).get('/api/categories/XXX/formdefs/', status=404)
|
||||
|
||||
resp = get_app(pub).get('/api/categories/category/formdefs/?backoffice-submission=on')
|
||||
|
|
11
wcs/api.py
11
wcs/api.py
|
@ -461,10 +461,13 @@ class ApiFormdefsDirectory(Directory):
|
|||
if formdefs is None:
|
||||
formdefs = FormDef.select(order_by='name', ignore_errors=True, lightweight=True)
|
||||
|
||||
if backoffice_submission:
|
||||
formdefs = [x for x in formdefs if not x.is_disabled()]
|
||||
else:
|
||||
formdefs = [x for x in formdefs if not x.is_disabled() or x.disabled_redirection]
|
||||
include_disabled = get_query_flag('include-disabled')
|
||||
|
||||
if not include_disabled:
|
||||
if backoffice_submission:
|
||||
formdefs = [x for x in formdefs if not x.is_disabled()]
|
||||
else:
|
||||
formdefs = [x for x in formdefs if not x.is_disabled() or x.disabled_redirection]
|
||||
|
||||
if self.category:
|
||||
formdefs = [x for x in formdefs if str(x.category_id) == str(self.category.id)]
|
||||
|
|
Loading…
Reference in New Issue