Bugfix when removing all chat moderation rules

This commit is contained in:
Noah Petherbridge 2024-09-20 20:32:56 -07:00
parent 066765d2dc
commit 9575041d1e
3 changed files with 10 additions and 9 deletions

View File

@ -135,12 +135,12 @@ var (
}, },
{ {
Value: "novideo", Value: "novideo",
Label: "No webcam privileges", Label: "No webcam privileges ('Shy Accounts')",
Help: "The user can not broadcast or watch any webcam. Note: this option supercedes all other video-related rules.", Help: "The user can not broadcast or watch any webcam. Note: this option supercedes all other video-related rules.",
}, },
{ {
Value: "noimage", Value: "noimage",
Label: "No image sharing privileges", Label: "No image sharing privileges ('Shy Accounts')",
Help: "The user can not share or see any image shared on chat.", Help: "The user can not share or see any image shared on chat.",
}, },
} }

View File

@ -139,18 +139,19 @@ func UserActions() http.HandlerFunc {
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
// Rules list for the change log. // Rules list for the change log.
var newRules = "(none)" var newRules = "(none)"
if rule, ok := r.PostForm["rules"]; ok { if rule, ok := r.PostForm["rules"]; ok && len(rule) > 0 {
newRules = strings.Join(rule, ",") newRules = strings.Join(rule, ",")
user.SetProfileField("chat_moderation_rules", newRules) user.SetProfileField("chat_moderation_rules", newRules)
if err := user.Save(); err != nil {
session.FlashError(w, r, "Error saving the user's chat rules: %s", err)
} else {
session.Flash(w, r, "Chat moderation rules have been updated!")
}
} else { } else {
user.DeleteProfileField("chat_moderation_rules") user.DeleteProfileField("chat_moderation_rules")
session.Flash(w, r, "All chat moderation rules have been cleared for user: %s", user.Username)
} }
if err := user.Save(); err != nil {
session.FlashError(w, r, "Error saving the user's chat rules: %s", err)
} else {
session.Flash(w, r, "Chat moderation rules have been updated!")
}
templates.Redirect(w, "/u/"+user.Username) templates.Redirect(w, "/u/"+user.Username)
// Log the new rules to the changelog. // Log the new rules to the changelog.

View File

@ -809,7 +809,7 @@ func (u *User) SetProfileField(name, value string) {
// DeleteProfileField removes a stored profile field. // DeleteProfileField removes a stored profile field.
func (u *User) DeleteProfileField(name string) error { func (u *User) DeleteProfileField(name string) error {
res := DB.Raw( res := DB.Exec(
"DELETE FROM profile_fields WHERE user_id=? AND name=?", "DELETE FROM profile_fields WHERE user_id=? AND name=?",
u.ID, name, u.ID, name,
) )