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.
This commit is contained in:
Lauryn Menard 2024-09-06 20:28:32 +02:00 committed by Tim Abbott
parent 00ecd4c8f0
commit d610e09397
3 changed files with 13 additions and 7 deletions

View File

@ -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}"

View File

@ -292,7 +292,7 @@ class TestRealmAuditLog(ZulipTestCase):
)
self.assertTrue(
repr(audit_entry).startswith(
f"<RealmAuditLog: <UserProfile: {user.email} {user.realm!r}> {AuditLogEventType.USER_EMAIL_CHANGED} "
f"<RealmAuditLog: {AuditLogEventType.USER_EMAIL_CHANGED.name} "
)
)

View File

@ -12,6 +12,7 @@ from analytics.models import BaseCount
from zerver.lib.rate_limiter import RateLimitedObject
from zerver.lib.rate_limiter import rules as rate_limiter_rules
from zerver.models import AbstractPushDeviceToken, AbstractRealmAuditLog, Realm, UserProfile
from zerver.models.realm_audit_logs import AuditLogEventType
def get_remote_server_by_uuid(uuid: str) -> "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 = [