Skip to content

Commit c7153b2

Browse files
authored
[API] feat: add existing ban check before creating punishments (#51)
1 parent 4bc156f commit c7153b2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

API/internal/rpc/server_management.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ func (s *ServerManagement) BanPlayer(ctx context.Context, req *pbapi.ServerBanPl
276276
return nil, status.Error(codes.PermissionDenied, "You cannot ban the server host")
277277
}
278278

279+
activeBan, err := s.store.Punishments.GetBanForServer(ctx, server.HostID, target.ID)
280+
if err != nil {
281+
logger.L().Error("Failed to check punishment", zap.Error(err))
282+
return nil, status.Error(codes.Internal, "Failed to check punishments")
283+
}
284+
285+
if activeBan != nil {
286+
return nil, status.Error(codes.PermissionDenied, "User is already banned")
287+
}
288+
279289
var expiresAt *time.Time
280290
if req.Duration != nil {
281291
expiresAt = new(time.Time)

0 commit comments

Comments
 (0)