forked from BRETT/BRETT
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>
20 lines
610 B
TypeScript
20 lines
610 B
TypeScript
import { z } from 'zod'
|
|
import { settings } from '../../db/schema'
|
|
|
|
const bodySchema = z.object({
|
|
message: z.string().trim().max(500),
|
|
})
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const actor = await requirePermission(event, 'site.manage')
|
|
const { message } = await readValidatedBody(event, bodySchema.parse)
|
|
const db = useDb()
|
|
await db
|
|
.insert(settings)
|
|
.values({ key: 'motd', value: message })
|
|
.onDuplicateKeyUpdate({ set: { value: message } })
|
|
broadcastToAll({ type: 'motd', message })
|
|
await logAudit(actor.id, 'update_motd', null, { message })
|
|
return { message }
|
|
})
|