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: Implement setting a current plan end date for Cloud support.

Lauryn Menard89b5e850b2bc
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 45abe4ee82b..3ab45d46297 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1612,7 +1612,9 @@ class BillingSession(ABC):
"property": "next_invoice_date",
}
plan.next_invoice_date = new_end_date
- # Currently, we send a reminder email 2 months before the end date.
+ # We send a reminder email 2 months before the end date of
+ # remote server and remote realm fixed-price plans so that
+ # billing support can follow-up about continuing service.
# Reset it when we are extending the end_date.
reminder_to_review_plan_email_sent_changed_extra_data = None
if (
@@ -1659,9 +1661,7 @@ class BillingSession(ABC):
)
return f"Current plan for {self.billing_entity_display_name} updated to end on {end_date_string}."
- raise SupportRequestError(
- f"No current plan for {self.billing_entity_display_name}."
- ) # nocoverage
+ raise SupportRequestError(f"No current plan for {self.billing_entity_display_name}.")
def generate_stripe_invoice(
self,
diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py
index 6ce6ce34bbf..9891680d270 100644
--- a/corporate/tests/test_support_views.py
+++ b/corporate/tests/test_support_views.py
@@ -1513,6 +1513,62 @@ class TestSupportEndpoint(ZulipTestCase):
)
self.assert_length(messages, 1)
+ def test_update_current_plan_end_date(self) -> None:
+ lear_realm = get_realm("lear")
+ customer = get_customer_by_realm(lear_realm)
+ assert customer is None
+
+ iago = self.example_user("iago")
+ self.login_user(iago)
+
+ result = self.client_post(
+ "/activity/support",
+ {
+ "realm_id": f"{lear_realm.id}",
+ "plan_end_date": "2020-01-01",
+ },
+ )
+ self.assert_in_success_response(
+ ["Cannot update current plan for lear to end on 2020-01-01."],
+ result,
+ )
+
+ result = self.client_post(
+ "/activity/support",
+ {
+ "realm_id": f"{lear_realm.id}",
+ "plan_end_date": "2050-03-01",
+ },
+ )
+ self.assert_in_success_response(
+ ["No current plan for lear."],
+ result,
+ )
+
+ customer = self.create_customer_and_plan(lear_realm, True)
+ assert customer is not None
+ current_plan = get_current_plan_by_customer(customer)
+ assert current_plan is not None
+ self.assertIsNone(current_plan.end_date)
+ next_invoice_date = current_plan.next_invoice_date
+ assert next_invoice_date is not None
+
+ result = self.client_post(
+ "/activity/support",
+ {
+ "realm_id": f"{lear_realm.id}",
+ "plan_end_date": "2050-03-01",
+ },
+ )
+ self.assert_in_success_response(
+ ["Current plan for lear updated to end on 2050-03-01."],
+ result,
+ )
+
+ current_plan.refresh_from_db()
+ self.assertEqual(current_plan.end_date, datetime(2050, 3, 1, tzinfo=timezone.utc))
+ self.assertEqual(current_plan.next_invoice_date, next_invoice_date)
+
def test_approve_sponsorship_deactivated_realm(self) -> None:
support_admin = self.example_user("iago")
with self.settings(BILLING_ENABLED=True):
diff --git a/corporate/views/support.py b/corporate/views/support.py
index 3b737910c06..c2c1ceeb242 100644
--- a/corporate/views/support.py
+++ b/corporate/views/support.py
@@ -419,6 +419,8 @@ def support(
query: Annotated[str | None, ApiParamConfig("q")] = None,
org_type: Json[NonNegativeInt] | None = None,
max_invites: Json[NonNegativeInt] | None = None,
+ plan_end_date: Annotated[str, AfterValidator(lambda x: check_date("plan_end_date", x))]
+ | None = None,
) -> HttpResponse:
from corporate.lib.stripe import (
RealmBillingSession,
@@ -482,6 +484,11 @@ def support(
)
if modify_plan == "upgrade_plan_tier":
support_view_request["new_plan_tier"] = CustomerPlan.TIER_CLOUD_PLUS
+ elif plan_end_date is not None:
+ support_view_request = SupportViewRequest(
+ support_type=SupportType.update_plan_end_date,
+ plan_end_date=plan_end_date,
+ )
elif plan_type is not None:
current_plan_type = realm.plan_type
do_change_realm_plan_type(realm, plan_type, acting_user=acting_user)
diff --git a/templates/corporate/support/current_plan_forms_support.html b/templates/corporate/support/current_plan_forms_support.html
index 353f2ddf04f..12732f89b68 100644
--- a/templates/corporate/support/current_plan_forms_support.html
+++ b/templates/corporate/support/current_plan_forms_support.html
@@ -9,7 +9,7 @@
<button type="submit" class="support-submit-button">Update</button>
</form>
-{% if current_plan.status == current_plan.ACTIVE and remote_support_view %}
+{% if current_plan.status == current_plan.ACTIVE %}
<form method="POST" class="support-form">
<b>Plan end date</b><br />
{{ csrf_input }}