Projet

Général

Profil

0001-backoffice-hide-API-access-69564.patch

Emmanuel Cazenave, 27 septembre 2022 18:10

Télécharger (3,72 ko)

Voir les différences:

Subject: [PATCH] backoffice: hide API access (#69564)

 tests/admin_pages/test_api_access.py          | 39 -------------------
 wcs/admin/settings.py                         |  3 ++
 .../wcs/backoffice/api_accesses.html          |  4 --
 3 files changed, 3 insertions(+), 43 deletions(-)
tests/admin_pages/test_api_access.py
52 52
    return obj
53 53

  
54 54

  
55
def test_api_access_new(pub):
56
    create_superuser(pub)
57
    ApiAccess.wipe()
58
    app = login(get_app(pub))
59

  
60
    # go to the page and cancel
61
    resp = app.get('/backoffice/settings/api-access/')
62
    resp = resp.click('New API access')
63
    resp = resp.forms[0].submit('cancel')
64
    assert resp.location == 'http://example.net/backoffice/settings/api-access/'
65

  
66
    # go to the page and add an API access
67
    resp = app.get('/backoffice/settings/api-access/')
68
    resp = resp.click('New API access')
69
    resp.form['name'] = 'a new API access'
70
    resp.form['description'] = 'description'
71
    resp.form['access_identifier'] = 'new_access'
72
    assert len(resp.form['access_key'].value) == 36
73
    resp = resp.form.submit('submit')
74
    assert resp.location == 'http://example.net/backoffice/settings/api-access/'
75
    resp = resp.follow()
76
    assert 'a new API access' in resp.text
77
    resp = resp.click('a new API access')
78
    assert 'API access - a new API access' in resp.text
79

  
80
    # check name unicity
81
    resp = app.get('/backoffice/settings/api-access/new')
82
    resp.form['name'] = 'a new API access'
83
    resp.form['access_identifier'] = 'changed'
84
    resp = resp.form.submit('submit')
85
    assert resp.html.find('div', {'class': 'error'}).text == 'This name is already used.'
86

  
87
    # check access_identifier unicity
88
    resp.form['name'] = 'new one'
89
    resp.form['access_identifier'] = 'new_access'
90
    resp = resp.form.submit('submit')
91
    assert resp.html.find('div', {'class': 'error'}).text == 'This value is already used.'
92

  
93

  
94 55
def test_api_access_view(pub, api_access):
95 56
    create_superuser(pub)
96 57

  
wcs/admin/settings.py
33 33
from quixote.directory import Directory
34 34
from quixote.html import TemplateIO, htmltext
35 35

  
36
from wcs.api_access import ApiAccess
36 37
from wcs.blocks import BlockDef
37 38
from wcs.carddef import CardDef
38 39
from wcs.data_sources import NamedDataSource
......
535 536

  
536 537
        disabled_screens_option = get_publisher().get_site_option('settings-disabled-screens') or ''
537 538
        disabled_screens = [x.strip() for x in disabled_screens_option.split(',')]
539
        if ApiAccess.count() == 0:
540
            disabled_screens.append('api-access')
538 541

  
539 542
        def enabled(screen):
540 543
            return screen not in disabled_screens
wcs/templates/wcs/backoffice/api_accesses.html
3 3

  
4 4
{% block appbar-title %}{% trans "API access" %}{% endblock %}
5 5

  
6
{% block appbar-actions %}
7
<a rel="popup" href="new">{% trans "New API access" %}</a>
8
{% endblock %}
9

  
10 6
{% block content %}
11 7
{% if api_accesses %}
12 8
<ul class="objects-list single-links">
13
-