auth_saml: improve journal message for related objects (#69368)
This commit is contained in:
parent
a2568a45b5
commit
249f425c22
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue