diff --git a/frontend/src/routes/persons/[id]/+page.server.ts b/frontend/src/routes/persons/[id]/+page.server.ts index 0bb0ca2a..6b7e8f79 100644 --- a/frontend/src/routes/persons/[id]/+page.server.ts +++ b/frontend/src/routes/persons/[id]/+page.server.ts @@ -1,11 +1,16 @@ -import { error, fail, redirect } from '@sveltejs/kit'; +import { error } from '@sveltejs/kit'; import { createApiClient } from '$lib/api.server'; import { getErrorMessage } from '$lib/errors'; -export async function load({ params, fetch }) { +export async function load({ params, fetch, locals }) { const { id } = params; const api = createApiClient(fetch); + const canWrite = + (locals.user as { groups?: { permissions: string[] }[] } | undefined)?.groups?.some((g) => + g.permissions.includes('WRITE_ALL') + ) ?? false; + const [personResult, sentDocsResult, receivedDocsResult] = await Promise.all([ api.GET('/api/persons/{id}', { params: { path: { id } } }), api.GET('/api/persons/{id}/documents', { params: { path: { id } } }), @@ -20,64 +25,7 @@ export async function load({ params, fetch }) { return { person: personResult.data!, sentDocuments: sentDocsResult.data ?? [], - receivedDocuments: receivedDocsResult.data ?? [] + receivedDocuments: receivedDocsResult.data ?? [], + canWrite }; } - -export const actions = { - update: async ({ request, params, fetch }) => { - const formData = await request.formData(); - const firstName = formData.get('firstName')?.toString().trim(); - const lastName = formData.get('lastName')?.toString().trim(); - const alias = formData.get('alias')?.toString().trim() || undefined; - const notes = formData.get('notes')?.toString().trim() || undefined; - const birthYearStr = formData.get('birthYear')?.toString().trim(); - const deathYearStr = formData.get('deathYear')?.toString().trim(); - const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined; - const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined; - - if (!firstName || !lastName) { - return fail(400, { updateError: 'Vor- und Nachname sind Pflichtfelder.' }); - } - - const api = createApiClient(fetch); - const { error: apiError } = await api.PUT('/api/persons/{id}', { - params: { path: { id: params.id } }, - body: { - firstName, - lastName, - ...(alias ? { alias } : {}), - ...(notes ? { notes } : {}), - ...(birthYear ? { birthYear } : {}), - ...(deathYear ? { deathYear } : {}) - } - }); - - if (apiError) { - return fail(400, { updateError: 'Speichern fehlgeschlagen.' }); - } - - return { updated: true }; - }, - - merge: async ({ request, params, fetch }) => { - const formData = await request.formData(); - const targetPersonId = formData.get('targetPersonId')?.toString(); - - if (!targetPersonId) { - return fail(400, { mergeError: 'Bitte eine Zielperson auswählen.' }); - } - - const api = createApiClient(fetch); - const { error: apiError } = await api.POST('/api/persons/{id}/merge', { - params: { path: { id: params.id } }, - body: { targetPersonId } - }); - - if (apiError) { - return fail(400, { mergeError: 'Zusammenführen fehlgeschlagen.' }); - } - - throw redirect(303, `/persons/${targetPersonId}`); - } -}; diff --git a/frontend/src/routes/persons/[id]/+page.svelte b/frontend/src/routes/persons/[id]/+page.svelte index a37e87da..2da3e2f2 100644 --- a/frontend/src/routes/persons/[id]/+page.svelte +++ b/frontend/src/routes/persons/[id]/+page.svelte @@ -2,11 +2,10 @@ import { m } from '$lib/paraglide/messages.js'; import { SvelteMap } from 'svelte/reactivity'; import PersonCard from './PersonCard.svelte'; -import PersonMergePanel from './PersonMergePanel.svelte'; import CoCorrespondentsList from './CoCorrespondentsList.svelte'; import PersonDocumentList from './PersonDocumentList.svelte'; -let { data, form } = $props(); +let { data } = $props(); const person = $derived(data.person); const sentDocuments = $derived(data.sentDocuments); @@ -47,7 +46,7 @@ const coCorrespondents = $derived.by(() => { }); -