apps: Redirect /apps -> zulipchat.com/apps, except on upstream itself.

This page describes software the user will get from upstream for
their own devices, independent of what's on the server they're
using.  So it should live in a place maintained together with
that other software, rather than be distributed and versioned
with the server.

The use of ZILENCER_ENABLED to tell the difference is rather a hack
but is currently how we do this in the small handful of similar
spots; see #5245.

Fixes #5234.
This commit is contained in:
Greg Price 2017-06-05 18:01:56 -07:00 committed by Tim Abbott
parent c78bfc356f
commit 04b363f3a2
3 changed files with 24 additions and 1 deletions

View File

@ -395,6 +395,23 @@ class HomeTest(ZulipTestCase):
path = urllib.parse.urlparse(result['Location']).path path = urllib.parse.urlparse(result['Location']).path
self.assertEqual(path, "/") self.assertEqual(path, "/")
def test_apps_view(self):
# type: () -> 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('Appsolutely', html)
def test_generate_204(self): def test_generate_204(self):
# type: () -> None # type: () -> None
email = self.example_email("hamlet") email = self.example_email("hamlet")

View File

@ -265,6 +265,12 @@ def desktop_home(request):
# type: (HttpRequest) -> HttpResponse # type: (HttpRequest) -> HttpResponse
return HttpResponseRedirect(reverse('zerver.views.home.home')) return HttpResponseRedirect(reverse('zerver.views.home.home'))
def apps_view(request):
# type: (HttpRequest) -> HttpResponse
if settings.ZILENCER_ENABLED:
return render(request, 'zerver/apps.html')
return HttpResponseRedirect('https://zulipchat.com/apps/', status=301)
def is_buggy_ua(agent): def is_buggy_ua(agent):
# type: (str) -> bool # type: (str) -> bool
"""Discrimiate CSS served to clients based on User Agent """Discrimiate CSS served to clients based on User Agent

View File

@ -141,7 +141,7 @@ i18n_urls = [
url(r'^api/endpoints/$', zerver.views.integrations.api_endpoint_docs, name='zerver.views.integrations.api_endpoint_docs'), url(r'^api/endpoints/$', zerver.views.integrations.api_endpoint_docs, name='zerver.views.integrations.api_endpoint_docs'),
url(r'^integrations/$', IntegrationView.as_view()), url(r'^integrations/$', IntegrationView.as_view()),
url(r'^about/$', TemplateView.as_view(template_name='zerver/about.html')), url(r'^about/$', TemplateView.as_view(template_name='zerver/about.html')),
url(r'^apps/$', TemplateView.as_view(template_name='zerver/apps.html')), url(r'^apps/$', zerver.views.home.apps_view, name='zerver.views.home.apps_view'),
url(r'^robots\.txt$', RedirectView.as_view(url='/static/robots.txt', permanent=True)), url(r'^robots\.txt$', RedirectView.as_view(url='/static/robots.txt', permanent=True)),