mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-26 19:46:59 -05:00
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:
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user