Phase 5 abgeschlossen: Dateien mit vollständiger Prüfkette

Upload → quarantine/ → Typprüfung → ClamAV → Neukodierung → store/. Es gibt
keinen Pfad, auf dem eine Datei ungeprüft in store/ landet, und keinen
Schalter, der die Kette abschaltet.

Die Typprüfung liest Magic Bytes aus einer eigenen Signaturtabelle statt aus
file-type: bei einer Positivliste aus fünf Formaten hilft es nicht, hundert
erkennen zu können. Die Signatur muss an Position 0 stehen — ein Vorspann vor
%PDF- ist der klassische Weg, eine Datei für zwei Programme zugleich lesbar zu
machen. Wer trotzdem durchkommt, kommt als text/plain durch und wird unter der
Endung des erkannten Typs ausgeliefert, nicht unter der hochgeladenen.

Drei Ausgänge statt zwei: BLOCKED heisst "ist gefährlich", FAILED heisst
"wissen wir nicht". Nur FAILED lässt sich freigeben, und die Freigabe
wiederholt die Kette ohne den Scanner — Typprüfung und Neukodierung laufen
dabei mit. Ein fehlender clamd macht damit keine Datei sauber; ein Test hält
das fest.

Auslieferung nur über /api/files/[id], mit Sichtbarkeitsprüfung der
zugehörigen Akte, Protokoll ab Stufe 3 und den harten Kopfzeilen aus docs/07.
Vorschaubilder dürfen inline, weil sie serverseitig als WebP neu kodiert
wurden.

Das Lichtbild im Aktenblatt ist damit gefüllt: der Feldwert ist die Kennung
eines geprüften Anhangs, serverseitig zu einer Adresse aufgelöst.

/api/events liefert attachment.scanned über pg_notify — die Grundlage, auf der
Phase 6 den Aktenchat aufsetzt. Die Sichtbarkeit wird je Ereignis geprüft,
sonst verriete schon die Kennung die Existenz.

Nebenbei riss das Bündelbudget (121 kB gegen 120 erlaubte): lib/i18n/de.ts war
ein Objekt, und eine Client-Komponente zieht die ganze Datei mit. Die Texte
stehen jetzt in sechs Dateien nach Bereichen, de.ts setzt sie nur zusammen.
Grösste Route wieder bei 118 kB, und sie wächst nicht mehr mit jedem neuen
Bereich mit.

133 Tests im Web-Paket, 15 in der Datenbank, 28 e2e.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Harlekin
2026-09-02 20:27:22 +02:00
co-authored by Claude Opus 5
parent 68ad0debd3
commit 5f58d9b96f
65 changed files with 3668 additions and 870 deletions
@@ -1,7 +1,8 @@
'use client'
import { useState, useTransition } from 'react'
import { de } from '@/lib/i18n/de'
import { caseText, entryText } from '@/lib/i18n/cases'
import { actionErrorsText, commonText } from '@/lib/i18n/common'
import { changeStatusAction, reclassifyAction } from '../actions'
/**
@@ -38,7 +39,7 @@ export function CaseActions({
setError(null)
startTransition(async () => {
const result = await action()
if (!result.ok) setError(result.error ?? de.actionErrors.default!)
if (!result.ok) setError(result.error ?? actionErrorsText.default!)
})
}
@@ -46,7 +47,7 @@ export function CaseActions({
<div className="mt-6 flex flex-wrap gap-x-10 gap-y-5 border-t border-line pt-5 text-xs">
{statusTargets.length > 0 ? (
<div>
<p className="font-condensed text-text-dim">{de.case.statusChange}</p>
<p className="font-condensed text-text-dim">{caseText.statusChange}</p>
<div className="mt-1.5 flex flex-wrap items-center gap-2">
<select
value={nextStatus}
@@ -55,14 +56,14 @@ export function CaseActions({
>
{statusTargets.map((target) => (
<option key={target} value={target}>
{de.case.statusNames[target] ?? target}
{caseText.statusNames[target] ?? target}
</option>
))}
</select>
<input
value={statusReason}
onChange={(event) => setStatusReason(event.target.value)}
placeholder={de.entry.changeReason}
placeholder={entryText.changeReason}
className="w-56 border border-line bg-raised px-2 py-1"
/>
<button
@@ -76,19 +77,19 @@ export function CaseActions({
to: nextStatus,
reason: statusReason || undefined,
}),
`${de.case.statusChange}: ${de.case.statusNames[nextStatus] ?? nextStatus}?`,
`${caseText.statusChange}: ${caseText.statusNames[nextStatus] ?? nextStatus}?`,
)
}
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
>
{pending ? de.case.saving : de.common.save}
{pending ? caseText.saving : commonText.save}
</button>
</div>
</div>
) : null}
<div>
<p className="font-condensed text-text-dim">{de.case.reclassify}</p>
<p className="font-condensed text-text-dim">{caseText.reclassify}</p>
<div className="mt-1.5 flex flex-wrap items-center gap-2">
<select
value={nextLevel}
@@ -109,7 +110,7 @@ export function CaseActions({
<input
value={levelReason}
onChange={(event) => setLevelReason(event.target.value)}
placeholder={de.case.reclassifyReason}
placeholder={caseText.reclassifyReason}
className="w-64 border border-line bg-raised px-2 py-1"
/>
) : null}
@@ -124,12 +125,12 @@ export function CaseActions({
to: nextLevel,
reason: levelReason || undefined,
}),
`${de.case.reclassify}: ${nextLevel}?`,
`${caseText.reclassify}: ${nextLevel}?`,
)
}
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
>
{pending ? de.case.saving : de.common.save}
{pending ? caseText.saving : commonText.save}
</button>
</div>
</div>
+12 -11
View File
@@ -2,7 +2,8 @@
import { useState, useTransition } from 'react'
import Link from 'next/link'
import { de } from '@/lib/i18n/de'
import { linkText } from '@/lib/i18n/cases'
import { commonText } from '@/lib/i18n/common'
import { LINK_KINDS } from '@/lib/cases/terms'
import { linkCasesAction, unlinkCasesAction } from '../actions'
import { classificationEdgeStyle } from '@/components/StampMark'
@@ -37,7 +38,7 @@ export function CaseLinks({
return (
<div>
{links.length === 0 ? (
<p className="text-text-dim">{de.link.empty}</p>
<p className="text-text-dim">{linkText.empty}</p>
) : (
<ul className="border-t border-line">
{links.map((link) => (
@@ -47,7 +48,7 @@ export function CaseLinks({
style={classificationEdgeStyle(link.other.classification)}
>
<span className="font-condensed text-2xs text-text-dim">
{(link.direction === 'in' ? de.link.incoming : de.link.kinds)[link.kind] ??
{(link.direction === 'in' ? linkText.incoming : linkText.kinds)[link.kind] ??
link.kind}
</span>
<Link
@@ -74,7 +75,7 @@ export function CaseLinks({
}
className="font-condensed text-2xs text-text-dim"
>
{de.link.remove}
{linkText.remove}
</button>
) : null}
</li>
@@ -90,20 +91,20 @@ export function CaseLinks({
<select
value={kind}
onChange={(event) => setKind(event.target.value)}
aria-label={de.link.kind}
aria-label={linkText.kind}
className="border border-line bg-raised px-2 py-1 text-2xs"
>
{LINK_KINDS.map((value) => (
<option key={value} value={value}>
{de.link.kinds[value] ?? value}
{linkText.kinds[value] ?? value}
</option>
))}
</select>
<input
value={target}
onChange={(event) => setTarget(event.target.value)}
placeholder={de.link.target}
aria-label={de.link.target}
placeholder={linkText.target}
aria-label={linkText.target}
className="border border-line bg-raised px-2 py-1 font-mono text-2xs"
/>
<button
@@ -127,14 +128,14 @@ export function CaseLinks({
}
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
>
{de.link.add}
{linkText.add}
</button>
<button
type="button"
onClick={() => setOpen(false)}
className="font-condensed text-2xs text-text-dim"
>
{de.common.cancel}
{commonText.cancel}
</button>
</div>
) : (
@@ -143,7 +144,7 @@ export function CaseLinks({
onClick={() => setOpen(true)}
className="mt-4 border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent"
>
{de.link.add}
{linkText.add}
</button>
)
) : null}
@@ -1,7 +1,8 @@
'use client'
import { useState, useTransition } from 'react'
import { de } from '@/lib/i18n/de'
import { caseText, entryText } from '@/lib/i18n/cases'
import { actionErrorsText } from '@/lib/i18n/common'
import { editEntryAction, restoreEntryAction, retractEntryAction } from '../actions'
/**
@@ -39,7 +40,7 @@ export function EntryActions({
setMode('idle')
setReason('')
} else {
setError(result.error ?? de.actionErrors.default!)
setError(result.error ?? actionErrorsText.default!)
}
})
}
@@ -51,7 +52,7 @@ export function EntryActions({
<input
value={reason}
onChange={(event) => setReason(event.target.value)}
placeholder={de.entry.retractReason}
placeholder={entryText.retractReason}
className="w-64 border border-line bg-raised px-2 py-1"
/>
<button
@@ -60,7 +61,7 @@ export function EntryActions({
onClick={() => run(() => restoreEntryAction({ entryId, caseNumber, reason }))}
className="font-condensed text-accent disabled:text-text-dim"
>
{de.entry.restore}
{entryText.restore}
</button>
{error ? <span className="text-stamp-4">{error}</span> : null}
</div>
@@ -73,7 +74,7 @@ export function EntryActions({
<div className="mt-1.5 flex gap-3 text-2xs">
{canEdit ? (
<button type="button" onClick={() => setMode('edit')} className="font-condensed text-accent">
{de.entry.edit}
{entryText.edit}
</button>
) : null}
{canRetract ? (
@@ -82,7 +83,7 @@ export function EntryActions({
onClick={() => setMode('retract')}
className="font-condensed text-accent"
>
{de.entry.retract}
{entryText.retract}
</button>
) : null}
</div>
@@ -103,7 +104,7 @@ export function EntryActions({
<input
value={reason}
onChange={(event) => setReason(event.target.value)}
placeholder={mode === 'edit' ? de.entry.changeReason : de.entry.retractReason}
placeholder={mode === 'edit' ? entryText.changeReason : entryText.retractReason}
className="mt-2 block w-full border border-line bg-raised px-2 py-1"
/>
@@ -120,7 +121,7 @@ export function EntryActions({
}
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
>
{pending ? de.case.saving : mode === 'edit' ? de.entry.editSave : de.entry.retract}
{pending ? caseText.saving : mode === 'edit' ? entryText.editSave : entryText.retract}
</button>
<button
type="button"
@@ -132,7 +133,7 @@ export function EntryActions({
}}
className="font-condensed text-text-dim"
>
{de.entry.cancel}
{entryText.cancel}
</button>
{error ? <span className="text-stamp-4">{error}</span> : null}
</div>
@@ -2,7 +2,7 @@
import { useOptimistic, useRef, useState, useTransition } from 'react'
import { uuidv7 } from 'uuidv7'
import { de } from '@/lib/i18n/de'
import { caseText, entryText } from '@/lib/i18n/cases'
import { addEntryAction } from '../actions'
type Pending = { id: string; body: string; failed: boolean }
@@ -52,7 +52,7 @@ export function EntryComposer({ caseNumber }: { caseNumber: string }) {
className="max-w-(--container-measure)"
>
<label htmlFor="vermerk" className="font-condensed text-xs text-text-dim">
{de.case.newEntry}
{caseText.newEntry}
</label>
<textarea
id="vermerk"
@@ -66,7 +66,7 @@ export function EntryComposer({ caseNumber }: { caseNumber: string }) {
}
}}
rows={3}
placeholder={de.case.entryPlaceholder}
placeholder={caseText.entryPlaceholder}
className="mt-1.5 block w-full border border-line bg-raised px-3 py-2 text-sm"
/>
<button
@@ -74,7 +74,7 @@ export function EntryComposer({ caseNumber }: { caseNumber: string }) {
disabled={pending || draft.trim().length === 0}
className="mt-2 border border-line bg-raised px-3 py-1.5 font-condensed text-xs text-accent disabled:text-text-dim"
>
{pending ? de.case.saving : de.entry.create}
{pending ? caseText.saving : entryText.create}
</button>
</form>
@@ -92,7 +92,7 @@ export function EntryComposer({ caseNumber }: { caseNumber: string }) {
{entry.body}
</p>
{entry.failed ? (
<p className="mt-1 font-condensed text-2xs text-stamp-4">{de.case.unsaved}</p>
<p className="mt-1 font-condensed text-2xs text-stamp-4">{caseText.unsaved}</p>
) : null}
</li>
))}
@@ -2,7 +2,8 @@
import { useState, useTransition } from 'react'
import Link from 'next/link'
import { de } from '@/lib/i18n/de'
import { participantText } from '@/lib/i18n/cases'
import { commonText } from '@/lib/i18n/common'
import { PARTICIPANT_ROLES } from '@/lib/cases/terms'
import { addParticipantAction, removeParticipantAction } from '../actions'
@@ -62,7 +63,7 @@ export function Participants({
return (
<div>
{participants.length === 0 ? (
<p className="text-text-dim">{de.participant.empty}</p>
<p className="text-text-dim">{participantText.empty}</p>
) : (
<ul className="border-t border-line">
{participants.map((person) => (
@@ -71,15 +72,15 @@ export function Participants({
className="flex flex-wrap items-baseline gap-x-4 gap-y-1 border-b border-line py-2"
>
<span className="font-condensed text-2xs text-text-dim">
{de.participant.roles[person.role] ?? person.role}
{participantText.roles[person.role] ?? person.role}
</span>
<span className="grow text-sm">
{person.personnelFileId ? (
<Link href={`/personalakten/${person.personnelFileId}`}>
{person.displayName ?? de.common.unknown}
{person.displayName ?? commonText.unknown}
</Link>
) : (
(person.displayName ?? de.common.unknown)
(person.displayName ?? commonText.unknown)
)}
</span>
{canEdit ? (
@@ -97,7 +98,7 @@ export function Participants({
}
className="font-condensed text-2xs text-text-dim"
>
{de.participant.remove}
{participantText.remove}
</button>
) : null}
</li>
@@ -111,36 +112,36 @@ export function Participants({
open ? (
<div className="mt-4 border border-line p-3">
<p className="max-w-(--container-measure) text-2xs text-text-dim">
{de.participant.hint}
{participantText.hint}
</p>
<div className="mt-3 flex flex-wrap items-center gap-2">
<select
value={role}
onChange={(event) => setRole(event.target.value)}
aria-label={de.participant.role}
aria-label={participantText.role}
className="border border-line bg-raised px-2 py-1 text-2xs"
>
{PARTICIPANT_ROLES.map((value) => (
<option key={value} value={value}>
{de.participant.roles[value] ?? value}
{participantText.roles[value] ?? value}
</option>
))}
</select>
<select
value={target}
onChange={(event) => setTarget(event.target.value)}
aria-label={de.participant.person}
aria-label={participantText.person}
className="border border-line bg-raised px-2 py-1 text-2xs"
>
<option value="">—</option>
<optgroup label={de.participant.pickUser}>
<optgroup label={participantText.pickUser}>
{members.map((member) => (
<option key={member.id} value={`user:${member.id}`}>
{member.displayName}
</option>
))}
</optgroup>
<optgroup label={de.participant.pickPersonnel}>
<optgroup label={participantText.pickPersonnel}>
{files.map((file) => (
<option key={file.id} value={`file:${file.id}`}>
{file.displayName}
@@ -154,14 +155,14 @@ export function Participants({
onClick={add}
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
>
{de.participant.add}
{participantText.add}
</button>
<button
type="button"
onClick={() => setOpen(false)}
className="font-condensed text-2xs text-text-dim"
>
{de.common.cancel}
{commonText.cancel}
</button>
</div>
</div>
@@ -171,7 +172,7 @@ export function Participants({
onClick={() => setOpen(true)}
className="mt-4 border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent"
>
{de.participant.add}
{participantText.add}
</button>
)
) : null}
+18 -1
View File
@@ -24,6 +24,9 @@ import { listDocuments, listTemplatesFor } from '@/lib/documents/service'
import { visiblePersonnelWhere } from '@/lib/access/personnelFilter'
import { DocumentList } from '@/components/documents/DocumentList'
import { NewDocument } from '@/components/documents/NewDocument'
import { Attachments } from '@/components/files/Attachments'
import { listAttachments } from '@/lib/files/service'
import { toAttachmentViews } from '@/lib/files/view'
import { allowedTargets, type CaseStatusName } from '@/lib/cases/lifecycle'
import { evaluateEntryEdit, canRetract } from '@/lib/cases/entryPolicy'
import Link from 'next/link'
@@ -155,10 +158,12 @@ async function Relations({
permissions: EffectivePermissions
canEdit: boolean
}) {
const [participants, links, documents, templates, levels, members, files] = await Promise.all([
const [participants, links, documents, anhaenge, templates, levels, members, files] =
await Promise.all([
listParticipants(permissions, akte.id),
listLinks(permissions, akte.id),
listDocuments(permissions, { caseId: akte.id }),
listAttachments(permissions, { caseId: akte.id }),
canEdit ? listTemplatesFor('CASE_DOCUMENT') : Promise.resolve([]),
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
canEdit
@@ -204,6 +209,18 @@ async function Relations({
</div>
</section>
<section className="md:col-span-2">
<h2 className="font-condensed">{de.attachment.heading}</h2>
<div className="mt-4">
<Attachments
target={{ caseNumber: akte.caseNumber }}
initial={toAttachmentViews(anhaenge)}
canUpload={canEdit}
canRelease={permissions.isAdmin}
/>
</div>
</section>
<section className="md:col-span-2">
<h2 className="font-condensed">{de.document.heading}</h2>
<div className="mt-4 space-y-4">
+8 -7
View File
@@ -1,7 +1,8 @@
'use client'
import { useActionState } from 'react'
import { de } from '@/lib/i18n/de'
import { caseText } from '@/lib/i18n/cases'
import { clearanceText } from '@/lib/i18n/common'
import { createCaseAction, type CreateState } from '../actions'
export function NewCaseForm({
@@ -21,7 +22,7 @@ export function NewCaseForm({
<form action={action} className="mt-6 space-y-5">
<div>
<label htmlFor="title" className="font-condensed text-xs text-text-dim">
{de.case.title}
{caseText.title}
</label>
<input
id="title"
@@ -35,7 +36,7 @@ export function NewCaseForm({
<div>
<label htmlFor="templateKey" className="font-condensed text-xs text-text-dim">
{de.case.type}
{caseText.type}
</label>
<select
id="templateKey"
@@ -53,7 +54,7 @@ export function NewCaseForm({
<div>
<label htmlFor="classification" className="font-condensed text-xs text-text-dim">
{de.clearance.classification}
{clearanceText.classification}
</label>
{/* Die Auswahl zeigt nur, was erlaubt ist. Geprüft wird trotzdem serverseitig. */}
<select
@@ -73,7 +74,7 @@ export function NewCaseForm({
{people.length > 0 ? (
<div>
<label htmlFor="personnelFileId" className="font-condensed text-xs text-text-dim">
{de.case.subject}
{caseText.subject}
</label>
{/* Gleich beim Anlegen verknüpfen erspart den zweiten Schritt, den
man sonst vergisst. Nachträglich geht es genauso. */}
@@ -83,7 +84,7 @@ export function NewCaseForm({
defaultValue=""
className="mt-1.5 block w-full border border-line bg-raised px-3 py-2 text-sm"
>
<option value="">{de.case.subjectNone}</option>
<option value="">{caseText.subjectNone}</option>
{people.map((person) => (
<option key={person.id} value={person.id}>
{person.displayName}
@@ -99,7 +100,7 @@ export function NewCaseForm({
disabled={pending}
className="border border-line bg-raised px-4 py-2 font-condensed text-xs text-accent disabled:text-text-dim"
>
{pending ? de.case.saving : de.case.create}
{pending ? caseText.saving : caseText.create}
</button>
{state.error ? (
<span className="font-condensed text-2xs text-stamp-4">{state.error}</span>