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.

plans: Mention whether realm is on free trial.

Vishnu KS5da3a69505a8
diff --git a/templates/zerver/plans.html b/templates/zerver/plans.html
index a5cc5616581..a668d541fad 100644
--- a/templates/zerver/plans.html
+++ b/templates/zerver/plans.html
@@ -91,7 +91,11 @@
</a>
{% elif realm.plan_type in [realm.STANDARD, realm.STANDARD_FREE] %}
<a href='/billing' class="button black-current-value" type="button">
+ {% if realm_on_free_trial %}
+ Current plan (free trial)
+ {% else %}
Current plan
+ {% endif %}
</a>
{% elif sponsorship_pending %}
<a href="/billing" class="button black-current-value" type="button">
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py
index 366310cce6a..c281c898514 100644
--- a/zerver/tests/test_docs.py
+++ b/zerver/tests/test_docs.py
@@ -8,8 +8,9 @@ import orjson
from django.conf import settings
from django.http import HttpResponse
from django.test import override_settings
+from django.utils.timezone import now as timezone_now
-from corporate.models import Customer
+from corporate.models import Customer, CustomerPlan
from zerver.lib.integrations import INTEGRATIONS
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import HostRequestMock
@@ -456,6 +457,13 @@ class PlansPageTest(ZulipTestCase):
self.assert_in_success_response([current_plan, buy_standard], result)
self.assert_not_in_success_response([sign_up_now, sponsorship_pending], result)
+ with self.settings(FREE_TRIAL_DAYS=60):
+ result = self.client_get("/plans/", subdomain="zulip")
+ self.assert_in_success_response([current_plan, "Start 60 day free trial"], result)
+ self.assert_not_in_success_response(
+ [sign_up_now, sponsorship_pending, buy_standard], result
+ )
+
realm.plan_type = Realm.STANDARD_FREE
realm.save(update_fields=["plan_type"])
result = self.client_get("/plans/", subdomain="zulip")
@@ -472,11 +480,25 @@ class PlansPageTest(ZulipTestCase):
[sign_up_now, buy_standard, sponsorship_pending], result
)
+ customer = Customer.objects.create(realm=get_realm("zulip"), stripe_customer_id="cus_id")
+ plan = CustomerPlan.objects.create(
+ customer=customer,
+ tier=CustomerPlan.STANDARD,
+ status=CustomerPlan.FREE_TRIAL,
+ billing_cycle_anchor=timezone_now(),
+ billing_schedule=CustomerPlan.MONTHLY,
+ )
+ result = self.client_get("/plans/", subdomain="zulip")
+ self.assert_in_success_response(["Current plan (free trial)"], result)
+ self.assert_not_in_success_response(
+ [sign_up_now, buy_standard, sponsorship_pending], result
+ )
+
realm.plan_type = Realm.LIMITED
realm.save()
- Customer.objects.create(
- realm=get_realm("zulip"), stripe_customer_id="cus_id", sponsorship_pending=True
- )
+ customer.sponsorship_pending = True
+ customer.save()
+ plan.delete()
result = self.client_get("/plans/", subdomain="zulip")
self.assert_in_success_response([current_plan], result)
self.assert_in_success_response([current_plan, sponsorship_pending], result)
diff --git a/zerver/views/portico.py b/zerver/views/portico.py
index 611d704db36..8302e11960a 100644
--- a/zerver/views/portico.py
+++ b/zerver/views/portico.py
@@ -41,6 +41,7 @@ def plans_view(request: HttpRequest) -> HttpResponse:
if is_subdomain_root_or_alias(request):
# If we're on the root domain, we make this link first ask you which organization.
sponsorship_url = f"/accounts/go/?next={urllib.parse.quote(sponsorship_url)}"
+ realm_on_free_trial = False
if realm is not None:
if realm.plan_type == Realm.SELF_HOSTED and settings.PRODUCTION:
@@ -50,11 +51,13 @@ def plans_view(request: HttpRequest) -> HttpResponse:
if request.user.is_guest:
return TemplateResponse(request, "404.html", status=404)
if settings.CORPORATE_ENABLED:
+ from corporate.lib.stripe import is_realm_on_free_trial
from corporate.models import get_customer_by_realm
customer = get_customer_by_realm(realm)
if customer is not None:
sponsorship_pending = customer.sponsorship_pending
+ realm_on_free_trial = is_realm_on_free_trial(realm)
return TemplateResponse(
request,
@@ -62,6 +65,7 @@ def plans_view(request: HttpRequest) -> HttpResponse:
context={
"realm": realm,
"free_trial_days": free_trial_days,
+ "realm_on_free_trial": realm_on_free_trial,
"sponsorship_pending": sponsorship_pending,
"sponsorship_url": sponsorship_url,
},