Projet

Général

Profil

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

Frédéric Péters, 27 avril 2020 20:45

Télécharger (1,9 ko)

Voir les différences:

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

 tests/test_api.py |  5 +++++
 wcs/api.py        | 17 +++++++++++++++++
 2 files changed, 22 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
                'title': x.name,
325
                'slug': x.url_name,
326
                'url': x.get_url(),
327
                'description': x.description or '',
328
                'keywords': x.keywords_list,
329
            } for x in carddefs]
330
        return json.dumps({'data': data, 'err': 0})
331

  
315 332
    def _q_lookup(self, component):
316 333
        return ApiCardPage(component)
317 334

  
318
-