From 04b363f3a232454a83f2141038dd829d81d2a5af Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 5 Jun 2017 18:01:56 -0700 Subject: [PATCH] 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. --- zerver/tests/test_home.py | 17 +++++++++++++++++ zerver/views/home.py | 6 ++++++ zproject/urls.py | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 6a1b15955a..4dff28a0e7 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -395,6 +395,23 @@ class HomeTest(ZulipTestCase): path = urllib.parse.urlparse(result['Location']).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): # type: () -> None email = self.example_email("hamlet") diff --git a/zerver/views/home.py b/zerver/views/home.py index af5a125823..0f18310fda 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -265,6 +265,12 @@ def desktop_home(request): # type: (HttpRequest) -> HttpResponse 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): # type: (str) -> bool """Discrimiate CSS served to clients based on User Agent diff --git a/zproject/urls.py b/zproject/urls.py index 2e519b737c..6524798e02 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -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'^integrations/$', IntegrationView.as_view()), 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)),