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.

apidocs: Migrate admin_config out of templates.

Suyash Vardhan Mathur1acee9f516ca
diff --git a/templates/zerver/api/create-custom-profile-field.md b/templates/zerver/api/create-custom-profile-field.md
index 07d9d59276a..3d7b2cf3a54 100644
--- a/templates/zerver/api/create-custom-profile-field.md
+++ b/templates/zerver/api/create-custom-profile-field.md
@@ -7,7 +7,7 @@
{start_tabs}
{tab|python}
-{generate_code_example(python)|/realm/profile_fields:post|example(admin_config=True)}
+{generate_code_example(python)|/realm/profile_fields:post|example}
{generate_code_example(javascript)|/realm/profile_fields:post|example}
diff --git a/templates/zerver/api/create-user.md b/templates/zerver/api/create-user.md
index 8b234adc6f8..efc43e0f155 100644
--- a/templates/zerver/api/create-user.md
+++ b/templates/zerver/api/create-user.md
@@ -7,9 +7,9 @@
{start_tabs}
{tab|python}
-{generate_code_example(python)|/users:post|example(admin_config=True)}
+{generate_code_example(python)|/users:post|example}
-{generate_code_example(javascript)|/users:post|example(admin_config=True)}
+{generate_code_example(javascript)|/users:post|example}
{tab|curl}
diff --git a/templates/zerver/api/delete-message.md b/templates/zerver/api/delete-message.md
index 3c5817e5d5a..ee1efea4675 100644
--- a/templates/zerver/api/delete-message.md
+++ b/templates/zerver/api/delete-message.md
@@ -9,7 +9,7 @@
{start_tabs}
{tab|python}
-{generate_code_example(python)|/messages/{message_id}:delete|example(admin_config=True)}
+{generate_code_example(python)|/messages/{message_id}:delete|example}
{generate_code_example(javascript)|/messages/{message_id}:delete|example}
diff --git a/templates/zerver/api/reorder-custom-profile-fields.md b/templates/zerver/api/reorder-custom-profile-fields.md
index 850d5e51beb..5732b3abf0b 100644
--- a/templates/zerver/api/reorder-custom-profile-fields.md
+++ b/templates/zerver/api/reorder-custom-profile-fields.md
@@ -7,7 +7,7 @@
{start_tabs}
{tab|python}
-{generate_code_example(python)|/realm/profile_fields:patch|example(admin_config=True)}
+{generate_code_example(python)|/realm/profile_fields:patch|example}
{generate_code_example(javascript)|/realm/profile_fields:patch|example}
diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py
index 4e82e22e763..2f85ae4c9aa 100644
--- a/zerver/openapi/markdown_extension.py
+++ b/zerver/openapi/markdown_extension.py
@@ -19,6 +19,7 @@ from markdown.preprocessors import Preprocessor
import zerver.openapi.python_examples
from zerver.openapi.openapi import (
+ check_requires_administrator,
generate_openapi_fixture,
get_openapi_description,
get_openapi_summary,
@@ -76,6 +77,7 @@ DEFAULT_EXAMPLE = {
"string": "demo",
"boolean": False,
}
+ADMIN_CONFIG_LANGUAGES = ["python", "javascript"]
def parse_language_and_options(input_str: Optional[str]) -> Tuple[str, Dict[str, Any]]:
@@ -426,7 +428,10 @@ class APICodeExamplesPreprocessor(Preprocessor):
if argument:
text = self.render_fixture(function, name=argument)
elif key == "example":
- if argument == "admin_config=True":
+ path, method = function.rsplit(":", 1)
+ if language in ADMIN_CONFIG_LANGUAGES and check_requires_administrator(
+ path, method
+ ):
text = SUPPORTED_LANGUAGES[language]["render"](
function, admin_config=True
)
@@ -525,6 +530,8 @@ class APITitlePreprocessor(Preprocessor):
raw_title = get_openapi_summary(path, method)
title.extend(raw_title.splitlines())
title = ["# " + line for line in title]
+ if check_requires_administrator(path, method):
+ title.append("{!api-admin-only.md!}")
return title
diff --git a/zerver/openapi/openapi.py b/zerver/openapi/openapi.py
index 6ae4b6822d5..f47c8f4b996 100644
--- a/zerver/openapi/openapi.py
+++ b/zerver/openapi/openapi.py
@@ -214,6 +214,13 @@ def get_openapi_fixture_description(endpoint: str, method: str, status_code: str
return get_schema(endpoint, method, status_code)["description"]
+def check_requires_administrator(endpoint: str, method: str) -> bool:
+ """Fetch if the endpoint requires admin config."""
+ return openapi_spec.openapi()["paths"][endpoint][method.lower()].get(
+ "x-requires-administrator", False
+ )
+
+
def generate_openapi_fixture(endpoint: str, method: str, status_code: str = "200") -> List[str]:
"""Generate fixture to be rendered"""
fixture = []
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index fa29ef6ac0a..2082e3f7944 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -5007,6 +5007,7 @@ paths:
This API corresponds to the
[delete a message completely][delete-completely] feature documented in
the Zulip Help Center.
+ x-requires-administrator: true
parameters:
- $ref: "#/components/parameters/MessageId"
responses:
@@ -5264,6 +5265,7 @@ paths:
Create a new user account via the API.
`POST {{ api_url }}/v1/users`
+ x-requires-administrator: true
parameters:
- name: email
in: query
@@ -5329,9 +5331,8 @@ paths:
operationId: reactivate_user
summary: Reactivate a user
tags: ["users"]
+ x-requires-administrator: true
description: |
- {!api-admin-only.md!}
-
[Reactivates a
user](https://zulip.com/help/deactivate-or-reactivate-a-user)
given their user ID.
@@ -6531,8 +6532,6 @@ paths:
summary: Reorder custom profile fields
tags: ["server_and_organizations"]
description: |
- {!api-admin-only.md!}
-
Reorder the custom profile fields in the user's organization.
`PATCH {{ api_url }}/v1/realm/profile_fields`
@@ -6542,6 +6541,7 @@ paths:
This endpoint is used to implement the dragging feature described in the
[custom profile fields documentation](/help/add-custom-profile-fields).
+ x-requires-administrator: true
parameters:
- name: order
in: query
@@ -6570,11 +6570,10 @@ paths:
summary: Create a custom profile field
tags: ["server_and_organizations"]
description: |
- {!api-admin-only.md!}
-
[Create a custom profile field](/help/add-custom-profile-fields) in the user's organization.
`POST {{ api_url }}/v1/realm/profile_fields`
+ x-requires-administrator: true
parameters:
- name: name
in: query
@@ -6960,9 +6959,8 @@ paths:
operationId: update_user
summary: Update a user
tags: ["users"]
+ x-requires-administrator: true
description: |
- {!api-admin-only.md!}
-
Administrative endpoint to update the details of another user in the organization.
`PATCH {{ api_url }}/v1/users/{user_id}`
@@ -7042,9 +7040,8 @@ paths:
operationId: deactivate_user
summary: Deactivate a user
tags: ["users"]
+ x-requires-administrator: true
description: |
- {!api-admin-only.md!}
-
[Deactivates a
user](https://zulip.com/help/deactivate-or-reactivate-a-user)
given their user ID.