From 24eecc16735baa7debb2fd53c413348e33ee8727 Mon Sep 17 00:00:00 2001 From: Steve Cliff Date: Mon, 4 May 2026 21:00:54 +0100 Subject: [PATCH] fix: read enabled checkbox correctly when paired with hidden=0 sibling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The notification channel form has a plus a so unchecking the box still submits 'enabled=0' (otherwise the field would just be absent). But Go's url.Values.Get returns the FIRST value, so even when the checkbox is ticked the handler read '0' and persisted enabled=false. Scan r.PostForm["enabled"] for any '1' instead. Caught during the sweep — all three test channels saved with enabled=0 even though the toggle visually rendered ON. --- internal/server/http/ui_notifications.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/server/http/ui_notifications.go b/internal/server/http/ui_notifications.go index b580a7e..3cfcb38 100644 --- a/internal/server/http/ui_notifications.go +++ b/internal/server/http/ui_notifications.go @@ -144,13 +144,26 @@ func (s *Server) decryptChannelConfig(ch store.NotificationChannel, dst any) err return json.Unmarshal(plain, dst) } +// formHasValue reports whether vals contains want. Used for hidden+checkbox +// pairs (e.g. + ) +// where r.PostForm.Get returns the first ("0") even when the checkbox is +// ticked, so we have to scan the slice instead. +func formHasValue(vals []string, want string) bool { + for _, v := range vals { + if v == want { + return true + } + } + return false +} + // formFromRequest parses the common + per-kind fields from a POST form. // The caller must have already called r.ParseForm(). func formFromRequest(r *stdhttp.Request) *notificationForm { f := ¬ificationForm{ Kind: strings.TrimSpace(r.PostForm.Get("kind")), Name: strings.TrimSpace(r.PostForm.Get("name")), - Enabled: r.PostForm.Get("enabled") == "1", + Enabled: formHasValue(r.PostForm["enabled"], "1"), DefaultPriority: strings.TrimSpace(r.PostForm.Get("default_priority")), WebhookURL: strings.TrimSpace(r.PostForm.Get("webhook_url")),