Fix admin ban: add banned/suspended to user_status enum, remove bad audit_log query
This commit is contained in:
parent
6edaf9206f
commit
d32da021fb
|
|
@ -470,14 +470,6 @@ func (h *AdminHandler) UpdateUserStatus(c *gin.Context) {
|
||||||
}
|
}
|
||||||
// Revoke ALL refresh tokens immediately
|
// Revoke ALL refresh tokens immediately
|
||||||
h.pool.Exec(ctx, `UPDATE refresh_tokens SET revoked = true WHERE user_id = $1::uuid`, targetUserID)
|
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" {
|
} else if req.Status == "suspended" {
|
||||||
suspendUntil := time.Now().Add(7 * 24 * time.Hour) // Default 7 day suspension from admin
|
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)
|
_, err := h.pool.Exec(ctx, `UPDATE users SET status = 'suspended', suspended_until = $2 WHERE id = $1::uuid`, targetUserID, suspendUntil)
|
||||||
|
|
|
||||||
2
go-backend/scripts/fix_user_status_enum.sql
Normal file
2
go-backend/scripts/fix_user_status_enum.sql
Normal 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';
|
||||||
Loading…
Reference in a new issue