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
This commit is contained in:
Lauryn Menard 2024-09-06 17:34:05 +02:00 committed by Tim Abbott
parent aad93e149e
commit 00ecd4c8f0
3 changed files with 21 additions and 22 deletions

View File

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

View File

@ -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)

View File

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