0001-manager-add-settings-for-password-section-options-on.patch
src/authentic2/a2_rbac/models.py | ||
---|---|---|
47 | 47 |
user_can_reset_password = models.NullBooleanField( |
48 | 48 |
verbose_name=_('Users can reset password')) |
49 | 49 | |
50 |
user_add_generate_password = models.BooleanField( |
|
51 |
blank=True, |
|
52 |
default=True, |
|
53 |
verbose_name=_('Generate password for user')) |
|
54 | ||
55 |
user_add_reset_password_at_next_login = models.BooleanField( |
|
56 |
blank=True, |
|
57 |
default=False, |
|
58 |
verbose_name=_('Reset password at next user login')) |
|
59 | ||
60 |
user_add_send_mail = models.BooleanField( |
|
61 |
blank=True, |
|
62 |
default=False, |
|
63 |
verbose_name=_('Send account creation information email to user')) |
|
64 | ||
65 |
user_add_send_password_reset = models.BooleanField( |
|
66 |
blank=True, |
|
67 |
default=False, |
|
68 |
verbose_name=_('Send password definition email to user')) |
|
69 | ||
50 | 70 |
objects = managers.OrganizationalUnitManager() |
51 | 71 | |
52 | 72 |
class Meta: |
src/authentic2/manager/user_views.py | ||
---|---|---|
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(self.get_user_add_policies()) |
|
156 |
return initial |
|
157 | ||
158 |
def get_user_add_policies(self, *args, **kwargs): |
|
159 |
options = ( |
|
160 |
'generate_password', |
|
161 |
'reset_password_at_next_login', |
|
162 |
'send_mail', |
|
163 |
'send_password_reset', |
|
164 |
) |
|
165 |
Ou = get_ou_model() |
|
166 |
ou_id = self.request.get_full_path().rsplit('/', 3)[1] |
|
167 |
ou = Ou.objects.get(id=ou_id) |
|
168 | ||
169 |
return {key: getattr(ou, 'user_add_{}'.format(key)) |
|
170 |
for key in options} |
|
171 | ||
172 | ||
153 | 173 |
user_add = UserAddView.as_view() |
154 | 174 | |
155 | 175 |
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), |
|
844 |
(False, True, False, False), |
|
845 |
(False, False, True, False), |
|
846 |
(True, False, True, False), |
|
847 |
(False, True, True, False), |
|
848 |
(True, True, True, False), |
|
849 |
(False, False, False, True), |
|
850 |
(False, True, False, True), |
|
851 |
(False, False, True, True), |
|
852 |
(True, False, True, True), |
|
853 |
(False, True, True, True), |
|
854 |
(True, True, True, True), |
|
855 |
) |
|
856 | ||
857 |
passwd_options = ('generate_password', 'reset_password_at_next_login', |
|
858 |
'send_mail', 'send_password_reset') |
|
859 | ||
860 |
for config in possible_configs: |
|
861 |
ou = get_default_ou() |
|
862 |
for option, i in zip(passwd_options, range(3)): |
|
863 |
setattr(ou, 'user_add_{}'.format(option), config[i]) |
|
864 |
ou.save() |
|
865 |
user_add = login(app, admin, '/manage/users/add/').follow() |
|
866 | ||
867 |
for option, i in zip(passwd_options, range(3)): |
|
868 |
assert user_add.form.get(option).value == {False:None, True:'on'}.get(config[i]) |
|
869 |
app.get('/logout/').form.submit() |
|
839 |
- |