Turn url back into a setting

This commit is contained in:
Mubelotix
2025-08-05 11:16:34 +02:00
parent 6cb2296644
commit a9c924b433
2 changed files with 13 additions and 10 deletions

View File

@ -61,9 +61,10 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[schema(rename_all = "camelCase")] #[schema(rename_all = "camelCase")]
pub(super) struct WebhookSettings { pub(super) struct WebhookSettings {
#[schema(value_type = Option<String>, example = "https://your.site/on-tasks-completed")]
#[deserr(default, error = DeserrJsonError<InvalidWebhooksUrl>)] #[deserr(default, error = DeserrJsonError<InvalidWebhooksUrl>)]
#[serde(default)] #[serde(default)]
url: Option<String>, url: Setting<String>,
#[schema(value_type = Option<BTreeMap<String, String>>, example = json!({"Authorization":"Bearer a-secret-token"}))] #[schema(value_type = Option<BTreeMap<String, String>>, example = json!({"Authorization":"Bearer a-secret-token"}))]
#[deserr(default, error = DeserrJsonError<InvalidWebhooksHeaders>)] #[deserr(default, error = DeserrJsonError<InvalidWebhooksHeaders>)]
#[serde(default)] #[serde(default)]
@ -241,7 +242,11 @@ fn patch_webhook_inner(
) -> Result<Webhook, WebhooksError> { ) -> Result<Webhook, WebhooksError> {
let Webhook { url: old_url, mut headers } = old_webhook; let Webhook { url: old_url, mut headers } = old_webhook;
let url = new_webhook.url.unwrap_or(old_url); let url = match new_webhook.url {
Setting::Set(url) => url,
Setting::NotSet => old_url,
Setting::Reset => return Err(MissingUrl(uuid.to_owned())),
};
match new_webhook.headers { match new_webhook.headers {
Setting::Set(new_headers) => { Setting::Set(new_headers) => {
@ -369,7 +374,7 @@ async fn post_webhook(
} }
let webhook = Webhook { let webhook = Webhook {
url: webhook_settings.url.ok_or(MissingUrl(uuid))?, url: webhook_settings.url.set().ok_or(MissingUrl(uuid))?,
headers: webhook_settings headers: webhook_settings
.headers .headers
.set() .set()

View File

@ -465,15 +465,13 @@ async fn create_and_patch() {
"#); "#);
let (value, code) = server.patch_webhook(&uuid, json!({ "url": null })).await; let (value, code) = server.patch_webhook(&uuid, json!({ "url": null })).await;
snapshot!(code, @"200 OK"); snapshot!(code, @"400 Bad Request");
snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#" snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#"
{ {
"uuid": "81ccb94c-74cf-4d40-8070-492055804693", "message": "The URL for the webhook `[uuid]` is missing.",
"isEditable": true, "code": "invalid_webhooks_url",
"url": "https://example.com/hook", "type": "invalid_request",
"headers": { "link": "https://docs.meilisearch.com/errors#invalid_webhooks_url"
"authorization2": "TOKEN"
}
} }
"#); "#);
} }