oops, allow saving edit too

This commit is contained in:
Ted Unangst 2019-10-09 16:16:38 -04:00
parent 60f301cc09
commit 04c65dcc0f
1 changed files with 10 additions and 3 deletions

13
web.go
View File

@ -902,7 +902,7 @@ func edithonkpage(w http.ResponseWriter, r *http.Request) {
user, _ := butwhatabout(u.Username) user, _ := butwhatabout(u.Username)
xid := r.FormValue("xid") xid := r.FormValue("xid")
honk := getxonk(u.UserID, xid) honk := getxonk(u.UserID, xid)
if honk == nil || honk.Honker != user.URL || honk.What == "bonk" { if !canedithonk(user, honk) {
http.Error(w, "no editing that please", http.StatusInternalServerError) http.Error(w, "no editing that please", http.StatusInternalServerError)
return return
} }
@ -930,6 +930,13 @@ func edithonkpage(w http.ResponseWriter, r *http.Request) {
} }
} }
func canedithonk(user *WhatAbout, honk *Honk) bool {
if honk == nil || honk.Honker != user.URL || honk.What == "bonk" {
return false
}
return true
}
// what a hot mess this function is // what a hot mess this function is
func submithonk(w http.ResponseWriter, r *http.Request) { func submithonk(w http.ResponseWriter, r *http.Request) {
rid := r.FormValue("rid") rid := r.FormValue("rid")
@ -943,8 +950,8 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
var honk *Honk var honk *Honk
if updatexid != "" { if updatexid != "" {
honk = getxonk(userinfo.UserID, updatexid) honk = getxonk(userinfo.UserID, updatexid)
if honk == nil || honk.Honker != user.URL || honk.What != "honk" { if !canedithonk(user, honk) {
log.Printf("not saving edit") http.Error(w, "no editing that please", http.StatusInternalServerError)
return return
} }
honk.Date = dt honk.Date = dt