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.

integrations: Rename WebhookUrlOption's validator to input_type.

Niloth Pae1fbd239d1d
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index c84d7ec4619..1a62d8f3b04 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 485**
+
+* [`POST /register`](/api/register-queue): Renamed the `validator` field
+ to `input_type` in the `url_options` array of the
+ `realm_incoming_webhook_bots` object array.
+
**Feature level 484**
* [`GET /events`](/api/get-events): Removed the deprecated `user` object
diff --git a/docs/webhooks/incoming-webhooks-reference.md b/docs/webhooks/incoming-webhooks-reference.md
index 48a3062b8f4..af9c21a1031 100644
--- a/docs/webhooks/incoming-webhooks-reference.md
+++ b/docs/webhooks/incoming-webhooks-reference.md
@@ -96,7 +96,7 @@ These URL options can be declared as follows:
WebhookUrlOption(
name='ignore_private_repositories',
label='Exclude notifications from private repositories',
- validator=check_string
+ input_type='checkbox',
),
],
)
@@ -109,15 +109,14 @@ offer when generating the integration URL:
integration's webhook URL.
- `label`: A short descriptive label for this URL parameter in the web
app UI.
-- `validator`: A validator function, which is used to determine the input
- type for this option in the UI, and to indicate how to validate the
- input. Currently, the web app UI only supports these validators:
- - `check_bool` for checkbox/select input.
- - `check_string` for text input.
-
-To add support for other validators, you can update
-`web/src/integration_url_modal.ts`. Common validators are available in
-`zerver/lib/validator.py`.
+- `input_type`: The type of input field this option maps to in the UI.
+ The web app UI currently supports the following input types:
+ - `checkbox`: A checkbox input for presence-only values (true or absent),
+ disabled by default.
+ - `text`: A text input for string values.
+
+To add support for other input types, you can update
+`web/src/integration_url_modal.ts`.
In rare cases, it may be necessary for an incoming webhook to require
additional user configuration beyond what is specified in the POST URL.
diff --git a/version.py b/version.py
index 0f1953571a5..093c6e36c87 100644
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# https://zulip.readthedocs.io/en/latest/documentation/api.html#step-by-step-guide
# Also available at docs/documentation/api.md.
-API_FEATURE_LEVEL = 484
+API_FEATURE_LEVEL = 485
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/web/src/integration_url_modal.ts b/web/src/integration_url_modal.ts
index 2f993076533..39878376192 100644
--- a/web/src/integration_url_modal.ts
+++ b/web/src/integration_url_modal.ts
@@ -22,7 +22,7 @@ import * as util from "./util.ts";
type UrlOption = {
key: string;
label: string;
- validator: string;
+ input_type: string;
};
type TopicUIParams = {
@@ -35,7 +35,7 @@ type TopicUIParams = {
const url_option_schema = z.object({
key: z.string(),
label: z.string(),
- validator: z.string(),
+ input_type: z.string(),
});
const url_options_schema = z.array(url_option_schema);
@@ -174,7 +174,7 @@ export function show_generate_integration_url_modal(api_key: string): void {
continue;
}
- const {key, label, validator} = option;
+ const {key, label, input_type} = option;
let $config_element: JQuery;
if (key === PresetUrlOption.BRANCHES) {
@@ -184,14 +184,14 @@ export function show_generate_integration_url_modal(api_key: string): void {
$config_element.find("#integration-url-all-branches").on("change", () => {
show_branch_filtering_ui();
});
- } else if (validator === "check_bool") {
+ } else if (input_type === "checkbox") {
$config_element = $(
render_generate_integration_url_config_checkbox_modal({key, label}),
);
$config_element.find(`#integration-url-${key}-checkbox`).on("change", () => {
update_url();
});
- } else if (validator === "check_string") {
+ } else if (input_type === "text") {
$config_element = $(
render_generate_integration_url_config_text_modal({key, label}),
);
@@ -314,7 +314,7 @@ export function show_generate_integration_url_modal(api_key: string): void {
if (url_options) {
for (const option of url_options) {
- const {key, validator} = option;
+ const {key, input_type} = option;
if (key === PresetUrlOption.CHANNEL_MAPPING) {
const stream_input = stream_input_dropdown_widget.value();
@@ -344,12 +344,12 @@ export function show_generate_integration_url_modal(api_key: string): void {
if (branch_names) {
params.set(key, branch_names);
}
- } else if (validator === "check_bool") {
+ } else if (input_type === "checkbox") {
const is_checked = $(`#integration-url-${key}-checkbox`).is(":checked");
if (is_checked) {
params.set(option.key, "true");
}
- } else if (validator === "check_string") {
+ } else if (input_type === "text") {
const value = $(`#integration-url-${key}-text`).val()?.toString();
if (value) {
params.set(key, value);
diff --git a/web/src/state_data.ts b/web/src/state_data.ts
index f04741c458e..c7802e79c6c 100644
--- a/web/src/state_data.ts
+++ b/web/src/state_data.ts
@@ -542,7 +542,7 @@ export const realm_schema = z.object({
z.object({
key: z.string(),
label: z.string(),
- validator: z.string(),
+ input_type: z.string(),
}),
),
),
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index d058f6096f1..dfb2f752079 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -797,7 +797,7 @@ def fetch_initial_state_data(
{
"key": c.name,
"label": c.label,
- "validator": c.validator.__name__,
+ "input_type": c.input_type,
}
for c in integration.url_options
]
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
index 2849889078e..6a373b9c651 100644
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -2,7 +2,7 @@ import os
from collections.abc import Callable, Sequence
from dataclasses import dataclass, field
from itertools import chain, zip_longest
-from typing import Any, TypeAlias
+from typing import Any
from django.contrib.staticfiles.storage import staticfiles_storage
from django.http import HttpRequest, HttpResponseBase
@@ -14,7 +14,6 @@ from django_stubs_ext import StrPromise
from typing_extensions import override
from zerver.lib.storage import static_path
-from zerver.lib.validator import check_bool, check_string
from zerver.lib.webhooks.common import PresetUrlOption, WebhookConfigOption, WebhookUrlOption
from zerver.webhooks import fixtureless_integrations
@@ -39,8 +38,6 @@ Over time, we expect this registry to grow additional convenience
features for writing and configuring integrations efficiently.
"""
-OptionValidator: TypeAlias = Callable[[str, str], str | bool | None]
-
META_CATEGORY: dict[str, StrPromise] = {
"meta-integration": gettext_lazy("Integration frameworks"),
"bots": gettext_lazy("Interactive bots"),
@@ -604,7 +601,7 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
[WebhookScreenshotConfig("job_run_completed_errored.json")],
display_name="DBT",
url_options=[
- WebhookUrlOption(name="access_url", label="DBT Access URL", validator=check_string)
+ WebhookUrlOption(name="access_url", label="DBT Access URL", input_type="text")
],
),
IncomingWebhookIntegration(
@@ -674,7 +671,7 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
WebhookUrlOption(
name="include_repository_name",
label="Include repository name in the notifications",
- validator=check_bool,
+ input_type="checkbox",
),
],
),
@@ -701,7 +698,7 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
WebhookUrlOption(
name="ignore_private_projects",
label="Exclude notifications from private projects",
- validator=check_bool,
+ input_type="checkbox",
),
],
),
@@ -815,7 +812,7 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
WebhookUrlOption(
name="eu_region",
label="Use Opsgenie's European service region",
- validator=check_bool,
+ input_type="checkbox",
)
],
),
diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py
index 21bc7f73718..aeac6a08f2e 100644
--- a/zerver/lib/webhooks/common.py
+++ b/zerver/lib/webhooks/common.py
@@ -31,7 +31,6 @@ from zerver.lib.exceptions import (
from zerver.lib.request import RequestNotes
from zerver.lib.send_email import FromAddress
from zerver.lib.typed_endpoint import ApiParamConfig, typed_endpoint
-from zerver.lib.validator import check_bool, check_string
from zerver.models import Realm, UserProfile
from zerver.models.custom_profile_fields import CustomProfileField, CustomProfileFieldValue
@@ -73,7 +72,7 @@ class WebhookConfigOption:
class WebhookUrlOption:
name: str
label: str
- validator: Callable[[str, str], str | bool | None]
+ input_type: str
@classmethod
def build_preset_config(cls, config: PresetUrlOption) -> "WebhookUrlOption":
@@ -89,19 +88,19 @@ class WebhookUrlOption:
return cls(
name=config.value,
label="",
- validator=check_string,
+ input_type="text",
)
case PresetUrlOption.IGNORE_PRIVATE_REPOSITORIES:
return cls(
name=config.value,
label="Exclude notifications from private repositories",
- validator=check_bool,
+ input_type="checkbox",
)
case PresetUrlOption.CHANNEL_MAPPING:
return cls(
name=config.value,
label="",
- validator=check_string,
+ input_type="text",
)
raise AssertionError(_("Unknown 'PresetUrlOption': {config}").format(config=config))
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index fdff6599a2f..09e6b0efbf7 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -27111,12 +27111,11 @@ components:
integration. In the web app, these are used when
[generating a URL for an integration](/help/generate-integration-url).
- This is an unstable API expected to be used only by the Zulip web
- app. Please discuss in chat.zulip.org before using it.
+ **Changes**: Before Zulip 12.0 (feature level 485), `input_type`
+ was named `validator`.
- **Changes**: New in Zulip 11.0 (feature level 403). Previously,
- these optional URL parameter options were included in the
- `config_options` object.
+ New in Zulip 11.0 (feature level 403). Previously, these optional
+ URL parameter options were included in the `config_options` object.
items:
type: object
additionalProperties: false
@@ -27124,17 +27123,15 @@ components:
key:
type: string
description: |
- The parameter variable to encode the users input for this
- option in the integrations webhook URL.
+ The name of the URL parameter.
label:
type: string
description: |
- A human-readable label of the url option.
- validator:
+ The label used for the input field in the UI.
+ input_type:
type: string
description: |
- The name of the validator function for the configuration
- option.
+ The type of input field this URL parameter maps to in the UI.
CustomProfileField:
type: object
additionalProperties: false