From 5a7aa8228acf7f2495052815c3396502db30cc46 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Tue, 23 Aug 2022 11:57:47 +0200 Subject: [PATCH] urls: Extend documentation URL redirects system to corporate landing pages. Extends the URL redirect system used for documentation pages to corporate landing pages. This makes it easier and consistent for contributors who work on both areas to create new URL redirects when needed. --- corporate/urls.py | 17 +++++++---------- zerver/lib/test_helpers.py | 1 - zerver/lib/url_redirects.py | 8 ++++++++ zerver/tests/test_urls.py | 6 ++++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/corporate/urls.py b/corporate/urls.py index c0c81164b8..e95a1a2ed1 100644 --- a/corporate/urls.py +++ b/corporate/urls.py @@ -23,6 +23,7 @@ from corporate.views.support import support_request from corporate.views.upgrade import initial_upgrade, sponsorship, upgrade from corporate.views.webhook import stripe_webhook from zerver.lib.rest import rest_path +from zerver.lib.url_redirects import LANDING_PAGE_REDIRECTS i18n_urlpatterns: Any = [ # Zephyr/MIT @@ -52,15 +53,11 @@ v1_api_and_json_patterns = [ landing_page_urls = [ # Landing page, features pages, signup form, etc. path("hello/", hello_view), - path("new-user/", RedirectView.as_view(url="/hello", permanent=True)), path("features/", landing_view, {"template_name": "corporate/features.html"}), path("plans/", plans_view, name="plans"), path("apps/", apps_view), path("apps/download/", app_download_link_redirect), path("apps/", apps_view), - path( - "developer-community/", RedirectView.as_view(url="/development-community/", permanent=True) - ), path( "development-community/", landing_view, @@ -79,17 +76,11 @@ landing_page_urls = [ landing_view, {"template_name": "corporate/for/communities.html"}, ), - # We merged this into /for/communities. - path( - "for/working-groups-and-communities/", - RedirectView.as_view(url="/for/communities/", permanent=True), - ), path("for/education/", landing_view, {"template_name": "corporate/for/education.html"}), path("for/events/", landing_view, {"template_name": "corporate/for/events.html"}), path("for/open-source/", landing_view, {"template_name": "corporate/for/open-source.html"}), path("for/research/", landing_view, {"template_name": "corporate/for/research.html"}), path("for/business/", landing_view, {"template_name": "corporate/for/business.html"}), - path("for/companies/", RedirectView.as_view(url="/for/business/", permanent=True)), # case-studies path( "case-studies/idrift/", @@ -128,6 +119,12 @@ landing_page_urls = [ ), path("communities/", communities_view), ] + +# Redirects due to us having moved or combined landing pages: +for redirect in LANDING_PAGE_REDIRECTS: + old_url = redirect.old_url.lstrip("/") + landing_page_urls += [path(old_url, RedirectView.as_view(url=redirect.new_url, permanent=True))] + i18n_urlpatterns += landing_page_urls # Make a copy of i18n_urlpatterns so that they appear without prefix for English diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index fc4018296a..d82825f170 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -481,7 +481,6 @@ def write_instrumentation_reports(full_suite: bool, include_webhooks: bool) -> N "confirmation_key/", "node-coverage/(?P.+)", "docs/(?P.+)", - "for/working-groups-and-communities/", "casper/(?P.+)", "static/(?P.+)", "flush_caches", diff --git a/zerver/lib/url_redirects.py b/zerver/lib/url_redirects.py index f106b3ec62..0a67cc393f 100644 --- a/zerver/lib/url_redirects.py +++ b/zerver/lib/url_redirects.py @@ -51,6 +51,14 @@ HELP_DOCUMENTATION_REDIRECTS: List[URLRedirect] = [ URLRedirect("/help/web-public-streams", "/help/public-access-option"), ] +LANDING_PAGE_REDIRECTS = [ + # Add URL redirects for corporate landing pages here. + URLRedirect("/new-user/", "/hello"), + URLRedirect("/developer-community/", "/development-community"), + URLRedirect("/for/companies/", "/for/business"), + URLRedirect("/for/working-groups-and-communities/", "/for/communities"), +] + DOCUMENTATION_REDIRECTS = ( API_DOCUMENTATION_REDIRECTS + POLICY_DOCUMENTATION_REDIRECTS + HELP_DOCUMENTATION_REDIRECTS ) diff --git a/zerver/tests/test_urls.py b/zerver/tests/test_urls.py index 247ed6b6c8..fe5fa6c080 100644 --- a/zerver/tests/test_urls.py +++ b/zerver/tests/test_urls.py @@ -9,6 +9,7 @@ from zerver.lib.test_classes import ZulipTestCase from zerver.lib.url_redirects import ( API_DOCUMENTATION_REDIRECTS, HELP_DOCUMENTATION_REDIRECTS, + LANDING_PAGE_REDIRECTS, POLICY_DOCUMENTATION_REDIRECTS, ) from zerver.models import Realm, Stream @@ -176,3 +177,8 @@ class RedirectURLTest(ZulipTestCase): for redirect in POLICY_DOCUMENTATION_REDIRECTS: result = self.client_get(redirect.old_url, follow=True) self.assert_in_success_response(["Policies", "Archive"], result) + + def test_landing_page_redirects(self) -> None: + for redirect in LANDING_PAGE_REDIRECTS: + result = self.client_get(redirect.old_url, follow=True) + self.assert_in_success_response(["Download"], result)