manager: easier journal filtering by event types (#50054)
This commit is contained in:
parent
f361cfdd16
commit
91a190cda7
|
@ -14,8 +14,10 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import functools
|
||||
import uuid
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.core.validators import EmailValidator
|
||||
|
@ -23,6 +25,7 @@ from django.db.models import Q
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from authentic2.apps.journal.forms import JournalForm
|
||||
from authentic2.apps.journal.models import EventType
|
||||
from authentic2.apps.journal.search_engine import JournalSearchEngine
|
||||
from authentic2.apps.journal.views import JournalView
|
||||
|
||||
|
@ -69,9 +72,49 @@ to user whose UUID is <tt>1234</tt>.'''
|
|||
return self.query_for_users(users)
|
||||
|
||||
|
||||
EVENT_TYPE_CHOICES = (
|
||||
('', _('All')),
|
||||
(
|
||||
_('Users'),
|
||||
(
|
||||
('login,user.creation,user.registration,sso,password', _('Connection & SSO')),
|
||||
('password', _('Password')),
|
||||
(
|
||||
'password,manager.user.((de)?activation|password|profile|email),^user.deletion,^user.profile',
|
||||
_('Profile changes'),
|
||||
),
|
||||
),
|
||||
),
|
||||
(
|
||||
_('Backoffice'),
|
||||
(
|
||||
('manager', _('All')),
|
||||
('manager.user', _('User management')),
|
||||
('manager.role', _('Role management')),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class JournalForm(JournalForm):
|
||||
search_engine_class = JournalSearchEngine
|
||||
|
||||
event_type = forms.ChoiceField(required=False, choices=EVENT_TYPE_CHOICES)
|
||||
|
||||
def clean_event_type(self):
|
||||
patterns = self.cleaned_data['event_type'].split(',')
|
||||
qs_filter = functools.reduce(Q.__or__, (Q(name__regex=pattern) for pattern in patterns))
|
||||
return EventType.objects.filter(qs_filter)
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
qs = super().get_queryset(**kwargs)
|
||||
|
||||
event_type = self.cleaned_data.get('event_type')
|
||||
if event_type:
|
||||
qs = qs.filter(type__in=event_type)
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
class BaseJournalView(views.TitleMixin, views.MediaMixin, views.MultipleOUMixin, JournalView):
|
||||
template_name = 'authentic2/manager/journal.html'
|
||||
|
|
|
@ -931,3 +931,36 @@ def test_search(app, superuser, events):
|
|||
list(map(text_content, p))
|
||||
for p in zip(pq('tbody td.journal-list--user-column'), pq('tbody td.journal-list--message-column'))
|
||||
] == [['Johnny doe', 'login using password']]
|
||||
|
||||
response.form.set('search', '')
|
||||
response.form['event_type'].select(text='Profile changes')
|
||||
response = response.form.submit()
|
||||
|
||||
table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')]
|
||||
assert table_content == [
|
||||
'deactivation of user "Johnny doe"',
|
||||
'activation of user "Johnny doe"',
|
||||
'mandatory password change at next login unset for user "Johnny doe"',
|
||||
'mandatory password change at next login set for user "Johnny doe"',
|
||||
'password reset request of "Johnny doe" sent to "user@example.com"',
|
||||
'password change of user "Johnny doe" and notification by mail',
|
||||
'password change of user "Johnny doe"',
|
||||
'email change of user "Johnny doe" for email address "jane@example.com"',
|
||||
'edit of user "Johnny doe" (first name)',
|
||||
'password reset',
|
||||
'password reset failure with email "USER@example.com"',
|
||||
'password reset request with email "user@example.com"',
|
||||
'user deletion',
|
||||
'profile edit (first name)',
|
||||
'password change',
|
||||
]
|
||||
|
||||
response.form['event_type'].select(text='Role management')
|
||||
response = response.form.submit()
|
||||
|
||||
table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')]
|
||||
assert table_content[:3] == [
|
||||
'removal of user "user (111111)" as administrator of role "role1"',
|
||||
'addition of user "user (111111)" as administrator of role "role1"',
|
||||
'removal of role "role2" as administrator of role "role1"',
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue