Don't create a poll if no options are set.
This commit is contained in:
parent
d95268f069
commit
7a27534153
@ -366,7 +366,9 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro
|
|||||||
var pollInputItems = make(map[int]string)
|
var pollInputItems = make(map[int]string)
|
||||||
for key, values := range r.Form {
|
for key, values := range r.Form {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
if strings.HasPrefix(key, "pollinputitem[") {
|
if !strings.HasPrefix(key, "pollinputitem[") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
halves := strings.Split(key, "[")
|
halves := strings.Split(key, "[")
|
||||||
if len(halves) != 2 {
|
if len(halves) != 2 {
|
||||||
return c.LocalError("Malformed pollinputitem", w, r, user)
|
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
|
// Make sure the indices are sequential to avoid out of bounds issues
|
||||||
var seqPollInputItems = make(map[int]string)
|
var seqPollInputItems = make(map[int]string)
|
||||||
for i := 0; i < len(pollInputItems); i++ {
|
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?
|
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")
|
err = c.Subscriptions.Add(user.ID, tid, "topic")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user