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:
@@ -1,10 +1,10 @@
|
||||
import { unlink } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { commentAttachments, comments, uploads } from '../../db/schema'
|
||||
import { commentAttachments, comments, uploads, users } from '../../db/schema'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requirePermission(event, 'upload.delete')
|
||||
const actor = await requirePermission(event, 'upload.delete')
|
||||
const id = getRouterParam(event, 'id') ?? ''
|
||||
if (!/^[A-Za-z0-9]{1,16}$/.test(id)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Ungültige ID' })
|
||||
@@ -12,8 +12,9 @@ export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
|
||||
const [upload] = await db
|
||||
.select({ fileName: uploads.fileName, previewImage: uploads.previewImage })
|
||||
.select({ fileName: uploads.fileName, previewImage: uploads.previewImage, type: uploads.type, originalName: uploads.originalName, userId: uploads.userId, userName: users.name })
|
||||
.from(uploads)
|
||||
.innerJoin(users, eq(uploads.userId, users.id))
|
||||
.where(eq(uploads.id, id))
|
||||
.limit(1)
|
||||
if (!upload) {
|
||||
@@ -40,5 +41,11 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
}
|
||||
broadcastToAll({ type: 'upload-deleted', ids: [id] })
|
||||
await logAudit(actor.id, 'delete_upload', { type: 'upload', id }, {
|
||||
uploadType: upload.type,
|
||||
originalName: upload.originalName,
|
||||
uploaderId: upload.userId,
|
||||
uploaderName: upload.userName,
|
||||
})
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user