mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +00:00
portico: Move portico view code to its own file.
This improves the readability of the codebase.
This commit is contained in:
@@ -505,3 +505,58 @@ class PlansPageTest(ZulipTestCase):
|
||||
result = self.client_get("/plans/", subdomain="zulip")
|
||||
self.assert_in_success_response([current_plan], result)
|
||||
self.assert_not_in_success_response([sign_up_now, buy_standard], result)
|
||||
|
||||
class AppsPageTest(ZulipTestCase):
|
||||
def test_apps_view(self) -> None:
|
||||
result = self.client_get('/apps')
|
||||
self.assertEqual(result.status_code, 301)
|
||||
self.assertTrue(result['Location'].endswith('/apps/'))
|
||||
|
||||
with self.settings(ZILENCER_ENABLED=False):
|
||||
result = self.client_get('/apps/')
|
||||
self.assertEqual(result.status_code, 301)
|
||||
self.assertTrue(result['Location'] == 'https://zulipchat.com/apps/')
|
||||
|
||||
with self.settings(ZILENCER_ENABLED=True):
|
||||
result = self.client_get('/apps/')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
html = result.content.decode('utf-8')
|
||||
self.assertIn('Apps for every platform.', html)
|
||||
|
||||
class PrivacyTermsTest(ZulipTestCase):
|
||||
def test_custom_tos_template(self) -> None:
|
||||
response = self.client_get("/terms/")
|
||||
|
||||
self.assert_in_success_response([u"Thanks for using our products and services (\"Services\"). ",
|
||||
u"By using our Services, you are agreeing to these terms"],
|
||||
response)
|
||||
|
||||
def test_custom_terms_of_service_template(self) -> None:
|
||||
not_configured_message = 'This installation of Zulip does not have a configured ' \
|
||||
'terms of service'
|
||||
with self.settings(TERMS_OF_SERVICE=None):
|
||||
response = self.client_get('/terms/')
|
||||
self.assert_in_success_response([not_configured_message], response)
|
||||
with self.settings(TERMS_OF_SERVICE='zerver/tests/markdown/test_markdown.md'):
|
||||
response = self.client_get('/terms/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
self.assert_not_in_success_response([not_configured_message], response)
|
||||
|
||||
def test_custom_privacy_policy_template(self) -> None:
|
||||
not_configured_message = 'This installation of Zulip does not have a configured ' \
|
||||
'privacy policy'
|
||||
with self.settings(PRIVACY_POLICY=None):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response([not_configured_message], response)
|
||||
with self.settings(PRIVACY_POLICY='zerver/tests/markdown/test_markdown.md'):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
self.assert_not_in_success_response([not_configured_message], response)
|
||||
|
||||
def test_custom_privacy_policy_template_with_absolute_url(self) -> None:
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
abs_path = os.path.join(current_dir, '..', '..',
|
||||
'templates/zerver/tests/markdown/test_markdown.md')
|
||||
with self.settings(PRIVACY_POLICY=abs_path):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
|
||||
@@ -719,22 +719,6 @@ class HomeTest(ZulipTestCase):
|
||||
path = urllib.parse.urlparse(result['Location']).path
|
||||
self.assertEqual(path, "/")
|
||||
|
||||
def test_apps_view(self) -> None:
|
||||
result = self.client_get('/apps')
|
||||
self.assertEqual(result.status_code, 301)
|
||||
self.assertTrue(result['Location'].endswith('/apps/'))
|
||||
|
||||
with self.settings(ZILENCER_ENABLED=False):
|
||||
result = self.client_get('/apps/')
|
||||
self.assertEqual(result.status_code, 301)
|
||||
self.assertTrue(result['Location'] == 'https://zulipchat.com/apps/')
|
||||
|
||||
with self.settings(ZILENCER_ENABLED=True):
|
||||
result = self.client_get('/apps/')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
html = result.content.decode('utf-8')
|
||||
self.assertIn('Apps for every platform.', html)
|
||||
|
||||
def test_compute_navbar_logo_url(self) -> None:
|
||||
user_profile = self.example_user("hamlet")
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Dict, Iterable
|
||||
import logging
|
||||
@@ -321,40 +320,3 @@ footer
|
||||
content_sans_whitespace = content.replace(" ", "").replace('\n', '')
|
||||
expected = 'headerfooter'
|
||||
self.assertEqual(content_sans_whitespace, expected)
|
||||
|
||||
def test_custom_tos_template(self) -> None:
|
||||
response = self.client_get("/terms/")
|
||||
|
||||
self.assert_in_success_response([u"Thanks for using our products and services (\"Services\"). ",
|
||||
u"By using our Services, you are agreeing to these terms"],
|
||||
response)
|
||||
|
||||
def test_custom_terms_of_service_template(self) -> None:
|
||||
not_configured_message = 'This installation of Zulip does not have a configured ' \
|
||||
'terms of service'
|
||||
with self.settings(TERMS_OF_SERVICE=None):
|
||||
response = self.client_get('/terms/')
|
||||
self.assert_in_success_response([not_configured_message], response)
|
||||
with self.settings(TERMS_OF_SERVICE='zerver/tests/markdown/test_markdown.md'):
|
||||
response = self.client_get('/terms/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
self.assert_not_in_success_response([not_configured_message], response)
|
||||
|
||||
def test_custom_privacy_policy_template(self) -> None:
|
||||
not_configured_message = 'This installation of Zulip does not have a configured ' \
|
||||
'privacy policy'
|
||||
with self.settings(PRIVACY_POLICY=None):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response([not_configured_message], response)
|
||||
with self.settings(PRIVACY_POLICY='zerver/tests/markdown/test_markdown.md'):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
self.assert_not_in_success_response([not_configured_message], response)
|
||||
|
||||
def test_custom_privacy_policy_template_with_absolute_url(self) -> None:
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
abs_path = os.path.join(current_dir, '..', '..',
|
||||
'templates/zerver/tests/markdown/test_markdown.md')
|
||||
with self.settings(PRIVACY_POLICY=abs_path):
|
||||
response = self.client_get('/privacy/')
|
||||
self.assert_in_success_response(['This is some <em>bold text</em>.'], response)
|
||||
|
||||
@@ -7,9 +7,8 @@ from django.shortcuts import redirect, render
|
||||
from django.utils import translation
|
||||
from django.utils.cache import patch_cache_control
|
||||
|
||||
from zerver.context_processors import get_realm_from_request, latest_info_context
|
||||
from zerver.decorator import zulip_login_required, \
|
||||
redirect_to_login
|
||||
from zerver.context_processors import latest_info_context
|
||||
from zerver.decorator import zulip_login_required
|
||||
from zerver.forms import ToSForm
|
||||
from zerver.models import Message, UserProfile, \
|
||||
Realm, UserMessage, \
|
||||
@@ -298,19 +297,3 @@ def home_real(request: HttpRequest) -> HttpResponse:
|
||||
@zulip_login_required
|
||||
def desktop_home(request: HttpRequest) -> HttpResponse:
|
||||
return HttpResponseRedirect(reverse('zerver.views.home.home'))
|
||||
|
||||
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)
|
||||
realm_plan_type = 0
|
||||
if realm is not None:
|
||||
realm_plan_type = realm.plan_type
|
||||
if realm.plan_type == Realm.SELF_HOSTED and settings.PRODUCTION:
|
||||
return HttpResponseRedirect('https://zulipchat.com/plans')
|
||||
if not request.user.is_authenticated:
|
||||
return redirect_to_login(next="plans")
|
||||
return render(request, "zerver/plans.html", context={"realm_plan_type": realm_plan_type})
|
||||
|
||||
41
zerver/views/portico.py
Normal file
41
zerver/views/portico.py
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
import ujson
|
||||
|
||||
from zerver.context_processors import get_realm_from_request
|
||||
from zerver.decorator import redirect_to_login
|
||||
from zerver.lib.storage import static_path
|
||||
from zerver.models import Realm
|
||||
|
||||
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)
|
||||
realm_plan_type = 0
|
||||
if realm is not None:
|
||||
realm_plan_type = realm.plan_type
|
||||
if realm.plan_type == Realm.SELF_HOSTED and settings.PRODUCTION:
|
||||
return HttpResponseRedirect('https://zulipchat.com/plans')
|
||||
if not request.user.is_authenticated:
|
||||
return redirect_to_login(next="plans")
|
||||
return render(request, "zerver/plans.html", context={"realm_plan_type": realm_plan_type})
|
||||
|
||||
def team_view(request: HttpRequest) -> HttpResponse:
|
||||
with open(static_path('generated/github-contributors.json')) as f:
|
||||
data = ujson.load(f)
|
||||
|
||||
return render(
|
||||
request,
|
||||
'zerver/team.html',
|
||||
context={
|
||||
'page_params': {
|
||||
'contrib': data['contrib'],
|
||||
},
|
||||
'date': data['date'],
|
||||
},
|
||||
)
|
||||
@@ -1,10 +1,9 @@
|
||||
from typing import Union, Optional, Dict, Any, List
|
||||
|
||||
import ujson
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.shortcuts import redirect, render
|
||||
from django.shortcuts import redirect
|
||||
from django.conf import settings
|
||||
|
||||
from zerver.decorator import require_realm_admin, require_member_or_admin
|
||||
@@ -23,7 +22,6 @@ from zerver.lib.exceptions import CannotDeactivateLastUserError
|
||||
from zerver.lib.integrations import EMBEDDED_BOTS
|
||||
from zerver.lib.request import has_request_variables, REQ
|
||||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.storage import static_path
|
||||
from zerver.lib.streams import access_stream_by_name
|
||||
from zerver.lib.upload import upload_avatar_image
|
||||
from zerver.lib.users import get_api_key
|
||||
@@ -492,18 +490,3 @@ def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> Http
|
||||
result['max_message_id'] = messages[0].id
|
||||
|
||||
return json_success(result)
|
||||
|
||||
def team_view(request: HttpRequest) -> HttpResponse:
|
||||
with open(static_path('generated/github-contributors.json')) as f:
|
||||
data = ujson.load(f)
|
||||
|
||||
return render(
|
||||
request,
|
||||
'zerver/team.html',
|
||||
context={
|
||||
'page_params': {
|
||||
'contrib': data['contrib'],
|
||||
},
|
||||
'date': data['date'],
|
||||
},
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@ import zerver.views.compatibility
|
||||
import zerver.views.home
|
||||
import zerver.views.email_mirror
|
||||
import zerver.views.registration
|
||||
import zerver.views.portico
|
||||
import zerver.views.zephyr
|
||||
import zerver.views.users
|
||||
import zerver.views.unsubscribe
|
||||
@@ -541,10 +542,10 @@ i18n_urls = [
|
||||
zerver.views.documentation.integration_doc,
|
||||
name="zerver.views.documentation.integration_doc"),
|
||||
url(r'^integrations/(.*)$', IntegrationView.as_view()),
|
||||
url(r'^team/$', zerver.views.users.team_view),
|
||||
url(r'^team/$', zerver.views.portico.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/$', zerver.views.home.plans_view, name='plans'),
|
||||
url(r'^apps/(.*)$', zerver.views.portico.apps_view, name='zerver.views.home.apps_view'),
|
||||
url(r'^plans/$', zerver.views.portico.plans_view, name='plans'),
|
||||
|
||||
# Landing page, features pages, signup form, etc.
|
||||
url(r'^hello/$', TemplateView.as_view(template_name='zerver/hello.html',
|
||||
|
||||
Reference in New Issue
Block a user