Skip to content

Commit

Permalink
try fix: not found in BanUserForever
Browse files Browse the repository at this point in the history
  • Loading branch information
ppolariss committed Oct 10, 2024
1 parent 3189621 commit a39104b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apis/penalty/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"treehole_next/utils"

"github.com/opentreehole/go-common"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
"gorm.io/gorm/clause"

Expand Down Expand Up @@ -144,6 +145,7 @@ func BanUserForever(c *fiber.Ctx) error {
if err != nil {
return err
}
log.Info().Msgf("ban user forever: %v", body)

floorID, err := c.ParamsInt("id")
if err != nil {
Expand All @@ -161,6 +163,8 @@ func BanUserForever(c *fiber.Ctx) error {
return common.Forbidden()
}

log.Info().Msgf("ban user forever: %d", floorID)

var floor Floor
err = DB.Take(&floor, floorID).Error
if err != nil {
Expand All @@ -181,6 +185,7 @@ func BanUserForever(c *fiber.Ctx) error {
var divisionIDs []int
madeBy := user.ID
err = DB.Transaction(func(tx *gorm.DB) (err error) {
log.Info().Msgf("ban user forever: %d", floor.UserID)
err = tx.Clauses(clause.Locking{Strength: "UPDATE"}).Take(&user, floor.UserID).Error
if err != nil {
return err
Expand All @@ -194,6 +199,7 @@ func BanUserForever(c *fiber.Ctx) error {
ExcludeBanForeverDivisionIds := config.Config.ExcludeBanForeverDivisionIds

divisionIDs = utils.Difference(divisionIDs, ExcludeBanForeverDivisionIds)
log.Info().Msgf("ban user forever: %v", divisionIDs)

for _, divisionID := range divisionIDs {
punishment = &Punishment{
Expand All @@ -217,6 +223,7 @@ func BanUserForever(c *fiber.Ctx) error {
punishments = append(punishments, punishment)
}
user.OffenceCount += len(divisionIDs)
log.Info().Msgf("ban user forever: %v", punishments)

err = tx.Create(&punishments).Error
if err != nil {
Expand All @@ -233,6 +240,7 @@ func BanUserForever(c *fiber.Ctx) error {
if err != nil {
return err
}
log.Info().Msgf("ban user forever: %v", user)

// construct message for user
message := Notification{
Expand All @@ -247,6 +255,7 @@ func BanUserForever(c *fiber.Ctx) error {
Type: MessageTypePermission,
URL: fmt.Sprintf("/api/floors/%d", floor.ID),
}
log.Info().Msgf("ban user forever: %v", message)

// send
_, err = message.Send()
Expand Down

0 comments on commit a39104b

Please sign in to comment.