Log when a user tried to block an admin

This commit is contained in:
Noah Petherbridge 2023-08-12 23:23:49 -07:00
parent 4d1a057a73
commit f8487f92e7

View File

@ -1,10 +1,12 @@
package block package block
import ( import (
"fmt"
"net/http" "net/http"
"strings" "strings"
"code.nonshy.com/nonshy/website/pkg/config" "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/models"
"code.nonshy.com/nonshy/website/pkg/session" "code.nonshy.com/nonshy/website/pkg/session"
"code.nonshy.com/nonshy/website/pkg/templates" "code.nonshy.com/nonshy/website/pkg/templates"
@ -97,6 +99,24 @@ func BlockUser() http.HandlerFunc {
// Can't block admins. // Can't block admins.
if user.IsAdmin { 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.") session.FlashError(w, r, "You can not block site administrators.")
templates.Redirect(w, "/u/"+username) templates.Redirect(w, "/u/"+username)
return return