0001-manager-do-without-disabled-add-user-button-on-users.patch
src/authentic2/manager/forms.py | ||
---|---|---|
420 | 420 |
# - show all if show_all_ou is True and user has ou_permission over all OUs or more than |
421 | 421 |
# one, |
422 | 422 |
# - show searchable OUs |
423 |
# - show none if user has ou_permission over all OUs |
|
423 |
# - show none if user has ou_permission over all OUs and show_none_ou is True
|
|
424 | 424 |
# - when no choice is made, |
425 | 425 |
# - show all ou is show_all_ou is True (including None if user has ou_permission over all |
426 | 426 |
# OUs) |
... | ... | |
431 | 431 |
all_ou_label = kwargs.pop('all_ou_label', pgettext('organizational unit', 'All')) |
432 | 432 |
self.queryset = kwargs.pop('queryset', None) |
433 | 433 |
self.show_all_ou = kwargs.pop('show_all_ou', True) |
434 |
self.show_none_ou = kwargs.pop('show_none_ou', True) |
|
434 | 435 |
request = kwargs['request'] |
435 | 436 |
self.ou_count = utils.get_ou_count() |
436 | 437 | |
... | ... | |
462 | 463 |
choices.append(('all', all_ou_label)) |
463 | 464 |
for ou in self.ou_qs: |
464 | 465 |
choices.append((str(ou.pk), six.text_type(ou))) |
465 |
if self.search_all_ous: |
|
466 |
if self.show_none_ou and self.search_all_ous:
|
|
466 | 467 |
choices.append(('none', pgettext('organizational unit', 'None'))) |
467 | 468 | |
468 | 469 |
# if user does not have ou_permission over all OUs, select user OU as default selected |
src/authentic2/manager/templates/authentic2/manager/users.html | ||
---|---|---|
7 | 7 |
{{ block.super }} |
8 | 8 |
<span class="actions"> |
9 | 9 |
<a class="extra-actions-menu-opener"></a> |
10 |
{% if add_ou %} |
|
11 | 10 |
<a |
12 |
href="{% url "a2-manager-user-add" ou_pk=add_ou.pk %}" |
|
11 |
{% if add_ou %}href="{% url "a2-manager-user-add" ou_pk=add_ou.pk %}"{% else %} |
|
12 |
href="{% url "a2-manager-user-add-choose-ou" %}" rel="popup"{% endif %} |
|
13 | 13 |
id="add-user-btn"> |
14 | 14 |
{% trans "Add user" %} |
15 | 15 |
</a> |
16 |
{% else %} |
|
17 |
<a |
|
18 |
href="#" |
|
19 |
class="disabled" |
|
20 |
id="add-user-btn"> |
|
21 |
{% trans "Add user" %} |
|
22 |
</a> |
|
23 |
{% endif %} |
|
24 | 16 |
{% if extra_actions %} |
25 | 17 |
<ul class="extra-actions-menu"> |
26 | 18 |
{% for extra_action in extra_actions %} |
src/authentic2/manager/urls.py | ||
---|---|---|
40 | 40 |
user_views.users_export, name='a2-manager-users-export'), |
41 | 41 |
url(r'^users/add/$', user_views.user_add_default_ou, |
42 | 42 |
name='a2-manager-user-add-default-ou'), |
43 |
url(r'^users/add/choose-ou/$', user_views.user_add_choose_ou, |
|
44 |
name='a2-manager-user-add-choose-ou'), |
|
43 | 45 |
url(r'^users/import/$', |
44 | 46 |
user_views.user_imports, name='a2-manager-users-imports'), |
45 | 47 |
url(r'^users/import/(?P<uuid>[a-z0-9]+)/download/(?P<filename>.*)$', |
src/authentic2/manager/user_views.py | ||
---|---|---|
55 | 55 |
from .forms import (UserSearchForm, UserAddForm, UserEditForm, |
56 | 56 |
UserChangePasswordForm, ChooseUserRoleForm, |
57 | 57 |
UserRoleSearchForm, UserChangeEmailForm, UserNewImportForm, |
58 |
UserEditImportForm, ChooseUserAuthorizationsForm) |
|
58 |
UserEditImportForm, ChooseUserAuthorizationsForm, OUSearchForm)
|
|
59 | 59 |
from .resources import UserResource |
60 | 60 |
from .utils import get_ou_count, has_show_username |
61 | 61 |
from .journal_views import BaseJournalView |
... | ... | |
240 | 240 |
return redirect(request, 'a2-manager-user-add', kwargs={'ou_pk': ou.id}, keep_params=True) |
241 | 241 | |
242 | 242 | |
243 |
class UserAddChooseOU(TitleMixin, FormNeedsRequest, FormView): |
|
244 |
template_name = 'authentic2/manager/form.html' |
|
245 |
title = _('Choose organizational unit in which to create user') |
|
246 |
form_class = OUSearchForm |
|
247 | ||
248 |
def get_success_url(self): |
|
249 |
return reverse('a2-manager-user-add', kwargs={'ou_pk': self.ou_pk}) |
|
250 | ||
251 |
def form_valid(self, form): |
|
252 |
self.ou_pk = form.cleaned_data['ou'].pk |
|
253 |
return super().form_valid(form) |
|
254 | ||
255 |
def get_form_kwargs(self): |
|
256 |
kwargs = super().get_form_kwargs() |
|
257 |
kwargs['show_all_ou'] = False |
|
258 |
kwargs['show_none_ou'] = False |
|
259 |
return kwargs |
|
260 | ||
261 |
def get_context_data(self, **kwargs): |
|
262 |
context = super().get_context_data(**kwargs) |
|
263 |
context['action'] = _('Validate') |
|
264 |
return context |
|
265 | ||
266 | ||
267 |
user_add_choose_ou = UserAddChooseOU.as_view() |
|
268 | ||
269 | ||
243 | 270 |
class UserDetailView(OtherActionsMixin, BaseDetailView): |
244 | 271 |
model = get_user_model() |
245 | 272 |
fields = ['username', 'ou', 'first_name', 'last_name', 'email'] |
tests/test_user_manager.py | ||
---|---|---|
204 | 204 |
assert user.has_usable_password() |
205 | 205 | |
206 | 206 | |
207 |
def test_create_user_choose_ou(app, superuser, ou1, ou2): |
|
208 |
response = login(app, superuser, '/manage/users/') |
|
209 |
response = response.click('Add user') |
|
210 |
assert 'Choose organizational unit' in response.text |
|
211 | ||
212 |
response = response.form.submit() |
|
213 |
assert str(get_default_ou().pk) in response.url |
|
214 | ||
215 |
response = app.get('/manage/users/') |
|
216 |
response = response.click('Add user') |
|
217 |
response.form['ou'] = ou1.pk |
|
218 |
response = response.form.submit() |
|
219 |
assert str(ou1.pk) in response.url |
|
220 | ||
221 | ||
207 | 222 |
def test_manager_user_change_email(app, superuser_or_admin, simple_user, mailoutbox): |
208 | 223 |
ou = get_default_ou() |
209 | 224 |
ou.validate_emails = True |
210 |
- |