Log when a user tried to block an admin

face-detect
Noah Petherbridge 2023-08-12 23:23:49 -07:00
parent 4d1a057a73
commit f8487f92e7
1 changed files with 20 additions and 0 deletions

View File

@ -1,10 +1,12 @@
package block
import (
"fmt"
"net/http"
"strings"
"code.nonshy.com/nonshy/website/pkg/config"
"code.nonshy.com/nonshy/website/pkg/log"
"code.nonshy.com/nonshy/website/pkg/models"
"code.nonshy.com/nonshy/website/pkg/session"
"code.nonshy.com/nonshy/website/pkg/templates"
@ -97,6 +99,24 @@ func BlockUser() http.HandlerFunc {
// Can't block admins.
if user.IsAdmin {
// For curiosity's sake, log a report.
fb := &models.Feedback{
Intent: "report",
Subject: "A user tried to block an admin",
Message: fmt.Sprintf(
"A user has tried to block an admin user account!\n\n"+
"* Username: %s\n* Tried to block: %s",
currentUser.Username,
user.Username,
),
UserID: currentUser.ID,
TableName: "users",
TableID: currentUser.ID,
}
if err := models.CreateFeedback(fb); err != nil {
log.Error("Could not log feedback for user %s trying to block admin %s: %s", currentUser.Username, user.Username, err)
}
session.FlashError(w, r, "You can not block site administrators.")
templates.Redirect(w, "/u/"+username)
return