billing: Hide /plans if Realm.plan_type=SELF_HOSTED.

This commit is contained in:
Rishi Gupta 2018-08-27 16:32:52 -07:00
parent c913eafdf4
commit 2a0523cbe5
2 changed files with 17 additions and 4 deletions

View File

@ -314,14 +314,14 @@ class PlansPageTest(ZulipTestCase):
result = self.client_get("/plans/", subdomain="moo")
self.assert_in_success_response(["does not exist"], result)
# Test valid domain, no login
realm = get_realm("zulip")
realm.plan_type = Realm.PREMIUM_FREE
realm.save(update_fields=["plan_type"])
result = self.client_get("/plans/", subdomain="zulip")
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], "/accounts/login?next=plans")
# Test valid domain, with login
self.login(self.example_email('hamlet'))
realm = get_realm("zulip")
realm.plan_type = Realm.PREMIUM_FREE
realm.save(update_fields=["plan_type"])
result = self.client_get("/plans/", subdomain="zulip")
self.assert_in_success_response(["Current plan"], result)
# Test root domain, with login on different domain
@ -340,8 +340,19 @@ class PlansPageTest(ZulipTestCase):
self.assert_in_success_response([sign_up_now, buy_premium], result)
self.assert_not_in_success_response([current_plan], result)
self.login(self.example_email("iago"))
realm = get_realm("zulip")
realm.plan_type = Realm.SELF_HOSTED
realm.save(update_fields=["plan_type"])
result = self.client_get("/plans/", subdomain="zulip")
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], "/")
self.login(self.example_email("iago"))
# SELF_HOSTED should hide plans, even if logged in
result = self.client_get("/plans/", subdomain="zulip")
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], "/")
realm.plan_type = Realm.LIMITED
realm.save(update_fields=["plan_type"])

View File

@ -294,6 +294,8 @@ def apps_view(request: HttpRequest, _: str) -> HttpResponse:
def plans_view(request: HttpRequest) -> HttpResponse:
realm = get_realm_from_request(request)
if realm is not None:
if realm.plan_type == Realm.SELF_HOSTED:
return HttpResponseRedirect(reverse('zerver.views.home.home'))
if not request.user.is_authenticated():
return redirect_to_login(next="plans")
return render(request, "zerver/plans.html")