From 00ecd4c8f0aa062fa7b88307be367a801dab1037 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Fri, 6 Sep 2024 17:34:05 +0200 Subject: [PATCH] audit-log: Move remote realm event types to AuditLogEventType enum. Event types moved: REMOTE_REALM_VALUE_UPDATED, REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM, REMOTE_REALM_LOCALLY_DELETED REMOTE_REALM_LOCALLY_DELETED_RESTORED --- zerver/models/realm_audit_logs.py | 19 +++++++++---------- zerver/tests/test_push_notifications.py | 16 ++++++++-------- zilencer/views.py | 8 ++++---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.py index 4d4926911d..3ff03bc02d 100644 --- a/zerver/models/realm_audit_logs.py +++ b/zerver/models/realm_audit_logs.py @@ -120,6 +120,14 @@ class AuditLogEventType(IntEnum): REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED = 10213 REMOTE_SERVER_CREATED = 10215 + # This value is for RemoteRealmAuditLog entries tracking changes to the + # RemoteRealm model resulting from modified realm information sent to us + # via send_server_data_to_push_bouncer. + REMOTE_REALM_VALUE_UPDATED = 20001 + REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM = 20002 + REMOTE_REALM_LOCALLY_DELETED = 20003 + REMOTE_REALM_LOCALLY_DELETED_RESTORED = 20004 + class AbstractRealmAuditLog(models.Model): """Defines fields common to RealmAuditLog and RemoteRealmAuditLog.""" @@ -139,16 +147,7 @@ class AbstractRealmAuditLog(models.Model): extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder) - # Event types - - # This value is for RemoteRealmAuditLog entries tracking changes to the - # RemoteRealm model resulting from modified realm information sent to us - # via send_server_data_to_push_bouncer. - REMOTE_REALM_VALUE_UPDATED = 20001 - REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM = 20002 - REMOTE_REALM_LOCALLY_DELETED = 20003 - REMOTE_REALM_LOCALLY_DELETED_RESTORED = 20004 - + # See AuditLogEventType class above. event_type = models.PositiveSmallIntegerField() # event_types synced from on-prem installations to Zulip Cloud when diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 1cd7678165..ebc545b800 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -1729,7 +1729,7 @@ class AnalyticsBouncerTest(BouncerTestCase): # Verify the RemoteRealmAuditLog entries created. remote_audit_logs = ( RemoteRealmAuditLog.objects.filter( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_realm=zephyr_remote_realm, ) .order_by("id") @@ -1740,7 +1740,7 @@ class AnalyticsBouncerTest(BouncerTestCase): list(remote_audit_logs), [ dict( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_id=None, realm_id=zephyr_realm.id, extra_data={ @@ -1750,7 +1750,7 @@ class AnalyticsBouncerTest(BouncerTestCase): }, ), dict( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_id=None, realm_id=zephyr_realm.id, extra_data={ @@ -1760,7 +1760,7 @@ class AnalyticsBouncerTest(BouncerTestCase): }, ), dict( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_id=None, realm_id=zephyr_realm.id, extra_data={ @@ -1770,7 +1770,7 @@ class AnalyticsBouncerTest(BouncerTestCase): }, ), dict( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_id=None, realm_id=zephyr_realm.id, extra_data={ @@ -1780,7 +1780,7 @@ class AnalyticsBouncerTest(BouncerTestCase): }, ), dict( - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, remote_id=None, realm_id=zephyr_realm.id, extra_data={ @@ -2719,7 +2719,7 @@ class AnalyticsBouncerTest(BouncerTestCase): self.assertEqual(analytics_logger.output, ["WARNING:zulip.analytics:Dummy warning"]) audit_log = RemoteRealmAuditLog.objects.latest("id") - self.assertEqual(audit_log.event_type, RemoteRealmAuditLog.REMOTE_REALM_LOCALLY_DELETED) + self.assertEqual(audit_log.event_type, AuditLogEventType.REMOTE_REALM_LOCALLY_DELETED) self.assertEqual(audit_log.remote_realm, remote_realm_for_deleted_realm) from django.core.mail import outbox @@ -2758,7 +2758,7 @@ class AnalyticsBouncerTest(BouncerTestCase): audit_log = RemoteRealmAuditLog.objects.latest("id") self.assertEqual( - audit_log.event_type, RemoteRealmAuditLog.REMOTE_REALM_LOCALLY_DELETED_RESTORED + audit_log.event_type, AuditLogEventType.REMOTE_REALM_LOCALLY_DELETED_RESTORED ) self.assertEqual(audit_log.remote_realm, remote_realm_for_deleted_realm) diff --git a/zilencer/views.py b/zilencer/views.py index 5839d813b9..a47723e49b 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -917,7 +917,7 @@ def update_remote_realm_data_for_server( remote_id=None, remote_realm=remote_realm, realm_id=realm.id, - event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, + event_type=AuditLogEventType.REMOTE_REALM_VALUE_UPDATED, event_time=now, extra_data={ "attr_name": remote_realm_attr, @@ -936,7 +936,7 @@ def update_remote_realm_data_for_server( remote_id=None, remote_realm=remote_realm, realm_id=uuid_to_realm_dict[str(remote_realm.uuid)].id, - event_type=RemoteRealmAuditLog.REMOTE_REALM_LOCALLY_DELETED_RESTORED, + event_type=AuditLogEventType.REMOTE_REALM_LOCALLY_DELETED_RESTORED, event_time=now, ) ) @@ -977,7 +977,7 @@ def update_remote_realm_data_for_server( remote_id=None, remote_realm=remote_realm, realm_id=None, - event_type=RemoteRealmAuditLog.REMOTE_REALM_LOCALLY_DELETED, + event_type=AuditLogEventType.REMOTE_REALM_LOCALLY_DELETED, event_time=now, ) ) @@ -1133,7 +1133,7 @@ def handle_customer_migration_from_server_to_realm( RemoteRealmAuditLog( server=server, remote_realm=remote_realm, - event_type=RemoteRealmAuditLog.REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM, + event_type=AuditLogEventType.REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM, event_time=event_time, extra_data={ "attr_name": "plan_type",