Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
support: Reject attempts to approve sponsorship for deactivated orgs.
Alex Vandiver8e1582d82e17
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex e8ddb268abb..46c61a99c2e 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 = Falsediff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.pyindex e9a728453ab..aef416e207a 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_realmfrom zerver.actions.invites import do_create_multiuse_invite_linkfrom zerver.actions.realm_settings import do_change_realm_org_type, do_send_realm_reactivation_emailfrom 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")