diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 4be2200565..45a7575d2e 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -1487,3 +1487,30 @@ class HomeTest(ZulipTestCase): page_params["state_data"]["realm_push_notifications_enabled_end_timestamp"], datetime_to_timestamp(end_timestamp), ) + + +class TestDocRedirectView(ZulipTestCase): + def test_doc_permalink_view(self) -> None: + result = self.client_get("/doc-permalinks/usage-statistics") + self.assertEqual(result.status_code, 302) + self.assertEqual( + result["Location"], + "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#uploading-usage-statistics", + ) + + result = self.client_get("/doc-permalinks/basic-metadata") + self.assertEqual(result.status_code, 302) + self.assertEqual( + result["Location"], + "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#uploading-basic-metadata", + ) + + result = self.client_get("/doc-permalinks/why-service") + self.assertEqual(result.status_code, 302) + self.assertEqual( + result["Location"], + "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#why-a-push-notification-service-is-necessary", + ) + + result = self.client_get("/doc-permalinks/invalid-doc-id") + self.assertEqual(result.status_code, 404) diff --git a/zerver/views/home.py b/zerver/views/home.py index ffafb969f0..795e7e76a0 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -2,7 +2,7 @@ import logging import secrets from django.conf import settings -from django.http import HttpRequest, HttpResponse +from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse from django.utils.cache import patch_cache_control @@ -266,3 +266,17 @@ def home_real(request: HttpRequest) -> HttpResponse: @zulip_login_required def desktop_home(request: HttpRequest) -> HttpResponse: return redirect(home) + + +def doc_permalinks_view(request: HttpRequest, doc_id: str) -> HttpResponse: + DOC_PERMALINK_MAP: dict[str, str] = { + "usage-statistics": "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#uploading-usage-statistics", + "basic-metadata": "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#uploading-basic-metadata", + "why-service": "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#why-a-push-notification-service-is-necessary", + } + + redirect_url = DOC_PERMALINK_MAP.get(doc_id) + if redirect_url is None: + return render(request, "404.html", status=404) + + return HttpResponseRedirect(redirect_url) diff --git a/zproject/urls.py b/zproject/urls.py index 5523c041a8..a9d1b08c41 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -60,7 +60,7 @@ from zerver.views.drafts import create_drafts, delete_draft, edit_draft, fetch_d from zerver.views.email_mirror import email_mirror_message from zerver.views.events_register import events_register_backend from zerver.views.health import health -from zerver.views.home import accounts_accept_terms, desktop_home, home +from zerver.views.home import accounts_accept_terms, desktop_home, doc_permalinks_view, home from zerver.views.invite import ( generate_multiuse_invite_backend, get_user_invites, @@ -851,6 +851,7 @@ urls += [ path("api/", api_documentation_view), path("policies/", policy_documentation_view), path("policies/", policy_documentation_view), + path("doc-permalinks/", doc_permalinks_view), ] urls += [