Implement Phase 2 audit logging

Add audit logging for admin settings changes, rate limit config updates, anomaly detection config changes (skipped due to no UI), and version cleanup settings updates. Implement logging via central logAdminAction helper and integrate into AdminSettings, VersionCleanupSettings, and RateLimitAlerts mutations (create, update, delete).
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 14:36:10 +00:00
parent 8581950a6e
commit a5fed1e26a
3 changed files with 88 additions and 6 deletions

View File

@@ -49,6 +49,10 @@ export function useAdminSettings() {
const updateSettingMutation = useMutation({
mutationFn: async ({ key, value }: { key: string; value: unknown }) => {
// Get old value for audit log
const oldSetting = settings?.find(s => s.setting_key === key);
const oldValue = oldSetting?.setting_value;
const { error } = await supabase
.from('admin_settings')
.update({
@@ -59,10 +63,19 @@ export function useAdminSettings() {
.eq('setting_key', key);
if (error) throw error;
return { key, value };
return { key, value, oldValue };
},
onSuccess: () => {
onSuccess: async (data) => {
queryClient.invalidateQueries({ queryKey: ['admin-settings'] });
// Log to audit trail
const { logAdminAction } = await import('@/lib/adminActionAuditHelpers');
await logAdminAction('admin_setting_updated', {
setting_key: data.key,
old_value: data.oldValue,
new_value: data.value,
});
toast({
title: "Setting Updated",
description: "The setting has been saved successfully.",