Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Mateusz Manderaa6f1916ab162
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 4be22005656..45a7575d2ec 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 ffafb969f02..795e7e76a0a 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 5523c041a85..a9d1b08c41a 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/<slug:article>", api_documentation_view),
path("policies/", policy_documentation_view),
path("policies/<slug:article>", policy_documentation_view),
+ path("doc-permalinks/<str:doc_id>", doc_permalinks_view),
]
urls += [