From 8e1582d82e17bc657afe8d196ae13580891fdfd4 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 14 Aug 2024 01:49:42 +0000 Subject: [PATCH] support: Reject attempts to approve sponsorship for deactivated orgs. --- corporate/lib/stripe.py | 3 +++ corporate/tests/test_support_views.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index e8ddb268ab..46c61a99c2 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -3946,6 +3946,9 @@ class RealmBillingSession(BillingSession): from zerver.actions.message_send import internal_send_private_message + if self.realm.deactivated: + raise SupportRequestError("Realm has been deactivated") + self.do_change_plan_type(tier=None, is_sponsored=True) if customer is not None and customer.sponsorship_pending: customer.sponsorship_pending = False diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py index e9a728453a..aef416e207 100644 --- a/corporate/tests/test_support_views.py +++ b/corporate/tests/test_support_views.py @@ -22,6 +22,7 @@ from corporate.models import ( get_current_plan_by_customer, get_customer_by_realm, ) +from zerver.actions.create_realm import do_create_realm from zerver.actions.invites import do_create_multiuse_invite_link from zerver.actions.realm_settings import do_change_realm_org_type, do_send_realm_reactivation_email from zerver.actions.user_settings import do_change_user_setting @@ -1403,6 +1404,29 @@ class TestSupportEndpoint(ZulipTestCase): ) self.assert_length(messages, 1) + def test_approve_sponsorship_deactivated_realm(self) -> None: + support_admin = self.example_user("iago") + with self.settings(BILLING_ENABLED=True): + limited_realm = do_create_realm("limited", "limited") + self.assertEqual(limited_realm.plan_type, Realm.PLAN_TYPE_LIMITED) + billing_session = RealmBillingSession( + user=support_admin, realm=limited_realm, support_session=True + ) + billing_session.update_customer_sponsorship_status(True) + limited_realm.deactivated = True + limited_realm.save() + + iago = self.example_user("iago") + self.login_user(iago) + + result = self.client_post( + "/activity/support", + {"realm_id": f"{limited_realm.id}", "approve_sponsorship": "true"}, + ) + self.assertIn(b"Realm has been deactivated", result.content) + limited_realm.refresh_from_db() + self.assertEqual(limited_realm.plan_type, Realm.PLAN_TYPE_LIMITED) + def test_activate_or_deactivate_realm(self) -> None: cordelia = self.example_user("cordelia") lear_realm = get_realm("lear")