manager: apply event_type filter even if not event type was found (#69264)

An empty queryset is not the same as the absence of a queryset.
This commit is contained in:
Benjamin Dauvergne 2022-09-19 14:58:37 +02:00
parent 467bb3c7df
commit 0a334b5d21
2 changed files with 15 additions and 2 deletions

View File

@ -150,7 +150,7 @@ class JournalForm(BaseJournalForm):
qs = super().get_queryset(**kwargs)
event_type = self.cleaned_data.get('_event_type')
if event_type:
if event_type is not None:
qs = qs.filter(type__in=event_type)
return qs

View File

@ -24,7 +24,7 @@ from django.utils.timezone import make_aware
from authentic2.a2_rbac.models import Role
from authentic2.a2_rbac.utils import get_default_ou
from authentic2.apps.authenticators.models import LoginPasswordAuthenticator
from authentic2.apps.journal.models import Event, _registry
from authentic2.apps.journal.models import Event, EventType, _registry
from authentic2.custom_user.models import Profile, ProfileType, User
from authentic2.journal import journal
from authentic2.models import Service
@ -1357,3 +1357,16 @@ def test_delete_authenticator(app, superuser, events):
response = response.form.submit()
assert len(response.pyquery('tbody tr')) == 1
assert 'creation of authenticator "Password"' in response.pyquery('tbody tr').text()
def test_empty_event_types(app, superuser, events):
'''Check that filtering by a/some non existing event type/s show an empty event's table.'''
# keep only sso events and event type
Event.objects.exclude(type__name__contains='sso').delete()
EventType.objects.exclude(name__contains='sso').delete()
# try to list only the deletion events (there should be none)
login(app, user=superuser)
response = app.get('/manage/journal/')
response.form['event_type'].select(text='User deletions')
response = response.form.submit()
assert len(response.pyquery('tbody tr[data-event-type]')) == 0