Implement Phase 1 audit logging

Add centralized admin action logger and integrate logging for:
- Alert resolutions (system, rate limit, grouped)
- Role grants/revokes in UserRoleManager
- Incident creation/acknowledgement/resolution
- Moderation lock overrides

Includes file updates and usage across relevant components to ensure consistent audit trails.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 14:22:30 +00:00
parent 53b576ecc1
commit 8581950a6e
7 changed files with 167 additions and 0 deletions

View File

@@ -151,6 +151,16 @@ export function useResolveAlert() {
return useMutation({
mutationFn: async (id: string) => {
// Fetch full alert details before resolving
const { data: alert, error: fetchError } = await supabase
.from('rate_limit_alerts')
.select('*')
.eq('id', id)
.single();
if (fetchError) throw fetchError;
// Resolve the alert
const { data, error } = await supabase
.from('rate_limit_alerts')
.update({ resolved_at: new Date().toISOString() })
@@ -159,6 +169,18 @@ export function useResolveAlert() {
.single();
if (error) throw error;
// Log to audit trail
const { logAdminAction } = await import('@/lib/adminActionAuditHelpers');
await logAdminAction('rate_limit_alert_resolved', {
alert_id: id,
metric_type: alert.metric_type,
metric_value: alert.metric_value,
threshold_value: alert.threshold_value,
function_name: alert.function_name,
time_window_ms: alert.time_window_ms,
});
return data;
},
onSuccess: () => {