0001-manager-hide-the-username-column-33971.patch
src/authentic2/manager/user_views.py | ||
---|---|---|
43 | 43 |
from .forms import (UserSearchForm, UserAddForm, UserEditForm, |
44 | 44 |
UserChangePasswordForm, ChooseUserRoleForm, UserRoleSearchForm, UserChangeEmailForm) |
45 | 45 |
from .resources import UserResource |
46 |
from .utils import get_ou_count |
|
46 |
from .utils import get_ou_count, has_show_username
|
|
47 | 47 |
from . import app_settings |
48 | 48 | |
49 | 49 | |
... | ... | |
78 | 78 |
return qs |
79 | 79 | |
80 | 80 |
def get_table(self, **kwargs): |
81 |
show_username = has_show_username() |
|
82 |
if show_username and self.is_ou_specified(): |
|
83 |
show_username = self.is_ou_specified().show_username |
|
84 |
if not show_username: |
|
85 |
exclude = kwargs.setdefault('exclude', []) |
|
86 |
if 'username' not in exclude: |
|
87 |
exclude.append('username') |
|
81 | 88 |
table = super(UsersView, self).get_table(**kwargs) |
82 | 89 |
if self.search_form.not_enough_chars(): |
83 | 90 |
user_qs = self.search_form.filter_by_ou(self.get_queryset()) |
... | ... | |
86 | 93 |
'limit': self.search_form.minimum_chars, |
87 | 94 |
'user_count': user_qs.count(), |
88 | 95 |
} |
96 | ||
89 | 97 |
return table |
90 | 98 | |
91 | 99 |
def get_context_data(self, **kwargs): |
src/authentic2/manager/utils.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
from authentic2.decorators import GlobalCache |
20 | 20 | |
21 |
OU = get_ou_model() |
|
22 | ||
21 | 23 | |
22 | 24 |
def label_from_user(user): |
23 | 25 |
labels = [] |
... | ... | |
39 | 41 | |
40 | 42 |
@GlobalCache(timeout=10) |
41 | 43 |
def get_ou_count(): |
42 |
return get_ou_model().objects.count() |
|
44 |
return OU.objects.count() |
|
45 | ||
46 | ||
47 |
@GlobalCache(timeout=10) |
|
48 |
def has_show_username(): |
|
49 |
return OU.objects.filter(show_username=True).exists() |
src/authentic2/manager/views.py | ||
---|---|---|
666 | 666 |
if OU.objects.count() < 2: |
667 | 667 |
exclude_ou = True |
668 | 668 |
if exclude_ou: |
669 |
kwargs['exclude'] = ['ou'] |
|
669 |
exclude = kwargs.setdefault('exclude', []) |
|
670 |
if 'ou' not in exclude: |
|
671 |
exclude.append('ou') |
|
670 | 672 |
return super(HideOUColumnMixin, self).get_table(**kwargs) |
671 | 673 | |
672 | 674 |
tests/test_user_manager.py | ||
---|---|---|
20 | 20 |
from django.contrib.contenttypes.models import ContentType |
21 | 21 |
from django.utils.six import text_type |
22 | 22 | |
23 |
from django_rbac.utils import get_ou_model |
|
24 | ||
23 | 25 |
from authentic2.custom_user.models import User |
24 | 26 |
from authentic2.models import Attribute, AttributeValue |
25 | 27 |
from authentic2.a2_rbac.utils import get_default_ou |
26 | 28 | |
29 | ||
27 | 30 |
from utils import login, get_link_from_mail, skipif_sqlite |
28 | 31 | |
32 |
OU = get_ou_model() |
|
29 | 33 | |
30 | 34 | |
31 | 35 |
def visible_users(response): |
... | ... | |
171 | 175 |
# disabled attribute should not show up |
172 | 176 |
for line in table: |
173 | 177 |
assert len(line) == num_col |
178 | ||
179 | ||
180 |
def test_user_table(app, admin, user_ou1, ou1): |
|
181 |
from authentic2.manager.utils import has_show_username |
|
182 | ||
183 |
# base state, username are shown |
|
184 |
response = login(app, admin, '/manage/users/') |
|
185 |
assert response.pyquery('td.username') |
|
186 | ||
187 |
# hide all usernames, from specific and general view |
|
188 |
OU.objects.update(show_username=False) |
|
189 |
has_show_username.cache.clear() |
|
190 | ||
191 |
response = app.get('/manage/users/') |
|
192 |
assert not response.pyquery('td.username') |
|
193 | ||
194 |
response = app.get('/manage/users/?search-ou=%s' % get_default_ou().id) |
|
195 |
assert not response.pyquery('td.username') |
|
196 | ||
197 |
response = app.get('/manage/users/?search-ou=%s' % ou1.id) |
|
198 |
assert not response.pyquery('td.username') |
|
199 | ||
200 |
# hide username only in the default OU |
|
201 |
ou1.show_username = True |
|
202 |
ou1.save() |
|
203 |
has_show_username.cache.clear() |
|
204 | ||
205 |
response = app.get('/manage/users/') |
|
206 |
assert response.pyquery('td.username') |
|
207 | ||
208 |
response = app.get('/manage/users/?search-ou=%s' % get_default_ou().id) |
|
209 |
assert not response.pyquery('td.username') |
|
210 | ||
211 |
response = app.get('/manage/users/?search-ou=%s' % ou1.id) |
|
212 |
assert response.pyquery('td.username') |
|
174 |
- |