docs: Add endpoint for permalinks to some push notifs docs.

This will gives us the flexibility to edit our documentation, including
section names, without worrying about breaking links to docs hard-coded
in older releases / deployed self-hosted servers.
This commit is contained in:
Mateusz Mandera
2025-02-13 01:07:40 +08:00
committed by Tim Abbott
parent 8f7c968408
commit a6f1916ab1
3 changed files with 44 additions and 2 deletions

View File

@@ -1487,3 +1487,30 @@ class HomeTest(ZulipTestCase):
page_params["state_data"]["realm_push_notifications_enabled_end_timestamp"], page_params["state_data"]["realm_push_notifications_enabled_end_timestamp"],
datetime_to_timestamp(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)

View File

@@ -2,7 +2,7 @@ import logging
import secrets import secrets
from django.conf import settings 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.shortcuts import redirect, render
from django.urls import reverse from django.urls import reverse
from django.utils.cache import patch_cache_control from django.utils.cache import patch_cache_control
@@ -266,3 +266,17 @@ def home_real(request: HttpRequest) -> HttpResponse:
@zulip_login_required @zulip_login_required
def desktop_home(request: HttpRequest) -> HttpResponse: def desktop_home(request: HttpRequest) -> HttpResponse:
return redirect(home) 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)

View File

@@ -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.email_mirror import email_mirror_message
from zerver.views.events_register import events_register_backend from zerver.views.events_register import events_register_backend
from zerver.views.health import health 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 ( from zerver.views.invite import (
generate_multiuse_invite_backend, generate_multiuse_invite_backend,
get_user_invites, get_user_invites,
@@ -851,6 +851,7 @@ urls += [
path("api/<slug:article>", api_documentation_view), path("api/<slug:article>", api_documentation_view),
path("policies/", policy_documentation_view), path("policies/", policy_documentation_view),
path("policies/<slug:article>", policy_documentation_view), path("policies/<slug:article>", policy_documentation_view),
path("doc-permalinks/<str:doc_id>", doc_permalinks_view),
] ]
urls += [ urls += [