forked from BRETT/BRETT
Add audit log for moderation and admin actions
New audit_log table records actor, action, target and a JSON snapshot of the details, so entries stay readable after the target is deleted; the actor is set to NULL when the user is removed. logAudit() is called from upload delete (single and bulk), comment delete, tag removal, role create/delete, role permission changes, role assign/revoke and MOTD updates. Logging failures only warn and never fail the action itself. The admin page gets an audit card behind the new audit.view permission with action filter, click-to-filter by user, readable summaries per action and server-side pagination. Action catalog lives in shared/utils/audit.ts, labels under admin.auditActions (de/en). Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { roles } from '../../../db/schema'
|
||||
import { SYSTEM_ROLES } from '../../../../shared/utils/permissions'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requirePermission(event, 'roles.manage')
|
||||
const actor = await requirePermission(event, 'roles.manage')
|
||||
const id = Number(getRouterParam(event, 'id'))
|
||||
if (!Number.isInteger(id) || id <= 0) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Ungültige ID' })
|
||||
@@ -17,5 +17,6 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, statusMessage: `Die ${existing[0].name}-Rolle kann nicht gelöscht werden` })
|
||||
}
|
||||
await db.delete(roles).where(eq(roles.id, id))
|
||||
await logAudit(actor.id, 'delete_role', { type: 'role', id }, { name: existing[0].name })
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user