Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm: Handle plan_type set to a paid plan without Customer.
Sahil Batraa24b71c13136
diff --git a/zerver/lib/workplace_users.py b/zerver/lib/workplace_users.pyindex 92ba38481d0..11f713eb6ed 100644--- a/zerver/lib/workplace_users.py+++ b/zerver/lib/workplace_users.py@@ -71,7 +71,13 @@ def realm_eligible_for_non_workplace_pricing(realm: Realm) -> bool:from corporate.models.plans import get_current_plan_by_realmcustomer_plan = get_current_plan_by_realm(realm)- assert customer_plan is not None++ if customer_plan is None:+ # Support staff have manually set a paid plan type for+ # this realm, and we want them to be able to correctly+ # configure their billing.+ return True+if customer_plan.fixed_price is not None:# Discounted pricing for non-workplace users is# currently incompatible with a fixed-price plan.@@ -90,10 +96,13 @@ def realm_on_discounted_cloud_plan(realm: Realm) -> bool:from corporate.models.customers import get_customer_by_realm- # We can assume that an active plan will be present- # if realm is not on free or fully sponsored plan.customer = get_customer_by_realm(realm)- assert customer is not None++ if customer is None:+ # Support staff have manually set a paid plan type for+ # this realm.+ return False+return customer.monthly_discounted_price > 0 or customer.annual_discounted_price > 0diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 180f1f7e54b..8b4a673a7c8 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -3326,9 +3326,21 @@ class RealmAPITest(ZulipTestCase):"workplace_users_group": orjson.dumps({"new": members_group.id}).decode(),}+ # Organizations where support staff have manually set plan_type to+ # PLAN_TYPE_STANDARD can enable discounted billing for non-workplace+ # users.+ do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)+ result = self.client_patch("/json/realm", params)+ self.assert_json_success(result)+ realm.refresh_from_db()+ self.assertEqual(realm.workplace_users_group_id, members_group.id)++ params = {+ "workplace_users_group": orjson.dumps({"new": moderators_group.id}).decode(),+ }+# Organizations with a fixed-price plan cannot enable discounted# billing for non-workplace users.- do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)customer = Customer.objects.create(realm=realm, stripe_customer_id="cus_id")plan = CustomerPlan.objects.create(customer=customer,@@ -3372,7 +3384,7 @@ class RealmAPITest(ZulipTestCase):result = self.client_patch("/json/realm", params)self.assert_json_success(result)realm.refresh_from_db()- self.assertEqual(realm.workplace_users_group_id, members_group.id)+ self.assertEqual(realm.workplace_users_group_id, moderators_group.id)def test_changing_can_manage_all_groups(self) -> None:realm = get_realm("zulip")