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.

support: Update validation for adding or updating a discount.

Lauryn Menard787d64e327b8
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 9b1db6caa79..e554e49b1e3 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -124,8 +124,7 @@ def format_discount_percentage(discount: Optional[Decimal]) -> Optional[str]:
if type(discount) is not Decimal or discount == Decimal(0):
return None
- # Even though it looks like /activity/support only finds integers valid,
- # this will look good for any custom discounts that we apply.
+ # This will look good for any custom discounts that we apply.
if discount * 100 % 100 == 0:
precision = 0
else:
diff --git a/templates/analytics/realm_details.html b/templates/analytics/realm_details.html
index 636bc6c516c..2f6667b632e 100644
--- a/templates/analytics/realm_details.html
+++ b/templates/analytics/realm_details.html
@@ -101,10 +101,10 @@
{{ csrf_input }}
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
{% if plan_data[realm.id].current_plan and plan_data[realm.id].current_plan.fixed_price %}
- <input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" disabled />
+ <input type="number" name="discount" value="{{ format_discount(get_discount(plan_data[realm.id].customer)) }}" step="0.01" min="0" max="99.99" disabled />
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
{% else %}
- <input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" required />
+ <input type="number" name="discount" value="{{ format_discount(get_discount(plan_data[realm.id].customer)) }}" step="0.01" min="0" max="99.99" required />
<button type="submit" class="btn btn-default support-submit-button">Update</button>
{% endif %}
</form>
diff --git a/templates/analytics/remote_realm_details.html b/templates/analytics/remote_realm_details.html
index 84d65f78cb6..7b9b7476282 100644
--- a/templates/analytics/remote_realm_details.html
+++ b/templates/analytics/remote_realm_details.html
@@ -32,6 +32,7 @@
{% set sponsorship_data = support_data[remote_realm.id].sponsorship_data %}
{% set remote_id = remote_realm.id %}
{% set remote_type = "remote_realm_id" %}
+ {% set format_discount = format_discount %}
{% set has_fixed_price = support_data[remote_realm.id].plan_data.has_fixed_price %}
{% include 'analytics/sponsorship_forms_support.html' %}
{% endwith %}
diff --git a/templates/analytics/remote_server_support.html b/templates/analytics/remote_server_support.html
index be2232392a5..ab7542a9794 100644
--- a/templates/analytics/remote_server_support.html
+++ b/templates/analytics/remote_server_support.html
@@ -67,6 +67,7 @@
{% set sponsorship_data = remote_servers_support_data[remote_server.id].sponsorship_data %}
{% set remote_id = remote_server.id %}
{% set remote_type = "remote_server_id" %}
+ {% set format_discount = format_discount %}
{% set has_fixed_price = remote_servers_support_data[remote_server.id].plan_data.has_fixed_price %}
{% include 'analytics/sponsorship_forms_support.html' %}
{% endwith %}
diff --git a/templates/analytics/sponsorship_forms_support.html b/templates/analytics/sponsorship_forms_support.html
index ac9896c8e35..9f525cab037 100644
--- a/templates/analytics/sponsorship_forms_support.html
+++ b/templates/analytics/sponsorship_forms_support.html
@@ -25,10 +25,10 @@
{{ csrf_input }}
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
{% if has_fixed_price %}
- <input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" disabled />
+ <input type="number" name="discount" value="{{ format_discount(sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" disabled />
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
{% else %}
- <input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" required />
+ <input type="number" name="discount" value="{{ format_discount(sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" required />
<button type="submit" class="btn btn-default support-submit-button">Update</button>
{% endif %}
</form>