audit-log: Move user muted event types to AuditLogEventType enum.

Event types moved: USER_MUTED, USER_UNMUTED
This commit is contained in:
Lauryn Menard 2024-09-06 12:57:33 +02:00 committed by Tim Abbott
parent 10d161638e
commit fc6bc6df60
3 changed files with 9 additions and 7 deletions

View File

@ -6,6 +6,7 @@ from django.utils.timezone import now as timezone_now
from zerver.actions.message_flags import do_mark_muted_user_messages_as_read from zerver.actions.message_flags import do_mark_muted_user_messages_as_read
from zerver.lib.muted_users import add_user_mute, get_user_mutes from zerver.lib.muted_users import add_user_mute, get_user_mutes
from zerver.models import MutedUser, RealmAuditLog, UserProfile from zerver.models import MutedUser, RealmAuditLog, UserProfile
from zerver.models.realm_audit_logs import AuditLogEventType
from zerver.tornado.django_api import send_event_on_commit from zerver.tornado.django_api import send_event_on_commit
@ -26,7 +27,7 @@ def do_mute_user(
realm=user_profile.realm, realm=user_profile.realm,
acting_user=user_profile, acting_user=user_profile,
modified_user=user_profile, modified_user=user_profile,
event_type=RealmAuditLog.USER_MUTED, event_type=AuditLogEventType.USER_MUTED,
event_time=date_muted, event_time=date_muted,
extra_data={"muted_user_id": muted_user.id}, extra_data={"muted_user_id": muted_user.id},
) )
@ -44,7 +45,7 @@ def do_unmute_user(mute_object: MutedUser) -> None:
realm=user_profile.realm, realm=user_profile.realm,
acting_user=user_profile, acting_user=user_profile,
modified_user=user_profile, modified_user=user_profile,
event_type=RealmAuditLog.USER_UNMUTED, event_type=AuditLogEventType.USER_UNMUTED,
event_time=timezone_now(), event_time=timezone_now(),
extra_data={"unmuted_user_id": muted_user.id}, extra_data={"unmuted_user_id": muted_user.id},
) )

View File

@ -71,6 +71,9 @@ class AuditLogEventType(IntEnum):
SUBSCRIPTION_DEACTIVATED = 303 SUBSCRIPTION_DEACTIVATED = 303
SUBSCRIPTION_PROPERTY_CHANGED = 304 SUBSCRIPTION_PROPERTY_CHANGED = 304
USER_MUTED = 350
USER_UNMUTED = 351
class AbstractRealmAuditLog(models.Model): class AbstractRealmAuditLog(models.Model):
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog.""" """Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
@ -91,9 +94,6 @@ class AbstractRealmAuditLog(models.Model):
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder) extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
# Event types # Event types
USER_MUTED = 350
USER_UNMUTED = 351
STRIPE_CUSTOMER_CREATED = 401 STRIPE_CUSTOMER_CREATED = 401
STRIPE_CARD_CHANGED = 402 STRIPE_CARD_CHANGED = 402
STRIPE_PLAN_CHANGED = 403 STRIPE_PLAN_CHANGED = 403

View File

@ -9,6 +9,7 @@ from zerver.lib.muted_users import get_mute_object, get_muting_users, get_user_m
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timestamp import datetime_to_timestamp from zerver.lib.timestamp import datetime_to_timestamp
from zerver.models import RealmAuditLog, UserMessage, UserProfile from zerver.models import RealmAuditLog, UserMessage, UserProfile
from zerver.models.realm_audit_logs import AuditLogEventType
class MutedUsersTests(ZulipTestCase): class MutedUsersTests(ZulipTestCase):
@ -111,7 +112,7 @@ class MutedUsersTests(ZulipTestCase):
self.assertEqual( self.assertEqual(
audit_log_entry, audit_log_entry,
( (
RealmAuditLog.USER_MUTED, AuditLogEventType.USER_MUTED,
mute_time, mute_time,
{"muted_user_id": cordelia.id}, {"muted_user_id": cordelia.id},
), ),
@ -171,7 +172,7 @@ class MutedUsersTests(ZulipTestCase):
self.assertEqual( self.assertEqual(
audit_log_entry, audit_log_entry,
( (
RealmAuditLog.USER_UNMUTED, AuditLogEventType.USER_UNMUTED,
mute_time, mute_time,
{"unmuted_user_id": cordelia.id}, {"unmuted_user_id": cordelia.id},
), ),