From d610e09397b78502644f7f4d425f80458f6cffbe Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Fri, 6 Sep 2024 20:28:32 +0200 Subject: [PATCH] audit-logs: Use AuditLogEventType enum name for string method. Reorders audit log string methods to have the following pattern: "event_type event_time (id): modified_object". And the event type is the name for the AuditLogEventType enum. --- zerver/models/realm_audit_logs.py | 11 +++++++---- zerver/tests/test_audit_log.py | 2 +- zilencer/models.py | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-) 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 = [