0001-manager-add-settings-for-password-section-options-on.patch
src/authentic2/app_settings.py | ||
---|---|---|
207 | 207 |
A2_ACCOUNTS_URL=Setting(default=None, definition='IdP has no account page, redirect to this one.'), |
208 | 208 |
A2_CACHE_ENABLED=Setting(default=True, definition='Disable all cache decorators for testing purpose.'), |
209 | 209 |
A2_ACCEPT_EMAIL_AUTHENTICATION=Setting(default=True, definition='Enable authentication by email'), |
210 |
A2_USER_ADD_GENERATE_PASSWORD=Setting(default=True, definition='Generate a password for newly created users.'), |
|
211 |
A2_USER_ADD_RESET_PASSWORD_AT_NEXT_LOGIN=Setting(default=False, definition='Choose whether the user needs to change their password on next login.'), |
|
212 |
A2_USER_ADD_SEND_MAIL=Setting(default=False, definition='Send a mail for newly created users that contain account information.'), |
|
213 |
A2_USER_ADD_SEND_PASSWORD_RESET=Setting(default=False, definition='Send a mail for newly created users to define their password.'), |
|
210 | 214 | |
211 | 215 |
) |
212 | 216 |
src/authentic2/manager/user_views.py | ||
---|---|---|
35 | 35 |
from .forms import (UserSearchForm, UserAddForm, UserEditForm, |
36 | 36 |
UserChangePasswordForm, ChooseUserRoleForm, UserRoleSearchForm, UserChangeEmailForm) |
37 | 37 |
from .resources import UserResource |
38 |
from .utils import get_ou_count |
|
38 |
from .utils import get_ou_count, get_user_add_policies
|
|
39 | 39 |
from . import app_settings |
40 | 40 | |
41 | 41 | |
... | ... | |
150 | 150 |
instance=form.instance, form=form) |
151 | 151 |
return response |
152 | 152 | |
153 |
def get_initial(self, *args, **kwargs): |
|
154 |
initial = super(UserAddView, self).get_initial(*args, **kwargs) |
|
155 |
initial.update(get_user_add_policies()) |
|
156 |
return initial |
|
157 | ||
153 | 158 |
user_add = UserAddView.as_view() |
154 | 159 | |
155 | 160 |
src/authentic2/manager/utils.py | ||
---|---|---|
3 | 3 |
from django_rbac.utils import get_ou_model |
4 | 4 | |
5 | 5 |
from authentic2.decorators import GlobalCache |
6 |
from authentic2 import app_settings |
|
6 | 7 | |
7 | 8 | |
8 | 9 |
def label_from_user(user): |
... | ... | |
26 | 27 |
@GlobalCache(timeout=10) |
27 | 28 |
def get_ou_count(): |
28 | 29 |
return get_ou_model().objects.count() |
30 | ||
31 | ||
32 |
def get_user_add_policies(): |
|
33 |
options = ( |
|
34 |
'generate_password', |
|
35 |
'reset_password_at_next_login', |
|
36 |
'send_mail', |
|
37 |
'send_password_reset', |
|
38 |
) |
|
39 | ||
40 |
return {key: getattr(app_settings, 'A2_USER_ADD_{}'.format(key.upper())) |
|
41 |
for key in options} |
tests/test_manager.py | ||
---|---|---|
836 | 836 |
response = app.get(url, params={'field_id': field_id, 'term': 'Admin édou'}) |
837 | 837 |
assert len(response.json['results']) == 1 |
838 | 838 |
assert response.json['results'][0]['text'] == u'La Bédoule - Administrateur' |
839 | ||
840 | ||
841 |
def test_user_add_settings(settings, admin, app, db): |
|
842 |
possible_configs = ( |
|
843 |
((False, False, False, False), (None, None, None, None)), |
|
844 |
((False, True, False, False), (None, 'on', None, None)), |
|
845 |
((False, False, True, False), (None, None, 'on', None)), |
|
846 |
((True, False, True, False), ('on', None, 'on', None)), |
|
847 |
((False, True, True, False), (None, 'on', 'on', None)), |
|
848 |
((True, True, True, False), ('on', 'on', 'on', None)), |
|
849 |
((False, False, False, True), (None, None, None, 'on')), |
|
850 |
((False, True, False, True), (None, 'on', None, 'on')), |
|
851 |
((False, False, True, True), (None, None, 'on', 'on')), |
|
852 |
((True, False, True, True), ('on', None, 'on', 'on')), |
|
853 |
((False, True, True, True), (None, 'on', 'on', 'on')), |
|
854 |
((True, True, True, True), ('on', 'on', 'on', 'on')) |
|
855 |
) |
|
856 | ||
857 |
for config in possible_configs: |
|
858 |
settings.A2_USER_ADD_GENERATE_PASSWORD = config[0][0] |
|
859 |
settings.A2_USER_ADD_RESET_PASSWORD_AT_NEXT_LOGIN = config[0][1] |
|
860 |
settings.A2_USER_ADD_SEND_MAIL = config[0][2] |
|
861 |
settings.A2_USER_ADD_SEND_PASSWORD_RESET = config[0][3] |
|
862 | ||
863 |
user_add = login(app, admin, '/manage/users/add/').follow() |
|
864 | ||
865 |
assert user_add.form.get('generate_password').value == config[1][0] |
|
866 |
assert user_add.form.get('reset_password_at_next_login').value == config[1][1] |
|
867 |
assert user_add.form.get('send_mail').value == config[1][2] |
|
868 |
assert user_add.form.get('send_password_reset').value == config[1][3] |
|
869 | ||
870 |
app.get('/logout/').form.submit() |
|
839 |
- |