Don't create a poll if no options are set.

This commit is contained in:
Azareal 2019-06-15 22:26:37 +10:00
parent d95268f069
commit 7a27534153

View File

@ -366,7 +366,9 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
var pollInputItems = make(map[int]string)
for key, values := range r.Form {
for _, value := range values {
if strings.HasPrefix(key, "pollinputitem[") {
if !strings.HasPrefix(key, "pollinputitem[") {
continue
}
halves := strings.Split(key, "[")
if len(halves) != 2 {
return c.LocalError("Malformed pollinputitem", w, r, user)
@ -389,8 +391,8 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
}
}
}
}
if len(pollInputItems) > 0 {
// Make sure the indices are sequential to avoid out of bounds issues
var seqPollInputItems = make(map[int]string)
for i := 0; i < len(pollInputItems); i++ {
@ -403,6 +405,7 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
return c.LocalError("Failed to add poll to topic", w, r, user) // TODO: Might need to be an internal error as it could leave phantom polls?
}
}
}
err = c.Subscriptions.Add(user.ID, tid, "topic")
if err != nil {