manager: disable globally-overriden options on OU edition page (#72384)
This commit is contained in:
parent
043c7abf6d
commit
86fc21ed42
|
@ -31,6 +31,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from django.utils.translation import pgettext
|
||||
from django_select2.forms import HeavySelect2Widget
|
||||
|
||||
from authentic2 import app_settings as a2_app_settings
|
||||
from authentic2.a2_rbac.models import Operation, OrganizationalUnit, Permission, Role
|
||||
from authentic2.a2_rbac.utils import generate_slug, get_default_ou
|
||||
from authentic2.custom_user.backends import DjangoRBACBackend
|
||||
|
@ -637,6 +638,13 @@ class OUEditForm(SlugMixin, CssClass, forms.ModelForm):
|
|||
self.fields['name'].label = _('label').title()
|
||||
self.fields['colour'].widget = forms.TextInput(attrs={'type': 'color'})
|
||||
|
||||
# disable overriden local configuration
|
||||
help_text = _('This option is disabled because global unicity is set.')
|
||||
for option in ('email', 'username'):
|
||||
if getattr(a2_app_settings, 'A2_%s_IS_UNIQUE' % option.upper(), False):
|
||||
self.fields['%s_is_unique' % option].disabled = True
|
||||
self.fields['%s_is_unique' % option].help_text = help_text
|
||||
|
||||
class Meta:
|
||||
model = OrganizationalUnit
|
||||
fields = (
|
||||
|
|
|
@ -82,3 +82,21 @@ def test_manager_ou_import(app, admin, ou1, role_ou1, ou2, role_ou2):
|
|||
resp = resp.form.submit().follow()
|
||||
|
||||
assert not Role.objects.filter(slug="should_not_exist").exists()
|
||||
|
||||
|
||||
def test_ou_edit_form_local_options_overriden(app, admin, ou1, settings):
|
||||
settings.A2_EMAIL_IS_UNIQUE = False
|
||||
settings.A2_USERNAME_IS_UNIQUE = True
|
||||
|
||||
response = login(app, admin, 'a2-manager-ou-add')
|
||||
|
||||
assert 'disabled' not in response.pyquery("input#id_email_is_unique")[0].attrib
|
||||
assert response.pyquery("input#id_username_is_unique")[0].attrib['disabled']
|
||||
|
||||
settings.A2_EMAIL_IS_UNIQUE = True
|
||||
settings.A2_USERNAME_IS_UNIQUE = False
|
||||
|
||||
response = app.get('/manage/organizational-units/%s/edit/' % ou1.pk)
|
||||
|
||||
assert response.pyquery("input#id_email_is_unique")[0].attrib['disabled']
|
||||
assert 'disabled' not in response.pyquery("input#id_username_is_unique")[0].attrib
|
||||
|
|
Loading…
Reference in New Issue