diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.py index 3ff03bc02d..03e11f6836 100644 --- a/zerver/models/realm_audit_logs.py +++ b/zerver/models/realm_audit_logs.py @@ -262,10 +262,13 @@ class RealmAuditLog(AbstractRealmAuditLog): @override def __str__(self) -> str: + event_type_name = AuditLogEventType(self.event_type).name if self.modified_user is not None: - return f"{self.modified_user!r} {self.event_type} {self.event_time} {self.id}" + return f"{event_type_name} {self.event_time} (id={self.id}): {self.modified_user!r}" if self.modified_stream is not None: - return f"{self.modified_stream!r} {self.event_type} {self.event_time} {self.id}" + return f"{event_type_name} {self.event_time} (id={self.id}): {self.modified_stream!r}" if self.modified_user_group is not None: - return f"{self.modified_user_group!r} {self.event_type} {self.event_time} {self.id}" - return f"{self.realm!r} {self.event_type} {self.event_time} {self.id}" + return ( + f"{event_type_name} {self.event_time} (id={self.id}): {self.modified_user_group!r}" + ) + return f"{event_type_name} {self.event_time} (id={self.id}): {self.realm!r}" diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index 48ff85fcdf..15f91f4d11 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -292,7 +292,7 @@ class TestRealmAuditLog(ZulipTestCase): ) self.assertTrue( repr(audit_entry).startswith( - f" {AuditLogEventType.USER_EMAIL_CHANGED} " + f" "RemoteZulipServer": @@ -292,7 +293,8 @@ class RemoteZulipServerAuditLog(AbstractRealmAuditLog): @override def __str__(self) -> str: - return f"{self.server!r} {self.event_type} {self.event_time} {self.id}" + event_type_name = AuditLogEventType(self.event_type).name + return f"{event_type_name} {self.event_time} (id={self.id}): {self.server!r}" class RemoteRealmAuditLog(AbstractRealmAuditLog): @@ -319,7 +321,8 @@ class RemoteRealmAuditLog(AbstractRealmAuditLog): @override def __str__(self) -> str: - return f"{self.server!r} {self.event_type} {self.event_time} {self.id}" + event_type_name = AuditLogEventType(self.event_type).name + return f"{event_type_name} {self.event_time} (id={self.id}): {self.server!r}" class Meta: constraints = [