Fix admin ban: add banned/suspended to user_status enum, remove bad audit_log query

This commit is contained in:
Patrick Britton 2026-02-06 12:30:00 -06:00
parent 6edaf9206f
commit d32da021fb
2 changed files with 2 additions and 8 deletions

View file

@ -470,14 +470,6 @@ func (h *AdminHandler) UpdateUserStatus(c *gin.Context) {
}
// Revoke ALL refresh tokens immediately
h.pool.Exec(ctx, `UPDATE refresh_tokens SET revoked = true WHERE user_id = $1::uuid`, targetUserID)
// Log the banned user's last known IP
h.pool.Exec(ctx, `
INSERT INTO banned_ips (ip_address, user_id, reason, banned_at)
SELECT COALESCE(
(SELECT ip_address FROM audit_log WHERE target_id = $1::uuid ORDER BY created_at DESC LIMIT 1),
'unknown'
), $1::uuid, $2, NOW()
`, targetUserID, req.Reason)
} else if req.Status == "suspended" {
suspendUntil := time.Now().Add(7 * 24 * time.Hour) // Default 7 day suspension from admin
_, err := h.pool.Exec(ctx, `UPDATE users SET status = 'suspended', suspended_until = $2 WHERE id = $1::uuid`, targetUserID, suspendUntil)

View file

@ -0,0 +1,2 @@
ALTER TYPE user_status ADD VALUE IF NOT EXISTS 'banned';
ALTER TYPE user_status ADD VALUE IF NOT EXISTS 'suspended';