Projet

Général

Profil

0001-api-add-endpoint-to-get-list-of-cards-41844.patch

Frédéric Péters, 02 mai 2020 11:15

Télécharger (1,97 ko)

Voir les différences:

Subject: [PATCH] api: add endpoint to get list of cards (#41844)

 tests/test_api.py |  5 +++++
 wcs/api.py        | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)
tests/test_api.py
3012 3012
    formdata.just_created()
3013 3013
    formdata.store()
3014 3014

  
3015
    resp = get_app(pub).get('/api/cards/@list', status=403)
3016
    resp = get_app(pub).get(sign_uri('/api/cards/@list'))
3017
    assert len(resp.json['data']) == 1
3018
    assert resp.json['data'][0]['slug'] == 'test'
3019

  
3015 3020
    resp = get_app(pub).get(sign_uri('/api/cards/test/list'), status=403)
3016 3021

  
3017 3022
    resp = get_app(pub).get(sign_uri(
wcs/api.py
312 312

  
313 313

  
314 314
class ApiCardsDirectory(Directory):
315
    _q_exports = [('@list', 'list')]
316

  
317
    def list(self):
318
        get_response().set_content_type('application/json')
319
        if not (is_url_signed() or (get_request().user and get_request().user.can_go_in_admin())):
320
            raise AccessForbiddenError('unsigned request or user is not admin')
321
        carddefs = CardDef.select(order_by='name', ignore_errors=True, lightweight=True)
322
        data = [
323
            {
324
                'id': x.url_name,
325
                'text': x.name,
326
                'title': x.name,
327
                'slug': x.url_name,
328
                'url': x.get_url(),
329
                'description': x.description or '',
330
                'keywords': x.keywords_list,
331
            } for x in carddefs]
332
        return json.dumps({'data': data, 'err': 0})
333

  
315 334
    def _q_lookup(self, component):
316 335
        return ApiCardPage(component)
317 336

  
318
-