Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing: Add PLUS as a plan_type to Realm.

Vishnu KSaff52722a7a8
diff --git a/analytics/tests/test_support_views.py b/analytics/tests/test_support_views.py
index d72f1e436cc..b2caafe63b9 100644
--- a/analytics/tests/test_support_views.py
+++ b/analytics/tests/test_support_views.py
@@ -356,6 +356,15 @@ class TestSupportEndpoint(ZulipTestCase):
["Plan type of zulip changed from self hosted to limited"], result
)
+ with mock.patch("analytics.views.support.do_change_plan_type") as m:
+ result = self.client_post(
+ "/activity/support", {"realm_id": f"{iago.realm_id}", "plan_type": "10"}
+ )
+ m.assert_called_once_with(get_realm("zulip"), 10, acting_user=iago)
+ self.assert_in_success_response(
+ ["Plan type of zulip changed from self hosted to plus"], result
+ )
+
def test_change_org_type(self) -> None:
cordelia = self.example_user("cordelia")
self.login_user(cordelia)
diff --git a/analytics/views/installation_activity.py b/analytics/views/installation_activity.py
index 5de2abf3866..92e6a936def 100644
--- a/analytics/views/installation_activity.py
+++ b/analytics/views/installation_activity.py
@@ -223,7 +223,7 @@ def realm_summary_table(realm_minutes: Dict[str, float]) -> str:
if string_id in estimated_arrs:
row["arr"] = estimated_arrs[string_id]
- if row["plan_type"] == Realm.STANDARD:
+ if row["plan_type"] in [Realm.STANDARD, Realm.PLUS]:
row["effective_rate"] = 100 - int(realms_to_default_discount.get(string_id, 0))
elif row["plan_type"] == Realm.STANDARD_FREE:
row["effective_rate"] = 0
diff --git a/analytics/views/support.py b/analytics/views/support.py
index ec2e85b7996..e90f8670052 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -58,7 +58,13 @@ if settings.BILLING_ENABLED:
def get_plan_name(plan_type: int) -> str:
- return ["", "self hosted", "limited", "standard", "open source"][plan_type]
+ return {
+ Realm.SELF_HOSTED: "self hosted",
+ Realm.LIMITED: "limited",
+ Realm.STANDARD: "standard",
+ Realm.STANDARD_FREE: "open source",
+ Realm.PLUS: "plus",
+ }[plan_type]
def get_confirmations(
diff --git a/templates/analytics/realm_details.html b/templates/analytics/realm_details.html
index 989706daf2a..8320f2abf5e 100644
--- a/templates/analytics/realm_details.html
+++ b/templates/analytics/realm_details.html
@@ -71,6 +71,7 @@
<option value="2" {% if realm.plan_type == 2 %}selected{% endif %}>Limited</option>
<option value="3" {% if realm.plan_type == 3 %}selected{% endif %}>Standard</option>
<option value="4" {% if realm.plan_type == 4 %}selected{% endif %}>Standard Free</option>
+ <option value="10" {% if realm.plan_type == 10 %}selected{% endif %}>Plus</option>
</select>
<button type="submit" class="btn btn-default support-submit-button">Update</button>
</form>
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 503a078f930..6a84dbcabae 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -4625,7 +4625,11 @@ def do_change_plan_type(
extra_data={"old_value": old_value, "new_value": plan_type},
)
- if plan_type == Realm.STANDARD:
+ if plan_type == Realm.PLUS:
+ realm.max_invites = Realm.INVITES_STANDARD_REALM_DAILY_MAX
+ realm.message_visibility_limit = None
+ realm.upload_quota_gb = Realm.UPLOAD_QUOTA_STANDARD
+ elif plan_type == Realm.STANDARD:
realm.max_invites = Realm.INVITES_STANDARD_REALM_DAILY_MAX
realm.message_visibility_limit = None
realm.upload_quota_gb = Realm.UPLOAD_QUOTA_STANDARD
diff --git a/zerver/models.py b/zerver/models.py
index 6580bc3e6a8..f5a0b32013b 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -540,6 +540,7 @@ class Realm(models.Model):
LIMITED = 2
STANDARD = 3
STANDARD_FREE = 4
+ PLUS = 10
plan_type: int = models.PositiveSmallIntegerField(default=SELF_HOSTED)
# This value is also being used in static/js/settings_bots.bot_creation_policy_values.
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 8518d666317..75c4f7a2876 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -754,7 +754,16 @@ class HomeTest(ZulipTestCase):
self.assertTrue(billing_info.show_billing)
self.assertFalse(billing_info.show_plans)
+ # billing admin, with CustomerPlan and realm plan_type PLUS -> show only billing link
+ do_change_plan_type(user.realm, Realm.PLUS, acting_user=None)
+ user.save(update_fields=["role", "is_billing_admin"])
+ with self.settings(CORPORATE_ENABLED=True):
+ billing_info = get_billing_info(user)
+ self.assertTrue(billing_info.show_billing)
+ self.assertFalse(billing_info.show_plans)
+
# member, with CustomerPlan and realm plan_type STANDARD -> neither billing link or plans
+ do_change_plan_type(user.realm, Realm.STANDARD, acting_user=None)
user.is_billing_admin = False
user.save(update_fields=["is_billing_admin"])
with self.settings(CORPORATE_ENABLED=True):
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index c959c8bf62a..2b98779afb5 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -699,6 +699,12 @@ class RealmTest(ZulipTestCase):
self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD)
do_change_plan_type(realm, Realm.LIMITED, acting_user=iago)
+ do_change_plan_type(realm, Realm.PLUS, acting_user=iago)
+ realm = get_realm("zulip")
+ self.assertEqual(realm.plan_type, Realm.PLUS)
+ self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
+ self.assertEqual(realm.message_visibility_limit, None)
+ self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD)
do_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=iago)
self.assertEqual(realm.plan_type, Realm.SELF_HOSTED)