manager: provide a simpler ou creation form (#66795)
This commit is contained in:
parent
4939516808
commit
63fa2d3f16
|
@ -636,12 +636,16 @@ class OUEditForm(SlugMixin, CssClass, forms.ModelForm):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['name'].label = _('label').title()
|
||||
self.fields['colour'].widget = forms.TextInput(attrs={'type': 'color'})
|
||||
if 'colour' in self.fields:
|
||||
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):
|
||||
if (
|
||||
getattr(a2_app_settings, 'A2_%s_IS_UNIQUE' % option.upper(), False)
|
||||
and '%s_is_unique' % option in self.fields
|
||||
):
|
||||
self.fields['%s_is_unique' % option].disabled = True
|
||||
self.fields['%s_is_unique' % option].help_text = help_text
|
||||
|
||||
|
|
|
@ -47,10 +47,7 @@ class OrganizationalUnitAddView(views.BaseAddView):
|
|||
permissions = ['a2_rbac.add_organizationalunit']
|
||||
form_class = forms.OUEditForm
|
||||
title = _('Add organizational unit')
|
||||
exclude_fields = ('slug',)
|
||||
|
||||
def get_fields(self):
|
||||
return [x for x in self.form_class.base_fields.keys() if x not in self.exclude_fields]
|
||||
fields = ('name',)
|
||||
|
||||
def get_success_url(self):
|
||||
return '..'
|
||||
|
|
|
@ -94,7 +94,25 @@ def test_manager_create_ou(superuser_or_admin, app):
|
|||
ou_add = login(app, superuser_or_admin, path=reverse('a2-manager-ou-add'))
|
||||
form = ou_add.form
|
||||
assert 'name' in form.fields
|
||||
assert 'slug' not in form.fields
|
||||
excluded_fields = (
|
||||
'slug',
|
||||
'default',
|
||||
'username_is_unique',
|
||||
'email_is_unique',
|
||||
'validate_emails',
|
||||
'show_username',
|
||||
'check_required_on_login_attributes',
|
||||
'user_can_reset_password',
|
||||
'user_add_password_policy',
|
||||
'clean_unused_accounts_alert',
|
||||
'clean_unused_accounts_deletion',
|
||||
'home_url',
|
||||
'logo',
|
||||
'colour',
|
||||
)
|
||||
for field in excluded_fields:
|
||||
assert field not in form.fields
|
||||
|
||||
form.set('name', 'New OU')
|
||||
response = form.submit().follow()
|
||||
assert 'New OU' in response
|
||||
|
@ -899,7 +917,6 @@ def test_manager_ou(app, superuser_or_admin, ou1):
|
|||
# add a new ou
|
||||
add_ou_page = ou_homepage.click('Add')
|
||||
add_ou_page.form.set('name', 'ou2')
|
||||
add_ou_page.form.set('default', True)
|
||||
ou_homepage = add_ou_page.form.submit().follow()
|
||||
ou2 = OU.objects.get(name='ou2')
|
||||
assert {text_content(e) for e in ou_homepage.pyquery('td.name')} == {
|
||||
|
@ -907,6 +924,14 @@ def test_manager_ou(app, superuser_or_admin, ou1):
|
|||
'Default organizational unit',
|
||||
'ou2',
|
||||
}
|
||||
assert len(ou_homepage.pyquery('tr[data-pk="%s"] td.default span.true' % ou2.pk)) == 0
|
||||
assert len(ou_homepage.pyquery('tr td a[href="%s"]' % ou2.get_absolute_url())) == 1
|
||||
|
||||
ou2_edit_page = app.get(reverse('a2-manager-ou-edit', kwargs={'pk': ou2.pk}))
|
||||
ou2_edit_page.form.set('default', True)
|
||||
|
||||
ou2_edit_page.form.submit().follow()
|
||||
ou_homepage = manager_home_page.click(href='organizational-units')
|
||||
assert len(ou_homepage.pyquery('tr[data-pk="%s"] td.default span.true' % ou2.pk)) == 1
|
||||
assert len(ou_homepage.pyquery('tr td a[href="%s"]' % ou2.get_absolute_url())) == 1
|
||||
|
||||
|
|
|
@ -85,10 +85,12 @@ def test_manager_ou_import(app, admin, ou1, role_ou1, ou2, role_ou2):
|
|||
|
||||
|
||||
def test_ou_edit_form_local_options_overriden(app, admin, ou1, settings):
|
||||
login(app, admin, 'a2-manager-ou-add')
|
||||
|
||||
settings.A2_EMAIL_IS_UNIQUE = False
|
||||
settings.A2_USERNAME_IS_UNIQUE = True
|
||||
|
||||
response = login(app, admin, 'a2-manager-ou-add')
|
||||
response = app.get('/manage/organizational-units/%s/edit/' % ou1.pk)
|
||||
|
||||
assert 'disabled' not in response.pyquery("input#id_email_is_unique")[0].attrib
|
||||
assert response.pyquery("input#id_username_is_unique")[0].attrib['disabled']
|
||||
|
|
Loading…
Reference in New Issue