feat(routes): add server-side WRITE_ALL guard on write-only routes

Block direct URL navigation to /persons/new, /documents/new,
/documents/:id/edit for users without WRITE_ALL permission.
E2E tests verify admin user retains access to all write routes.

Closes #17
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-20 09:47:52 +01:00
parent fde75f3fcf
commit fa4bfb8e5c
4 changed files with 46 additions and 4 deletions

View File

@@ -1,9 +1,12 @@
import { fail, redirect } from '@sveltejs/kit';
import { error, fail, redirect } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { createApiClient } from '$lib/api.server';
import { parseBackendError, getErrorMessage } from '$lib/errors';
export async function load({ fetch }) {
export async function load({ fetch, locals }: { fetch: typeof globalThis.fetch; locals: App.Locals }) {
const canWrite = locals.user?.groups?.some((g: { permissions: string[] }) => g.permissions.includes('WRITE_ALL')) ?? false;
if (!canWrite) throw error(403, 'Forbidden');
const api = createApiClient(fetch);
const personsResult = await api.GET('/api/persons');