apps: Fix redirect from /apps -> https://zulip.com/apps/.

When this code was moved from being in zerver in 21a2fd482e, it kept
the `if ZILENCER_ENABLED` blocks.  Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.

However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.

The other side effect of this is that with e54ded49c4, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`.  Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.

Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
This commit is contained in:
Alex Vandiver
2022-12-16 09:17:00 -05:00
committed by Tim Abbott
parent 13ad9e8323
commit 7613928e8a
4 changed files with 48 additions and 25 deletions

View File

@@ -176,9 +176,8 @@ class DocPageTest(ZulipTestCase):
self._test("/errors/5xx/", "Internal server error", landing_page=False)
def test_corporate_portico_endpoints(self) -> None:
if settings.ZILENCER_ENABLED:
self._test("/team/", "industry veterans")
self._test("/apps/", "Apps for every platform.")
self._test("/team/", "industry veterans")
self._test("/apps/", "Apps for every platform.")
self._test("/history/", "Zulip released as open source!")
# Test the i18n version of one of these pages.
@@ -524,34 +523,42 @@ class PlansPageTest(ZulipTestCase):
class AppsPageTest(ZulipTestCase):
def test_get_apps_page_url(self) -> None:
with self.settings(ZILENCER_ENABLED=False):
with self.settings(CORPORATE_ENABLED=False):
apps_page_url = get_apps_page_url()
self.assertEqual(apps_page_url, "https://zulip.com/apps/")
with self.settings(ZILENCER_ENABLED=True):
with self.settings(CORPORATE_ENABLED=True):
apps_page_url = get_apps_page_url()
self.assertEqual(apps_page_url, "/apps/")
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(CORPORATE_ENABLED=False):
# Note that because this cannot actually uninstall the
# "corporate" app and trigger updates to URL resolution,
# this does not test the "apps/" path installed in
# zproject.urls, but rather the special-case for testing
# in corporate.views.portico
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://zulip.com/apps/")
self.assertEqual(result.status_code, 301)
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
with self.settings(ZILENCER_ENABLED=False):
result = self.client_get("/apps/linux")
self.assertEqual(result.status_code, 301)
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
self.assertEqual(result.status_code, 301)
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
with self.settings(CORPORATE_ENABLED=True):
result = self.client_get("/apps")
self.assertEqual(result.status_code, 301)
self.assertTrue(result["Location"].endswith("/apps/"))
with self.settings(ZILENCER_ENABLED=True):
result = self.client_get("/apps/")
self.assertEqual(result.status_code, 200)
html = result.content.decode()
self.assertIn("Apps for every platform.", html)
self.assertEqual(result.status_code, 200)
html = result.content.decode()
self.assertIn("Apps for every platform.", html)
def test_app_download_link_view(self) -> None:
return_value = "https://desktop-download.zulip.com/v5.4.3/Zulip-Web-Setup-5.4.3.exe"