From 6091e8ebe212cf9dc6c6946981c0e6bbfd6ae136 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 21 Sep 2022 10:21:33 +0200 Subject: [PATCH] auth_saml: improve journal message for related objects (#69368) --- src/authentic2_auth_saml/journal_event_types.py | 16 +++++++++------- src/authentic2_auth_saml/models.py | 4 ++-- tests/test_manager_journal.py | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/authentic2_auth_saml/journal_event_types.py b/src/authentic2_auth_saml/journal_event_types.py index e5e7c04fc..bef5295bd 100644 --- a/src/authentic2_auth_saml/journal_event_types.py +++ b/src/authentic2_auth_saml/journal_event_types.py @@ -26,7 +26,7 @@ class SAMLAuthenticatorEvents(EventTypeDefinition): @classmethod def record(cls, *, user, session, related_object, data=None): data = data or {} - data.update({'related_object': repr(related_object)}) + data.update({'related_object': related_object.get_journal_text()}) super().record(user=user, session=session, references=[related_object.authenticator], data=data) @@ -39,11 +39,11 @@ class SAMLAuthenticatorRelatedObjectCreation(SAMLAuthenticatorEvents): (authenticator,) = event.get_typed_references(SAMLAuthenticator) related_object = event.get_data('related_object') if context != authenticator: - return _('creation of {related_object} in authenticator "{authenticator}"').format( + return _('creation of object "{related_object}" in authenticator "{authenticator}"').format( related_object=related_object, authenticator=authenticator ) else: - return _('creation of %s') % related_object + return _('creation of object "%s"') % related_object class SAMLAuthenticatorRelatedObjectEdit(SAMLAuthenticatorEvents): @@ -66,13 +66,15 @@ class SAMLAuthenticatorRelatedObjectEdit(SAMLAuthenticatorEvents): new = event.get_data('new') or {} edited_attributes = ', '.join(new) or '' if context != authenticator: - return _('edit {related_object} in authenticator "{authenticator}" ({change})').format( + return _( + 'edit of object "{related_object}" in authenticator "{authenticator}" ({change})' + ).format( related_object=related_object, authenticator=authenticator, change=edited_attributes, ) else: - return _('edit {related_object} ({change})').format( + return _('edit of object "{related_object}" ({change})').format( related_object=related_object, change=edited_attributes ) @@ -86,8 +88,8 @@ class SAMLAuthenticatorRelatedObjectDeletion(SAMLAuthenticatorEvents): (authenticator,) = event.get_typed_references(SAMLAuthenticator) related_object = event.get_data('related_object') if context != authenticator: - return _('deletion of {related_object} in authenticator "{authenticator}"').format( + return _('deletion of object "{related_object}" in authenticator "{authenticator}"').format( related_object=related_object, authenticator=authenticator ) else: - return _('deletion of %s') % related_object + return _('deletion of object "%s"') % related_object diff --git a/src/authentic2_auth_saml/models.py b/src/authentic2_auth_saml/models.py index c4a2df5af..1566ed5e6 100644 --- a/src/authentic2_auth_saml/models.py +++ b/src/authentic2_auth_saml/models.py @@ -205,8 +205,8 @@ class SAMLRelatedObjectBase(models.Model): class Meta: abstract = True - def __repr__(self): - return '%s (%s)' % (self._meta.object_name, self.pk) + def get_journal_text(self): + return '%s (%s)' % (self._meta.verbose_name, self.pk) def get_user_field_display(self): from authentic2.forms.widgets import SelectAttributeWidget diff --git a/tests/test_manager_journal.py b/tests/test_manager_journal.py index 833c25acb..f36defd2b 100644 --- a/tests/test_manager_journal.py +++ b/tests/test_manager_journal.py @@ -727,21 +727,21 @@ def test_global_journal(app, superuser, events): 'user': 'agent', }, { - 'message': 'creation of SetAttributeAction (%s) in authenticator "SAML"' + 'message': 'creation of object "Set an attribute (%s)" in authenticator "SAML"' % set_attribute_action.pk, 'timestamp': 'Jan. 3, 2020, 8 a.m.', 'type': 'authenticator.saml.related_object.creation', 'user': 'agent', }, { - 'message': 'edit SetAttributeAction (%s) in authenticator "SAML" (from_name)' + 'message': 'edit of object "Set an attribute (%s)" in authenticator "SAML" (from_name)' % set_attribute_action.pk, 'timestamp': 'Jan. 3, 2020, 9 a.m.', 'type': 'authenticator.saml.related_object.edit', 'user': 'agent', }, { - 'message': 'deletion of SetAttributeAction (%s) in authenticator "SAML"' + 'message': 'deletion of object "Set an attribute (%s)" in authenticator "SAML"' % set_attribute_action.pk, 'timestamp': 'Jan. 3, 2020, 10 a.m.', 'type': 'authenticator.saml.related_object.deletion', -- 2.30.2