complete new audit system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Response } from 'express';
|
||||
import { AuthRequest } from '../types/index.js';
|
||||
import * as auditService from '../services/audit.service.js';
|
||||
import { logChange } from '../services/audit.service.js';
|
||||
import { AuditAction, AuditSensitivity } from '@prisma/client';
|
||||
|
||||
/**
|
||||
@@ -106,12 +107,15 @@ export async function exportAuditLogs(req: AuthRequest, res: Response) {
|
||||
format
|
||||
);
|
||||
|
||||
const contentType = format === 'csv' ? 'text/csv' : 'application/json';
|
||||
const filename = `audit-logs-${new Date().toISOString().split('T')[0]}.${format}`;
|
||||
|
||||
res.setHeader('Content-Type', contentType);
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||
res.send(content);
|
||||
if (format === 'csv') {
|
||||
const filename = `audit-logs-${new Date().toISOString().split('T')[0]}.csv`;
|
||||
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||
// BOM für Excel UTF-8 Erkennung
|
||||
res.send('\uFEFF' + content);
|
||||
} else {
|
||||
res.json({ success: true, data: JSON.parse(content) })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Exportieren der Audit-Logs:', error);
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Exportieren' });
|
||||
@@ -147,6 +151,23 @@ export async function verifyIntegrity(req: AuthRequest, res: Response) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash-Kette reparieren (alle Hashes neu berechnen)
|
||||
*/
|
||||
export async function rehashAll(req: AuthRequest, res: Response) {
|
||||
try {
|
||||
const result = await auditService.rehashAll();
|
||||
res.json({
|
||||
success: true,
|
||||
data: result,
|
||||
message: `${result.rehashedCount} Einträge neu gehasht. Kette ist jetzt intakt.`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Re-Hashing:', error);
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Re-Hashing' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retention-Policies abrufen
|
||||
*/
|
||||
@@ -175,6 +196,12 @@ export async function updateRetentionPolicy(req: AuthRequest, res: Response) {
|
||||
isActive,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'RetentionPolicy',
|
||||
resourceId: id.toString(),
|
||||
label: `Aufbewahrungsrichtlinie aktualisiert`,
|
||||
});
|
||||
|
||||
res.json({ success: true, data: policy });
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Aktualisieren der Retention-Policy:', error);
|
||||
|
||||
Reference in New Issue
Block a user