Phase 3 — Alerts (P3-05/06/07) #7

Merged
steve merged 34 commits from p3-alerts into main 2026-05-04 22:51:17 +01:00
Showing only changes of commit 6466f8c759 - Show all commits
+14 -1
View File
@@ -144,13 +144,26 @@ func (s *Server) decryptChannelConfig(ch store.NotificationChannel, dst any) err
return json.Unmarshal(plain, dst) return json.Unmarshal(plain, dst)
} }
// formHasValue reports whether vals contains want. Used for hidden+checkbox
// pairs (e.g. <input hidden name=x value=0> + <input checkbox name=x value=1>)
// 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. // formFromRequest parses the common + per-kind fields from a POST form.
// The caller must have already called r.ParseForm(). // The caller must have already called r.ParseForm().
func formFromRequest(r *stdhttp.Request) *notificationForm { func formFromRequest(r *stdhttp.Request) *notificationForm {
f := &notificationForm{ f := &notificationForm{
Kind: strings.TrimSpace(r.PostForm.Get("kind")), Kind: strings.TrimSpace(r.PostForm.Get("kind")),
Name: strings.TrimSpace(r.PostForm.Get("name")), 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")), DefaultPriority: strings.TrimSpace(r.PostForm.Get("default_priority")),
WebhookURL: strings.TrimSpace(r.PostForm.Get("webhook_url")), WebhookURL: strings.TrimSpace(r.PostForm.Get("webhook_url")),