mirror of https://github.com/zulip/zulip.git
plans: Redirect to login if /plans is accessed from realm subdomain.
This commit is contained in:
parent
18b86a9499
commit
9489ce0efc
|
@ -15,6 +15,7 @@ from zerver.lib.test_classes import ZulipTestCase
|
|||
from zerver.lib.test_helpers import HostRequestMock
|
||||
from zerver.lib.test_runner import slow
|
||||
from zerver.lib.utils import split_by
|
||||
from zerver.models import Realm, get_realm
|
||||
from zerver.views.integrations import (
|
||||
add_api_uri_context,
|
||||
add_integrations_context,
|
||||
|
@ -104,7 +105,6 @@ class DocPageTest(ZulipTestCase):
|
|||
self._test('/for/companies/', 'in a company')
|
||||
self._test('/for/working-groups-and-communities/', 'standards bodies')
|
||||
self._test('/for/mystery-hunt/', 'four SIPB alums')
|
||||
self._test('/plans/', 'Community support')
|
||||
self._test('/devlogin/', 'Normal users', landing_page=False)
|
||||
self._test('/devtools/', 'Useful development URLs')
|
||||
self._test('/errors/404/', 'Page not found')
|
||||
|
@ -304,3 +304,28 @@ class ConfigErrorTest(ZulipTestCase):
|
|||
result = self.client_get("/config-error/dev")
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_in_success_response(["DevAuthBackend"], result)
|
||||
|
||||
class PlansPageTest(ZulipTestCase):
|
||||
def test_plans_auth(self) -> None:
|
||||
# Test root domain
|
||||
result = self.client_get("/plans/", subdomain="")
|
||||
self.assert_in_success_response(["Sign up now"], result)
|
||||
# Test non-existant domain
|
||||
result = self.client_get("/plans/", subdomain="moo")
|
||||
self.assert_in_success_response(["does not exist"], result)
|
||||
# Test valid domain, no login
|
||||
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(["Sign up now"], result)
|
||||
# Test root domain, with login on different domain
|
||||
result = self.client_get("/plans/", subdomain="")
|
||||
# TODO: works in manual testing, but I suspect something is funny in
|
||||
# the test environment
|
||||
# self.assert_in_success_response(["Sign up now"], result)
|
||||
|
|
|
@ -8,7 +8,9 @@ from django.utils import translation
|
|||
from django.utils.cache import patch_cache_control
|
||||
from itertools import zip_longest
|
||||
|
||||
from zerver.decorator import zulip_login_required, process_client
|
||||
from zerver.context_processors import get_realm_from_request
|
||||
from zerver.decorator import zulip_login_required, process_client, \
|
||||
redirect_to_login
|
||||
from zerver.forms import ToSForm
|
||||
from zerver.lib.realm_icon import realm_icon_url
|
||||
from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
|
||||
|
@ -288,3 +290,10 @@ def apps_view(request: HttpRequest, _: str) -> HttpResponse:
|
|||
if settings.ZILENCER_ENABLED:
|
||||
return render(request, 'zerver/apps.html')
|
||||
return HttpResponseRedirect('https://zulipchat.com/apps/', status=301)
|
||||
|
||||
def plans_view(request: HttpRequest) -> HttpResponse:
|
||||
realm = get_realm_from_request(request)
|
||||
if realm is not None:
|
||||
if not request.user.is_authenticated():
|
||||
return redirect_to_login(next="plans")
|
||||
return render(request, "zerver/plans.html")
|
||||
|
|
|
@ -486,7 +486,7 @@ i18n_urls = [
|
|||
url(r'^team/$', zerver.views.users.team_view),
|
||||
url(r'^history/$', TemplateView.as_view(template_name='zerver/history.html')),
|
||||
url(r'^apps/(.*)', zerver.views.home.apps_view, name='zerver.views.home.apps_view'),
|
||||
url(r'^plans/$', TemplateView.as_view(template_name='zerver/plans.html'), name='plans'),
|
||||
url(r'^plans/$', zerver.views.home.plans_view, name='plans'),
|
||||
|
||||
# Landing page, features pages, signup form, etc.
|
||||
url(r'^hello/$', TemplateView.as_view(template_name='zerver/hello.html'), name='landing-page'),
|
||||
|
|
Loading…
Reference in New Issue