0001-authenticators-forbid-disabling-all-authenticators-6.patch
src/authentic2/apps/authenticators/templates/authentic2/authenticators/authenticator_detail.html | ||
---|---|---|
6 | 6 |
<span class="actions"> |
7 | 7 |
<a class="extra-actions-menu-opener"></a> |
8 | 8 | |
9 |
{% if can_be_toggled %} |
|
9 | 10 |
<a href="{% url 'a2-manager-authenticator-toggle' pk=object.pk %}">{{ object.enabled|yesno:_("Disable,Enable") }}</a> |
11 |
{% endif %} |
|
10 | 12 |
<a href="{% url 'a2-manager-authenticator-edit' pk=object.pk %}">{% trans "Edit" %}</a> |
11 | 13 |
<ul class="extra-actions-menu"> |
12 | 14 |
{% if not object.internal %} |
src/authentic2/apps/authenticators/views.py | ||
---|---|---|
58 | 58 |
def title(self): |
59 | 59 |
return str(self.object) |
60 | 60 | |
61 |
def get_context_data(self, **kwargs): |
|
62 |
ctx = super().get_context_data(**kwargs) |
|
63 |
ctx['can_be_toggled'] = ( |
|
64 |
not self.object.enabled or BaseAuthenticator.objects.filter(enabled=True).count() > 1 |
|
65 |
) |
|
66 |
return ctx |
|
67 | ||
61 | 68 | |
62 | 69 |
detail = AuthenticatorDetailView.as_view() |
63 | 70 |
tests/test_manager_authenticators.py | ||
---|---|---|
73 | 73 |
"Show condition: 'backoffice' in login_hint or remotre_addr == '1.2.3.4'" |
74 | 74 |
in resp.text |
75 | 75 |
) |
76 | ||
77 |
# only one authenticator, it cannot be disabled |
|
78 |
assert 'Disable' not in resp.text |
|
79 | ||
80 |
# add one more |
|
81 |
OIDCProvider.objects.create(slug='test', enabled=True) |
|
82 | ||
83 |
resp = app.get('/manage/authenticators/') |
|
84 |
resp = resp.click('Configure', index=0) |
|
85 | ||
76 | 86 |
resp = resp.click('Disable').follow() |
77 | 87 |
assert 'Authenticator has been disabled.' in resp.text |
78 | 88 | |
79 | 89 |
resp = app.get('/manage/authenticators/') |
80 | 90 |
assert 'class="section disabled"' in resp.text |
81 | 91 | |
82 |
resp = resp.click('Configure') |
|
92 |
resp = resp.click('Configure', index=1)
|
|
83 | 93 |
resp = resp.click('Enable').follow() |
84 | 94 |
assert 'Authenticator has been enabled.' in resp.text |
85 | 95 | |
86 |
- |