support: Reject attempts to approve sponsorship for deactivated orgs.

This commit is contained in:
Alex Vandiver 2024-08-14 01:49:42 +00:00 committed by Tim Abbott
parent 1806c390c1
commit 8e1582d82e
2 changed files with 27 additions and 0 deletions

View File

@ -3946,6 +3946,9 @@ class RealmBillingSession(BillingSession):
from zerver.actions.message_send import internal_send_private_message 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) self.do_change_plan_type(tier=None, is_sponsored=True)
if customer is not None and customer.sponsorship_pending: if customer is not None and customer.sponsorship_pending:
customer.sponsorship_pending = False customer.sponsorship_pending = False

View File

@ -22,6 +22,7 @@ from corporate.models import (
get_current_plan_by_customer, get_current_plan_by_customer,
get_customer_by_realm, 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.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.realm_settings import do_change_realm_org_type, do_send_realm_reactivation_email
from zerver.actions.user_settings import do_change_user_setting from zerver.actions.user_settings import do_change_user_setting
@ -1403,6 +1404,29 @@ class TestSupportEndpoint(ZulipTestCase):
) )
self.assert_length(messages, 1) 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: def test_activate_or_deactivate_realm(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
lear_realm = get_realm("lear") lear_realm = get_realm("lear")