Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
sponsorship: Populate sponsorship page with correct context.
Aman Agrawal49908ba166ba
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex f90dcbb0841..5e169f36092 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -2162,8 +2162,28 @@ class BillingSession(ABC):raise JsonableError(_("Pass stripe_session_id or stripe_payment_intent_id"))def get_sponsorship_request_context(self) -> Optional[Dict[str, Any]]:- context: Dict[str, Any] = {}customer = self.get_customer()+ is_remotely_hosted = isinstance(+ self, (RemoteRealmBillingSession, RemoteServerBillingSession)+ )++ # We only support sponsorships for these plans.+ sponsored_plan_name = CustomerPlan.name_from_tier(CustomerPlan.TIER_CLOUD_STANDARD)+ if is_remotely_hosted:+ sponsored_plan_name = CustomerPlan.name_from_tier(+ CustomerPlan.TIER_SELF_HOSTED_COMMUNITY+ )++ plan_name = "Zulip Cloud Free"+ if is_remotely_hosted:+ plan_name = "Self-managed"++ context: Dict[str, Any] = {+ "billing_base_url": self.billing_base_url,+ "is_remotely_hosted": is_remotely_hosted,+ "sponsored_plan_name": sponsored_plan_name,+ "plan_name": plan_name,+ }if customer is not None and customer.sponsorship_pending:if self.on_paid_plan():@@ -2173,18 +2193,13 @@ class BillingSession(ABC):if self.is_sponsored():context["is_sponsored"] = True+ context["plan_name"] = sponsored_plan_nameif customer is not None:plan = get_current_plan_by_customer(customer)if plan is not None:context["plan_name"] = plan.namecontext["free_trial"] = plan.is_free_trial()- elif self.is_sponsored():- # We don't create CustomerPlan objects for fully sponsored realms via support page.- context["plan_name"] = "Zulip Cloud Standard"- else:- # TODO: Don't hardcode this plan name.- context["plan_name"] = "Zulip Cloud Free"self.add_sponsorship_info_to_context(context)return context@@ -2637,6 +2652,7 @@ class RealmBillingSession(BillingSession):key=sponsorship_org_type_key_helper,),)+ context["org_name"] = self.realm.name@overridedef get_sponsorship_request_session_specific_context(@@ -2924,6 +2940,7 @@ class RemoteRealmBillingSession(BillingSession): # nocoveragekey=sponsorship_org_type_key_helper,),)+ context["org_name"] = self.remote_realm.host@overridedef get_sponsorship_request_session_specific_context(@@ -3224,6 +3241,7 @@ class RemoteServerBillingSession(BillingSession): # nocoveragekey=sponsorship_org_type_key_helper,),)+ context["org_name"] = self.remote_server.hostname@overridedef get_sponsorship_request_session_specific_context(diff --git a/corporate/models.py b/corporate/models.pyindex 49ac8c512b4..7a11f0cc56d 100644--- a/corporate/models.py+++ b/corporate/models.py@@ -299,6 +299,7 @@ class CustomerPlan(models.Model):CustomerPlan.TIER_CLOUD_ENTERPRISE: "Zulip Enterprise",CustomerPlan.TIER_SELF_HOSTED_LEGACY: "Self-managed",CustomerPlan.TIER_SELF_HOSTED_BUSINESS: "Zulip Business",+ CustomerPlan.TIER_SELF_HOSTED_COMMUNITY: "Community",}[tier]@propertydiff --git a/corporate/urls.py b/corporate/urls.pyindex 85101e58bc4..9edf1826340 100644--- a/corporate/urls.py+++ b/corporate/urls.py@@ -233,8 +233,8 @@ urlpatterns += [name="remote_server_event_status_page",),# Remote variants of above API endpoints.- path("json/realm/<realm_uuid>/sponsorship", remote_realm_sponsorship),- path("json/server/<server_uuid>/sponsorship", remote_server_sponsorship),+ path("json/realm/<realm_uuid>/billing/sponsorship", remote_realm_sponsorship),+ path("json/server/<server_uuid>/billing/sponsorship", remote_server_sponsorship),path("json/realm/<realm_uuid>/billing/session/start_card_update_session",start_card_update_stripe_session_for_remote_realm,diff --git a/corporate/views/sponsorship.py b/corporate/views/sponsorship.pyindex 5b331f78f55..ca91d8d0196 100644--- a/corporate/views/sponsorship.py+++ b/corporate/views/sponsorship.py@@ -37,7 +37,9 @@ def remote_realm_sponsorship_page() -> HttpResponse: # nocoveragecontext = billing_session.get_sponsorship_request_context()if context is None:- return HttpResponseRedirect(reverse("remote_realm_billing_page"))+ return HttpResponseRedirect(+ reverse("remote_realm_billing_page", args=(billing_session.remote_realm.uuid,))+ )return render(request, "corporate/sponsorship.html", context=context)@@ -49,7 +51,9 @@ def remote_server_sponsorship_page() -> HttpResponse: # nocoveragecontext = billing_session.get_sponsorship_request_context()if context is None:- return HttpResponseRedirect(reverse("remote_server_billing_page"))+ return HttpResponseRedirect(+ reverse("remote_server_billing_page", args=(billing_session.remote_server.uuid,))+ )return render(request, "corporate/sponsorship.html", context=context)diff --git a/templates/corporate/sponsorship.html b/templates/corporate/sponsorship.htmlindex 29d1cc82abb..864c7073c5e 100644--- a/templates/corporate/sponsorship.html+++ b/templates/corporate/sponsorship.html@@ -11,13 +11,20 @@<div class="center-block new-style"><div class="alert alert-success sponsorship-page-success" id="sponsorship-status-success-message-top">{% if is_sponsored %}- Zulip is sponsoring a free <a href="/plans/">Zulip Cloud Standard</a> plan for this organization. 🎉+ Zulip is sponsoring a free <a href="{{ billing_base_url }}/plans/">{{ sponsored_plan_name }}</a> plan for this organization. 🎉{% else %}- This organization has requested sponsorship for a <a href="/plans/">Zulip Cloud Standard</a> plan. <a href="mailto:[email protected]">Contact Zulip support</a> with any questions or updates.+ This organization has requested sponsorship for a <a href="{{ billing_base_url }}/plans/">{{ sponsored_plan_name }}</a> plan. <a href="mailto:[email protected]">Contact Zulip support</a> with any questions or updates.{% endif %}</div><div class="pitch">- <h1>Zulip Cloud billing for {{realm_name}}</h1>+ <h1>+ Zulip+ {% if is_remotely_hosted %}+ {% else %}+ Cloud+ {% endif %}+ billing for {{ org_name }}+ </h1></div><div class="white-box"><div id="sponsorship-status-page-details">@@ -49,16 +56,22 @@<div class="register-account flex full-page sponsorship-page"><div class="center-block new-style"><div class="pitch">- <h1>Request Zulip Cloud sponsorship</h1>+ <h1>+ Request Zulip+ {% if is_remotely_hosted %}+ {% else %}+ Cloud+ {% endif %} sponsorship+ </h1></div><div class="white-box"><div id="sponsorship-error" class="alert alert-danger"></div><div id="sponsorship-input-section">- <form id="sponsorship-form" method="post">+ <form id="sponsorship-form" method="post" data-billing-base-url="{{ billing_base_url }}"><input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}" /><div class="input-box sponsorship-form-field no-validation"><label for="org-name" class="inline-block label-title">Organization</label>- <div id="org-name" class="not-editable-realm-field">{{ realm_name }}</div>+ <div id="org-name" class="not-editable-realm-field">{{ org_name }}</div></div><div class="input-box sponsorship-form-field"><div class="inline-block relative">diff --git a/web/src/billing/sponsorship.ts b/web/src/billing/sponsorship.tsindex c7f44174ffd..00ff7231b69 100644--- a/web/src/billing/sponsorship.ts+++ b/web/src/billing/sponsorship.ts@@ -53,10 +53,10 @@ function create_ajax_request(): void {return;}+ const billing_base_url = $form.attr("data-billing-base-url") ?? "";void $.ajax({type: "post",- // TODO: This needs to be conditional on billing session type- url: "/json/billing/sponsorship",+ url: `/json${billing_base_url}/billing/sponsorship`,data,success() {window.location.reload();