Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api-docs: Return 404 for direct `/api-doc-template` call.
Lauryn Menard2a1ceb58d926
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.pyindex a380ea413b4..86bdfc5e13e 100644--- a/zerver/tests/test_docs.py+++ b/zerver/tests/test_docs.py@@ -137,6 +137,14 @@ class DocPageTest(ZulipTestCase):)self.assertEqual(result.status_code, 404)+ result = self.client_get(+ # This template shouldn't be accessed directly.+ "/api/api-doc-template",+ follow=True,+ HTTP_X_REQUESTED_WITH="XMLHttpRequest",+ )+ self.assertEqual(result.status_code, 404)+# Test some API doc endpoints for specific content and metadata.self._test("/api/", "The Zulip API")self._test("/api/api-keys", "be careful with it")diff --git a/zerver/views/documentation.py b/zerver/views/documentation.pyindex 6c4641a000d..a121134d24f 100644--- a/zerver/views/documentation.py+++ b/zerver/views/documentation.py@@ -110,6 +110,15 @@ class MarkdownDirectoryView(ApiURLView):endpoint_method=None,)+ if path == "/zerver/api/api-doc-template.md":+ # This template shouldn't be accessed directly.+ return DocumentationArticle(+ article_path=self.path_template % ("missing",),+ article_http_status=404,+ endpoint_path=None,+ endpoint_method=None,+ )+# The following is a somewhat hacky approach to extract titles from articles.# Hack: `context["article"] has a leading `/`, so we use + to add directories.article_path = os.path.join(settings.DEPLOY_ROOT, "templates") + path