diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index bcd2a73df8..e0e14ea08b 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -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"]) diff --git a/zerver/views/home.py b/zerver/views/home.py index 6e472d01cd..5e39d5302b 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -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")