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.

stripe: Add required plan tier for cloud realms on support page.

Aman Agrawal04638ffaee31
diff --git a/corporate/views/support.py b/corporate/views/support.py
index 5b31ef1daeb..a5573da841c 100644
--- a/corporate/views/support.py
+++ b/corporate/views/support.py
@@ -296,6 +296,21 @@ def get_realm_plan_type_options() -> List[SupportSelectOption]:
return plan_types
+def get_realm_plan_type_options_for_discount() -> List[SupportSelectOption]:
+ plan_types = [
+ SupportSelectOption("None", 0),
+ SupportSelectOption(
+ CustomerPlan.name_from_tier(CustomerPlan.TIER_CLOUD_STANDARD),
+ CustomerPlan.TIER_CLOUD_STANDARD,
+ ),
+ SupportSelectOption(
+ CustomerPlan.name_from_tier(CustomerPlan.TIER_CLOUD_PLUS),
+ CustomerPlan.TIER_CLOUD_PLUS,
+ ),
+ ]
+ return plan_types
+
+
VALID_MODIFY_PLAN_METHODS = [
"downgrade_at_billing_cycle_end",
"downgrade_now_without_additional_licenses",
@@ -321,6 +336,8 @@ def support(
realm_id: Optional[int] = REQ(default=None, converter=to_non_negative_int),
plan_type: Optional[int] = REQ(default=None, converter=to_non_negative_int),
discount: Optional[Decimal] = REQ(default=None, converter=to_decimal),
+ minimum_licenses: Optional[int] = REQ(default=None, converter=to_non_negative_int),
+ required_plan_tier: Optional[int] = REQ(default=None, converter=to_non_negative_int),
new_subdomain: Optional[str] = REQ(default=None),
status: Optional[str] = REQ(default=None, str_validator=check_string_in(VALID_STATUS_VALUES)),
billing_modality: Optional[str] = REQ(
@@ -370,6 +387,16 @@ def support(
support_type=SupportType.attach_discount,
discount=discount,
)
+ elif minimum_licenses is not None:
+ support_view_request = SupportViewRequest(
+ support_type=SupportType.update_minimum_licenses,
+ minimum_licenses=minimum_licenses,
+ )
+ elif required_plan_tier is not None:
+ support_view_request = SupportViewRequest(
+ support_type=SupportType.update_required_plan_tier,
+ required_plan_tier=required_plan_tier,
+ )
elif billing_modality is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_billing_modality,
@@ -537,6 +564,7 @@ def support(
context["realm_icon_url"] = realm_icon_url
context["Confirmation"] = Confirmation
context["REALM_PLAN_TYPES"] = get_realm_plan_type_options()
+ context["REALM_PLAN_TYPES_FOR_DISCOUNT"] = get_realm_plan_type_options_for_discount()
context["ORGANIZATION_TYPES"] = sorted(
Realm.ORG_TYPES.values(), key=lambda d: d["display_order"]
)
diff --git a/templates/corporate/support/realm_details.html b/templates/corporate/support/realm_details.html
index 538c615213d..768c43584cb 100644
--- a/templates/corporate/support/realm_details.html
+++ b/templates/corporate/support/realm_details.html
@@ -103,18 +103,13 @@
</form>
{% endif %}
- <form method="POST" class="support-discount-form support-form">
- <b>Discount (use 85 for nonprofits)</b>:<br />
- {{ csrf_input }}
- <input type="hidden" name="realm_id" value="{{ realm.id }}" />
- {% if realm_support_data[realm.id].plan_data.current_plan and realm_support_data[realm.id].plan_data.current_plan.fixed_price %}
- <input type="number" name="discount" value="{{ format_discount(realm_support_data[realm.id].sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" disabled />
- <button type="submit" class="support-submit-button" disabled>Update</button>
- {% else %}
- <input type="number" name="discount" value="{{ format_discount(realm_support_data[realm.id].sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" required />
- <button type="submit" class="support-submit-button">Update</button>
- {% endif %}
- </form>
+ {% with %}
+ {% set sponsorship_data = realm_support_data[realm.id].sponsorship_data %}
+ {% set PLAN_TYPES = REALM_PLAN_TYPES_FOR_DISCOUNT %}
+ {% set remote_id = realm.id %}
+ {% set remote_type = "realm_id" %}
+ {% include 'corporate/support/sponsorship_discount_forms.html' %}
+ {% endwith %}
{% if realm_support_data[realm.id].sponsorship_data.sponsorship_pending %}
{% with %}
diff --git a/templates/corporate/support/sponsorship_discount_forms.html b/templates/corporate/support/sponsorship_discount_forms.html
index bd473d79d11..e7e6150ba1f 100644
--- a/templates/corporate/support/sponsorship_discount_forms.html
+++ b/templates/corporate/support/sponsorship_discount_forms.html
@@ -4,7 +4,7 @@
{{ csrf_input }}
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
<select name="required_plan_tier">
- {% for plan_tier in REMOTE_PLAN_TIERS %}
+ {% for plan_tier in PLAN_TYPES %}
{% if sponsorship_data.required_plan_tier == plan_tier.value %}
<option value="{{ plan_tier.value }}" selected>{{ plan_tier.name }}</option>
{% else %}
diff --git a/templates/corporate/support/sponsorship_forms_support.html b/templates/corporate/support/sponsorship_forms_support.html
index 41f78506c71..67da5e85303 100644
--- a/templates/corporate/support/sponsorship_forms_support.html
+++ b/templates/corporate/support/sponsorship_forms_support.html
@@ -20,7 +20,10 @@
</form>
{% endif %}
-{% include 'corporate/support/sponsorship_discount_forms.html' %}
+{% with %}
+ {% set PLAN_TYPES = REMOTE_PLAN_TIERS %}
+ {% include 'corporate/support/sponsorship_discount_forms.html' %}
+{% endwith %}
{% if sponsorship_data.sponsorship_pending %}
{% with %}