0001-manager-easier-journal-filtering-by-event-types-5005.patch
src/authentic2/manager/journal_views.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import functools |
|
17 | 18 |
import uuid |
18 | 19 | |
20 |
from django import forms |
|
19 | 21 |
from django.contrib.auth import get_user_model |
20 | 22 |
from django.core.exceptions import PermissionDenied, ValidationError |
21 | 23 |
from django.core.validators import EmailValidator |
... | ... | |
23 | 25 |
from django.utils.translation import ugettext_lazy as _ |
24 | 26 | |
25 | 27 |
from authentic2.apps.journal.forms import JournalForm |
28 |
from authentic2.apps.journal.models import EventType |
|
26 | 29 |
from authentic2.apps.journal.search_engine import JournalSearchEngine |
27 | 30 |
from authentic2.apps.journal.views import JournalView |
28 | 31 | |
... | ... | |
69 | 72 |
return self.query_for_users(users) |
70 | 73 | |
71 | 74 | |
75 |
EVENT_TYPE_CHOICES = ( |
|
76 |
('', _('All')), |
|
77 |
( |
|
78 |
_('Users'), |
|
79 |
( |
|
80 |
('login,user.creation,user.registration,sso,password', _('Connection & SSO')), |
|
81 |
('password', _('Password')), |
|
82 |
( |
|
83 |
'password,manager.user.((de)?activation|password|profile|email),^user.deletion,^user.profile', |
|
84 |
_('Profile changes'), |
|
85 |
), |
|
86 |
), |
|
87 |
), |
|
88 |
( |
|
89 |
_('Backoffice'), |
|
90 |
( |
|
91 |
('manager', _('All')), |
|
92 |
('manager.user', _('User management')), |
|
93 |
('manager.role', _('Role management')), |
|
94 |
), |
|
95 |
), |
|
96 |
) |
|
97 | ||
98 | ||
72 | 99 |
class JournalForm(JournalForm): |
73 | 100 |
search_engine_class = JournalSearchEngine |
74 | 101 | |
102 |
event_type = forms.ChoiceField(required=False, choices=EVENT_TYPE_CHOICES) |
|
103 | ||
104 |
def clean_event_type(self): |
|
105 |
patterns = self.cleaned_data['event_type'].split(',') |
|
106 |
qs_filter = functools.reduce(Q.__or__, (Q(name__regex=pattern) for pattern in patterns)) |
|
107 |
return EventType.objects.filter(qs_filter) |
|
108 | ||
109 |
def get_queryset(self, **kwargs): |
|
110 |
qs = super().get_queryset(**kwargs) |
|
111 | ||
112 |
event_type = self.cleaned_data.get('event_type') |
|
113 |
if event_type: |
|
114 |
qs = qs.filter(type__in=event_type) |
|
115 | ||
116 |
return qs |
|
117 | ||
75 | 118 | |
76 | 119 |
class BaseJournalView(views.TitleMixin, views.MediaMixin, views.MultipleOUMixin, JournalView): |
77 | 120 |
template_name = 'authentic2/manager/journal.html' |
tests/test_manager_journal.py | ||
---|---|---|
931 | 931 |
list(map(text_content, p)) |
932 | 932 |
for p in zip(pq('tbody td.journal-list--user-column'), pq('tbody td.journal-list--message-column')) |
933 | 933 |
] == [['Johnny doe', 'login using password']] |
934 | ||
935 |
response.form.set('search', '') |
|
936 |
response.form['event_type'].select(text='Profile changes') |
|
937 |
response = response.form.submit() |
|
938 | ||
939 |
table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')] |
|
940 |
assert table_content == [ |
|
941 |
'deactivation of user "Johnny doe"', |
|
942 |
'activation of user "Johnny doe"', |
|
943 |
'mandatory password change at next login unset for user "Johnny doe"', |
|
944 |
'mandatory password change at next login set for user "Johnny doe"', |
|
945 |
'password reset request of "Johnny doe" sent to "user@example.com"', |
|
946 |
'password change of user "Johnny doe" and notification by mail', |
|
947 |
'password change of user "Johnny doe"', |
|
948 |
'email change of user "Johnny doe" for email address "jane@example.com"', |
|
949 |
'edit of user "Johnny doe" (first name)', |
|
950 |
'password reset', |
|
951 |
'password reset failure with email "USER@example.com"', |
|
952 |
'password reset request with email "user@example.com"', |
|
953 |
'user deletion', |
|
954 |
'profile edit (first name)', |
|
955 |
'password change', |
|
956 |
] |
|
957 | ||
958 |
response.form['event_type'].select(text='Role management') |
|
959 |
response = response.form.submit() |
|
960 | ||
961 |
table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')] |
|
962 |
assert table_content[:3] == [ |
|
963 |
'removal of user "user (111111)" as administrator of role "role1"', |
|
964 |
'addition of user "user (111111)" as administrator of role "role1"', |
|
965 |
'removal of role "role2" as administrator of role "role1"', |
|
966 |
] |
|
934 |
- |