Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
audit-log: Move stripe event types to AuditLogEventType enum.
Lauryn Menardbf4a650999e5
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 1ace2d7374c..562a0b147f5 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -3828,9 +3828,9 @@ class RealmBillingSession(BillingSession):@overridedef get_audit_log_event(self, event_type: BillingSessionEventType) -> int:if event_type is BillingSessionEventType.STRIPE_CUSTOMER_CREATED:- return RealmAuditLog.STRIPE_CUSTOMER_CREATED+ return AuditLogEventType.STRIPE_CUSTOMER_CREATEDelif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED:- return RealmAuditLog.STRIPE_CARD_CHANGED+ return AuditLogEventType.STRIPE_CARD_CHANGEDelif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED:return RealmAuditLog.CUSTOMER_PLAN_CREATEDelif event_type is BillingSessionEventType.DISCOUNT_CHANGED:@@ -4204,9 +4204,9 @@ class RemoteRealmBillingSession(BillingSession):@overridedef get_audit_log_event(self, event_type: BillingSessionEventType) -> int:if event_type is BillingSessionEventType.STRIPE_CUSTOMER_CREATED:- return RemoteRealmAuditLog.STRIPE_CUSTOMER_CREATED+ return AuditLogEventType.STRIPE_CUSTOMER_CREATEDelif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED:- return RemoteRealmAuditLog.STRIPE_CARD_CHANGED+ return AuditLogEventType.STRIPE_CARD_CHANGEDelif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED:return RemoteRealmAuditLog.CUSTOMER_PLAN_CREATEDelif event_type is BillingSessionEventType.DISCOUNT_CHANGED:@@ -4647,9 +4647,9 @@ class RemoteServerBillingSession(BillingSession):@overridedef get_audit_log_event(self, event_type: BillingSessionEventType) -> int:if event_type is BillingSessionEventType.STRIPE_CUSTOMER_CREATED:- return RemoteZulipServerAuditLog.STRIPE_CUSTOMER_CREATED+ return AuditLogEventType.STRIPE_CUSTOMER_CREATEDelif event_type is BillingSessionEventType.STRIPE_CARD_CHANGED:- return RemoteZulipServerAuditLog.STRIPE_CARD_CHANGED+ return AuditLogEventType.STRIPE_CARD_CHANGEDelif event_type is BillingSessionEventType.CUSTOMER_PLAN_CREATED:return RemoteZulipServerAuditLog.CUSTOMER_PLAN_CREATEDelif event_type is BillingSessionEventType.DISCOUNT_CHANGED:diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 56804e87911..683357937ef 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -965,10 +965,10 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),- (RealmAuditLog.STRIPE_CARD_CHANGED, self.now),+ (AuditLogEventType.STRIPE_CARD_CHANGED, self.now),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),],)@@ -1095,7 +1095,7 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),@@ -1235,10 +1235,10 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),- (RealmAuditLog.STRIPE_CARD_CHANGED, self.now),+ (AuditLogEventType.STRIPE_CARD_CHANGED, self.now),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),],)@@ -1378,7 +1378,7 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),@@ -1492,11 +1492,11 @@ class StripeTest(StripeTestCase):audit_log_entries[:4],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),(- RealmAuditLog.STRIPE_CARD_CHANGED,+ AuditLogEventType.STRIPE_CARD_CHANGED,self.now,),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),@@ -1725,7 +1725,7 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),@@ -1883,7 +1883,7 @@ class StripeTest(StripeTestCase):audit_log_entries[:3],[(- RealmAuditLog.STRIPE_CUSTOMER_CREATED,+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,timestamp_to_datetime(stripe_customer.created),),(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),@@ -2795,7 +2795,7 @@ class StripeTest(StripeTestCase):stripe.InvoiceItem.create(amount=5000, currency="usd", customer=stripe_customer_id)stripe_invoice = stripe.Invoice.create(customer=stripe_customer_id)stripe.Invoice.finalize_invoice(stripe_invoice)- RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).delete()+ RealmAuditLog.objects.filter(event_type=AuditLogEventType.STRIPE_CARD_CHANGED).delete()start_session_json_response = self.client_billing_post("/billing/session/start_card_update_session"@@ -2857,7 +2857,9 @@ class StripeTest(StripeTestCase):response = self.client_get("/billing/")self.assert_in_success_response(["Visa ending in 0341"], response)- assert RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).exists()+ assert RealmAuditLog.objects.filter(+ event_type=AuditLogEventType.STRIPE_CARD_CHANGED+ ).exists()stripe_payment_methods = stripe.PaymentMethod.list(customer=stripe_customer_id, type="card")self.assert_length(stripe_payment_methods, 2)@@ -2904,7 +2906,8 @@ class StripeTest(StripeTestCase):for stripe_invoice in stripe.Invoice.list(customer=stripe_customer_id):self.assertEqual(stripe_invoice.status, "paid")self.assertEqual(- 2, RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).count()+ 2,+ RealmAuditLog.objects.filter(event_type=AuditLogEventType.STRIPE_CARD_CHANGED).count(),)# Test if manual license management upgrade session is created and is successfully recovered.diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.pyindex eed5ac49ef8..f2e587f05ba 100644--- a/zerver/models/realm_audit_logs.py+++ b/zerver/models/realm_audit_logs.py@@ -74,6 +74,11 @@ class AuditLogEventType(IntEnum):USER_MUTED = 350USER_UNMUTED = 351+ STRIPE_CUSTOMER_CREATED = 401+ STRIPE_CARD_CHANGED = 402+ STRIPE_PLAN_CHANGED = 403+ STRIPE_PLAN_QUANTITY_RESET = 404+class AbstractRealmAuditLog(models.Model):"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""@@ -94,11 +99,6 @@ class AbstractRealmAuditLog(models.Model):extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)# Event types- STRIPE_CUSTOMER_CREATED = 401- STRIPE_CARD_CHANGED = 402- STRIPE_PLAN_CHANGED = 403- STRIPE_PLAN_QUANTITY_RESET = 404-CUSTOMER_CREATED = 501CUSTOMER_PLAN_CREATED = 502CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 503