From cf226351c41e7a29a0f0868563ccbcbb690be070 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 27 Oct 2021 15:08:21 +0200 Subject: [PATCH] manager: search events by authentication method (#57932) --- src/authentic2/manager/journal_views.py | 9 +++++++++ tests/test_manager_journal.py | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/authentic2/manager/journal_views.py b/src/authentic2/manager/journal_views.py index 4fbf2603..bab85693 100644 --- a/src/authentic2/manager/journal_views.py +++ b/src/authentic2/manager/journal_views.py @@ -94,6 +94,15 @@ class JournalSearchEngine(BaseJournalSearchEngine): ), ) + def search_by_how(self, lexem): + yield Q(data__how=lexem) + + @classmethod + def search_by_how_documentation(cls): + return _( + 'You can use how:fc to find all events related to FranceConnect. Other possible values are "saml", "oidc" and "password".' + ) + EVENT_TYPE_CHOICES = ( ('', _('All')), diff --git a/tests/test_manager_journal.py b/tests/test_manager_journal.py index 2a14ed37..bd0c3c2c 100644 --- a/tests/test_manager_journal.py +++ b/tests/test_manager_journal.py @@ -71,7 +71,7 @@ def events(db, freezer): user=user, session=session1, service=service, - how="franceconnect", + how="fc", ) make("user.logout", user=user, session=session1) @@ -320,7 +320,7 @@ def test_global_journal(app, superuser, events): 'user': '-', }, { - 'message': 'registration using franceconnect', + 'message': 'registration using FranceConnect', 'timestamp': 'Jan. 1, 2020, 1 a.m.', 'type': 'user.registration', 'user': 'Johnny doe', @@ -608,7 +608,7 @@ def test_user_journal(app, superuser, events): assert content == [ { - 'message': 'registration using franceconnect', + 'message': 'registration using FranceConnect', 'timestamp': 'Jan. 1, 2020, 1 a.m.', 'type': 'user.registration', 'user': 'Johnny doe', @@ -1065,7 +1065,16 @@ def test_search(app, superuser, events): text_content(response.pyquery('tbody tr td.journal-list--message-column')[0]).strip() == 'creation of user "Johnny doe"' ) - assert text_content(response.pyquery('tbody tr td.journal-list--session-column')[0]).strip() == 'API' + + response.form.set('search', 'how:fc') + response = response.form.submit() + table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')] + assert table_content == ['registration using FranceConnect'] + + response.form.set('search', 'how:saml') + response = response.form.submit() + table_content = [text_content(p) for p in response.pyquery('tbody td.journal-list--message-column')] + assert table_content == ['login using SAML'] response.form.set('search', '') response.form['event_type'].select(text='Profile changes') -- 2.30.2