Phase 3 — Alerts (P3-05/06/07) #7
@@ -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 := ¬ificationForm{
|
f := ¬ificationForm{
|
||||||
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")),
|
||||||
|
|||||||
Reference in New Issue
Block a user