Projet

Général

Profil

0001-api-add-parameter-to-include-disabled-formdefs-43630.patch

Nicolas Roche, 14 août 2020 14:39

Télécharger (4,2 ko)

Voir les différences:

Subject: [PATCH] api: add parameter to include disabled formdefs (#43630)

 help/fr/api-schema.page |  5 +++++
 tests/test_api.py       | 12 ++++++++++++
 wcs/api.py              | 11 +++++++----
 3 files changed, 24 insertions(+), 4 deletions(-)
help/fr/api-schema.page
76 76
</p>
77 77

  
78 78
<p>
79 79
Il est également possible d'obtenir un nombre permettant de trier les résultats
80 80
par « popularité » en ajoutant un paramètre <code>include-count=on</code>. Les
81 81
différentes entrées disposeront alors d'une clé <code>count</code>.
82 82
</p>
83 83

  
84
<p>
85
La liste retournée inclura les formulaires désactivés en ajoutant le paramètre
86
<code>include-disabled=on</code>.
87
</p>
88

  
84 89
</section>
85 90

  
86 91

  
87 92
<section id="categories">
88 93
   <title>Catégories</title>
89 94

  
90 95
<p>
91 96
La liste des catégories est disponible à l'URL <code>/api/categories/</code>.
tests/test_api.py
1077 1077

  
1078 1078
    formdef2 = FormDef()
1079 1079
    formdef2.name = 'other test'
1080 1080
    formdef2.category_id = None
1081 1081
    formdef2.fields = []
1082 1082
    formdef2.store()
1083 1083
    formdef2.data_class().wipe()
1084 1084

  
1085
    formdef2 = FormDef()
1086
    formdef2.name = 'test disabled'
1087
    formdef2.category_id = category.id
1088
    formdef2.fields = []
1089
    formdef2.disabled = True
1090
    formdef2.store()
1091
    formdef2.data_class().wipe()
1092

  
1085 1093
    resp = get_app(pub).get('/api/categories/category/formdefs/')
1086 1094
    resp2 = get_app(pub).get('/category/json')
1087 1095
    assert resp.json == resp2.json
1088 1096
    assert resp.json['err'] == 0
1089 1097
    assert len(resp.json['data']) == 2
1090 1098
    assert resp.json['data'][0]['title'] == 'test'
1091 1099
    assert resp.json['data'][0]['url'] == 'http://example.net/test/'
1092 1100
    assert resp.json['data'][0]['redirection'] == False
......
1094 1102
    assert resp.json['data'][0]['category_slug'] == 'category'
1095 1103
    assert 'count' not in resp.json['data'][0]
1096 1104

  
1097 1105
    resp = get_app(pub).get('/api/categories/category/formdefs/?include-count=on')
1098 1106
    assert resp.json['data'][0]['title'] == 'test'
1099 1107
    assert resp.json['data'][0]['url'] == 'http://example.net/test/'
1100 1108
    assert resp.json['data'][0]['count'] == 0
1101 1109

  
1110
    resp = get_app(pub).get('/api/categories/category/formdefs/?include-disabled=on')
1111
    assert len(resp.json['data']) == 3
1112
    assert resp.json['data'][2]['title'] == 'test disabled'
1113

  
1102 1114
    get_app(pub).get('/api/categories/XXX/formdefs/', status=404)
1103 1115

  
1104 1116
    resp = get_app(pub).get('/api/categories/category/formdefs/?backoffice-submission=on')
1105 1117
    assert resp.json['err'] == 0
1106 1118
    assert len(resp.json['data']) == 0
1107 1119

  
1108 1120
    Role.wipe()
1109 1121
    role = Role(name='test')
wcs/api.py
456 456
        list_forms = []
457 457

  
458 458
        if not user and backoffice_submission:
459 459
            return list_forms
460 460

  
461 461
        if formdefs is None:
462 462
            formdefs = FormDef.select(order_by='name', ignore_errors=True, lightweight=True)
463 463

  
464
        if backoffice_submission:
465
            formdefs = [x for x in formdefs if not x.is_disabled()]
466
        else:
467
            formdefs = [x for x in formdefs if not x.is_disabled() or x.disabled_redirection]
464
        include_disabled = get_query_flag('include-disabled')
465

  
466
        if not include_disabled:
467
            if backoffice_submission:
468
                formdefs = [x for x in formdefs if not x.is_disabled()]
469
            else:
470
                formdefs = [x for x in formdefs if not x.is_disabled() or x.disabled_redirection]
468 471

  
469 472
        if self.category:
470 473
            formdefs = [x for x in formdefs if str(x.category_id) == str(self.category.id)]
471 474

  
472 475
        charset = get_publisher().site_charset
473 476

  
474 477
        include_count = get_query_flag('include-count')
475 478

  
476
-