diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 562a0b147f..018c997086 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -3832,11 +3832,11 @@ class RealmBillingSession(BillingSession): elif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED: return AuditLogEventType.STRIPE_CARD_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED: - return RealmAuditLog.CUSTOMER_PLAN_CREATED + return AuditLogEventType.CUSTOMER_PLAN_CREATED elif event_type is BillingSessionEventType.DISCOUNT_CHANGED: return AuditLogEventType.REALM_DISCOUNT_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PROPERTY_CHANGED: - return RealmAuditLog.CUSTOMER_PROPERTY_CHANGED + return AuditLogEventType.CUSTOMER_PROPERTY_CHANGED elif event_type is BillingSessionEventType.SPONSORSHIP_APPROVED: return AuditLogEventType.REALM_SPONSORSHIP_APPROVED elif event_type is BillingSessionEventType.SPONSORSHIP_PENDING_STATUS_CHANGED: @@ -3844,11 +3844,11 @@ class RealmBillingSession(BillingSession): elif event_type is BillingSessionEventType.BILLING_MODALITY_CHANGED: return AuditLogEventType.REALM_BILLING_MODALITY_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PLAN_PROPERTY_CHANGED: - return RealmAuditLog.CUSTOMER_PLAN_PROPERTY_CHANGED # nocoverage + return AuditLogEventType.CUSTOMER_PLAN_PROPERTY_CHANGED # nocoverage elif event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN: - return RealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN elif event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN: - return RealmAuditLog.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN else: raise BillingSessionAuditLogEventError(event_type) @@ -4208,11 +4208,11 @@ class RemoteRealmBillingSession(BillingSession): elif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED: return AuditLogEventType.STRIPE_CARD_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED: - return RemoteRealmAuditLog.CUSTOMER_PLAN_CREATED + return AuditLogEventType.CUSTOMER_PLAN_CREATED elif event_type is BillingSessionEventType.DISCOUNT_CHANGED: return RemoteRealmAuditLog.REMOTE_SERVER_DISCOUNT_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PROPERTY_CHANGED: - return RemoteRealmAuditLog.CUSTOMER_PROPERTY_CHANGED # nocoverage + return AuditLogEventType.CUSTOMER_PROPERTY_CHANGED # nocoverage elif event_type is BillingSessionEventType.SPONSORSHIP_APPROVED: return RemoteRealmAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVED elif event_type is BillingSessionEventType.SPONSORSHIP_PENDING_STATUS_CHANGED: @@ -4220,17 +4220,17 @@ class RemoteRealmBillingSession(BillingSession): elif event_type is BillingSessionEventType.BILLING_MODALITY_CHANGED: return RemoteRealmAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGED # nocoverage elif event_type is BillingSessionEventType.CUSTOMER_PLAN_PROPERTY_CHANGED: - return RemoteRealmAuditLog.CUSTOMER_PLAN_PROPERTY_CHANGED + return AuditLogEventType.CUSTOMER_PLAN_PROPERTY_CHANGED elif event_type is BillingSessionEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED: return RemoteRealmAuditLog.REMOTE_SERVER_PLAN_TYPE_CHANGED elif ( event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN ): # nocoverage - return RemoteRealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN elif ( event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN ): # nocoverage - return RemoteRealmAuditLog.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN else: # nocoverage raise BillingSessionAuditLogEventError(event_type) @@ -4651,11 +4651,11 @@ class RemoteServerBillingSession(BillingSession): elif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED: return AuditLogEventType.STRIPE_CARD_CHANGED elif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED: - return RemoteZulipServerAuditLog.CUSTOMER_PLAN_CREATED + return AuditLogEventType.CUSTOMER_PLAN_CREATED elif event_type is BillingSessionEventType.DISCOUNT_CHANGED: return RemoteZulipServerAuditLog.REMOTE_SERVER_DISCOUNT_CHANGED # nocoverage elif event_type is BillingSessionEventType.CUSTOMER_PROPERTY_CHANGED: - return RemoteZulipServerAuditLog.CUSTOMER_PROPERTY_CHANGED # nocoverage + return AuditLogEventType.CUSTOMER_PROPERTY_CHANGED # nocoverage elif event_type is BillingSessionEventType.SPONSORSHIP_APPROVED: return RemoteZulipServerAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVED elif event_type is BillingSessionEventType.SPONSORSHIP_PENDING_STATUS_CHANGED: @@ -4663,17 +4663,17 @@ class RemoteServerBillingSession(BillingSession): elif event_type is BillingSessionEventType.BILLING_MODALITY_CHANGED: return RemoteZulipServerAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGED # nocoverage elif event_type is BillingSessionEventType.CUSTOMER_PLAN_PROPERTY_CHANGED: - return RemoteZulipServerAuditLog.CUSTOMER_PLAN_PROPERTY_CHANGED # nocoverage + return AuditLogEventType.CUSTOMER_PLAN_PROPERTY_CHANGED # nocoverage elif event_type is BillingSessionEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED: return RemoteZulipServerAuditLog.REMOTE_SERVER_PLAN_TYPE_CHANGED elif ( event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN ): # nocoverage - return RemoteZulipServerAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN elif ( event_type is BillingSessionEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN ): # nocoverage - return RemoteZulipServerAuditLog.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN + return AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN else: # nocoverage raise BillingSessionAuditLogEventError(event_type) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 683357937e..efac918276 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -969,12 +969,12 @@ class StripeTest(StripeTestCase): timestamp_to_datetime(stripe_customer.created), ), (AuditLogEventType.STRIPE_CARD_CHANGED, self.now), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), ], ) self.assertEqual(audit_log_entries[3][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1098,13 +1098,13 @@ class StripeTest(StripeTestCase): AuditLogEventType.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(stripe_customer.created), ), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now), ], ) self.assertEqual(audit_log_entries[2][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1239,12 +1239,12 @@ class StripeTest(StripeTestCase): timestamp_to_datetime(stripe_customer.created), ), (AuditLogEventType.STRIPE_CARD_CHANGED, self.now), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), ], ) self.assertEqual(audit_log_entries[3][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1381,13 +1381,13 @@ class StripeTest(StripeTestCase): AuditLogEventType.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(stripe_customer.created), ), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now), ], ) self.assertEqual(audit_log_entries[2][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1499,13 +1499,13 @@ class StripeTest(StripeTestCase): AuditLogEventType.STRIPE_CARD_CHANGED, self.now, ), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now), ], ) self.assertEqual(audit_log_entries[3][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1728,13 +1728,13 @@ class StripeTest(StripeTestCase): AuditLogEventType.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(stripe_customer.created), ), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now), ], ) self.assertEqual(audit_log_entries[2][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -1886,13 +1886,13 @@ class StripeTest(StripeTestCase): AuditLogEventType.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(stripe_customer.created), ), - (RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now), + (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now), (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now), ], ) self.assertEqual(audit_log_entries[2][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED) first_audit_log_entry = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.CUSTOMER_PLAN_CREATED) + RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED) .values_list("extra_data", flat=True) .first() ) @@ -3128,7 +3128,7 @@ class StripeTest(StripeTestCase): annual_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[1], (25, 25) ) audit_log = RealmAuditLog.objects.get( - event_type=RealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN + event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN ) self.assertEqual(audit_log.realm, user.realm) self.assertEqual(audit_log.extra_data["monthly_plan_id"], monthly_plan.id) @@ -3503,7 +3503,7 @@ class StripeTest(StripeTestCase): monthly_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[1], (25, 25) ) audit_log = RealmAuditLog.objects.get( - event_type=RealmAuditLog.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN + event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN ) self.assertEqual(audit_log.realm, user.realm) self.assertEqual(audit_log.extra_data["annual_plan_id"], annual_plan.id) @@ -3679,7 +3679,7 @@ class StripeTest(StripeTestCase): self.assertEqual(new_plan.invoiced_through, ledger_entry) realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN + event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN ).last() assert realm_audit_log is not None @@ -3733,7 +3733,7 @@ class StripeTest(StripeTestCase): self.assertEqual(new_plan.invoiced_through, ledger_entry) realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN + event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN ).last() assert realm_audit_log is not None @@ -6297,7 +6297,7 @@ class TestSupportBillingHelpers(StripeTestCase): message = billing_session.process_support_view_request(support_view_request) self.assertEqual("Minimum licenses for zulip changed to 25 from 0.", message) realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.CUSTOMER_PROPERTY_CHANGED + event_type=AuditLogEventType.CUSTOMER_PROPERTY_CHANGED ).last() assert realm_audit_log is not None expected_extra_data = {"old_value": None, "new_value": 25, "property": "minimum_licenses"} @@ -6337,7 +6337,7 @@ class TestSupportBillingHelpers(StripeTestCase): message = billing_session.process_support_view_request(support_view_request) self.assertEqual("Required plan tier for zulip set to Zulip Cloud Standard.", message) realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.CUSTOMER_PROPERTY_CHANGED + event_type=AuditLogEventType.CUSTOMER_PROPERTY_CHANGED ).last() assert realm_audit_log is not None expected_extra_data = { @@ -6414,7 +6414,7 @@ class TestSupportBillingHelpers(StripeTestCase): ) self.assertEqual(discount_for_plus_plan, None) realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.CUSTOMER_PROPERTY_CHANGED + event_type=AuditLogEventType.CUSTOMER_PROPERTY_CHANGED ).last() assert realm_audit_log is not None expected_extra_data = { @@ -6628,14 +6628,13 @@ class TestRemoteBillingWriteAuditLog(StripeTestCase): session = session_class(remote_object) session.write_to_audit_log( # This "ordinary billing" event type value gets translated by write_to_audit_log - # into a RemoteRealmBillingSession.CUSTOMER_PLAN_CREATED or - # RemoteServerBillingSession.CUSTOMER_PLAN_CREATED value. + # into a AuditLogEventType.CUSTOMER_PLAN_CREATED value. event_type=BillingSessionEventType.CUSTOMER_PLAN_CREATED, event_time=event_time, ) audit_log = audit_log_model.objects.latest("id") assert_audit_log( - audit_log, None, None, audit_log_class.CUSTOMER_PLAN_CREATED, event_time + audit_log, None, None, AuditLogEventType.CUSTOMER_PLAN_CREATED, event_time ) session = session_class(remote_object, remote_billing_user=remote_user) @@ -6645,7 +6644,7 @@ class TestRemoteBillingWriteAuditLog(StripeTestCase): ) audit_log = audit_log_model.objects.latest("id") assert_audit_log( - audit_log, remote_user, None, audit_log_class.CUSTOMER_PLAN_CREATED, event_time + audit_log, remote_user, None, AuditLogEventType.CUSTOMER_PLAN_CREATED, event_time ) session = session_class( @@ -6657,7 +6656,7 @@ class TestRemoteBillingWriteAuditLog(StripeTestCase): ) audit_log = audit_log_model.objects.latest("id") assert_audit_log( - audit_log, None, support_admin, audit_log_class.CUSTOMER_PLAN_CREATED, event_time + audit_log, None, support_admin, AuditLogEventType.CUSTOMER_PLAN_CREATED, event_time ) diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py index 1ddad1e3a2..df901df3b5 100644 --- a/corporate/tests/test_support_views.py +++ b/corporate/tests/test_support_views.py @@ -30,6 +30,7 @@ from zerver.actions.user_settings import do_change_user_setting from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_helpers import reset_email_visibility_to_everyone_in_zulip_realm from zerver.models import MultiuseInvite, PreregistrationUser, Realm, UserMessage, UserProfile +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import OrgTypeEnum, get_org_type_display_name, get_realm from zilencer.lib.remote_counts import MissingDataError @@ -477,7 +478,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): self.assertEqual(plan.next_invoice_date, datetime(2050, 3, 1, tzinfo=timezone.utc)) self.assertFalse(plan.reminder_to_review_plan_email_sent) audit_logs = RemoteRealmAuditLog.objects.filter( - event_type=RemoteRealmAuditLog.CUSTOMER_PLAN_PROPERTY_CHANGED + event_type=AuditLogEventType.CUSTOMER_PLAN_PROPERTY_CHANGED ).order_by("-id") assert audit_logs.exists() reminder_to_review_plan_email_sent_changed_audit_log = audit_logs[0] diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.py index f2e587f05b..bf9445ec63 100644 --- a/zerver/models/realm_audit_logs.py +++ b/zerver/models/realm_audit_logs.py @@ -79,6 +79,13 @@ class AuditLogEventType(IntEnum): STRIPE_PLAN_CHANGED = 403 STRIPE_PLAN_QUANTITY_RESET = 404 + CUSTOMER_CREATED = 501 + CUSTOMER_PLAN_CREATED = 502 + CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 503 + CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN = 504 + CUSTOMER_PROPERTY_CHANGED = 505 + CUSTOMER_PLAN_PROPERTY_CHANGED = 506 + class AbstractRealmAuditLog(models.Model): """Defines fields common to RealmAuditLog and RemoteRealmAuditLog.""" @@ -99,13 +106,6 @@ class AbstractRealmAuditLog(models.Model): extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder) # Event types - CUSTOMER_CREATED = 501 - CUSTOMER_PLAN_CREATED = 502 - CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 503 - CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN = 504 - CUSTOMER_PROPERTY_CHANGED = 505 - CUSTOMER_PLAN_PROPERTY_CHANGED = 506 - STREAM_CREATED = 601 STREAM_DEACTIVATED = 602 STREAM_NAME_CHANGED = 603