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 84e121bb9c - Show all commits
+15 -1
View File
@@ -144,6 +144,20 @@ func (s *Server) decryptChannelConfig(ch store.NotificationChannel, dst any) err
return json.Unmarshal(plain, dst)
}
// firstNonEmpty returns the first non-empty (after TrimSpace) value in
// vals, or "". Used for fields like `name` that appear once per per-kind
// sub-form: only the visible kind's input is filled in, so PostForm.Get
// (which returns the first regardless of emptiness) would lose the
// actual value when the user edits the second or third kind.
func firstNonEmpty(vals []string) string {
for _, v := range vals {
if strings.TrimSpace(v) != "" {
return v
}
}
return ""
}
// 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
@@ -162,7 +176,7 @@ func formHasValue(vals []string, want string) bool {
func formFromRequest(r *stdhttp.Request) *notificationForm {
f := &notificationForm{
Kind: strings.TrimSpace(r.PostForm.Get("kind")),
Name: strings.TrimSpace(r.PostForm.Get("name")),
Name: strings.TrimSpace(firstNonEmpty(r.PostForm["name"])),
Enabled: formHasValue(r.PostForm["enabled"], "1"),
DefaultPriority: strings.TrimSpace(r.PostForm.Get("default_priority")),