forked from fahrPool/fahrPool
fix: allow schaden photos during unterwegs and close final-review gaps
Final whole-branch review before merging feature/auftragsverwaltung found
two Important and three Minor issues, all fixed in this round:
- auftrag_fotos and storage.objects INSERT policies now split the
condition: Pflicht-positions still require status = 'zugewiesen', but
schaden photos may additionally be uploaded while status = 'unterwegs',
matching the spec's "jederzeit waehrend der Fahrt nachtragen" requirement.
- Added schadenFotoNachtragen server action + a page form so drivers can
actually use the new mid-trip upload window.
- Added supabase/tests/auftrag_fotos_rls_test.sql (12 pgTAP tests) covering
SELECT/INSERT RLS on both auftrag_fotos and storage.objects, including the
new unterwegs-schaden-allowed / unterwegs-pflicht-blocked cases.
- fahrtBeginnen now checks affected row count like fahrtBeenden/stornieren
instead of only checking `error`.
- /auftraege/neu now gates on role (admin/disponent) via loadProfile(),
redirecting non-privileged roles back to /auftraege with a visible error
(which now renders the error query param).
- Renamed the over-long storage INSERT policy name to stay under the 63
byte Postgres identifier limit.
Migrations were edited in place rather than layered with a new migration,
following the established precedent (55c4ac5) for pre-merge, not-yet-deployed
RLS fixes on this branch.
Verified: npx supabase db reset clean, npx supabase test db 33/33 passing
(was 21), npm run build and npm test green in web/, and a live rolled-back
SQL probe confirming a driver can insert a schaden photo but not a Pflicht
photo while status = 'unterwegs'.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
58e34a14a6
commit
c758dd2305
|
|
@ -44,6 +44,11 @@ create policy "Disponent Admin Readonly sehen alle Auftragsfotos"
|
|||
-- Insert/Upsert explizit auf die eigene auth.uid() setzen -- ein Insert
|
||||
-- ohne diesen Wert (uploaded_by bleibt NULL) scheitert an dieser Policy,
|
||||
-- da `null = auth.uid()` in Postgres nie wahr ist.
|
||||
-- Pflicht-Positionen (alles ausser "schaden") duerfen weiterhin nur beim
|
||||
-- Fahrtbeginn (status = 'zugewiesen') hochgeladen werden. "schaden"-Fotos
|
||||
-- duerfen laut Spec jederzeit waehrend der Fahrt nachgetragen werden, also
|
||||
-- zusaetzlich auch bei status = 'unterwegs' -- daher die zweigeteilte
|
||||
-- Bedingung statt eines einzelnen status = 'zugewiesen'.
|
||||
create policy "Fahrer laedt Fotos fuer eigenen zugewiesenen Auftrag hoch"
|
||||
on public.auftrag_fotos for insert
|
||||
with check (
|
||||
|
|
@ -53,7 +58,10 @@ create policy "Fahrer laedt Fotos fuer eigenen zugewiesenen Auftrag hoch"
|
|||
select 1 from public.auftraege
|
||||
where id = auftrag_fotos.auftrag_id
|
||||
and zugewiesen_an = auth.uid()
|
||||
and status = 'zugewiesen'
|
||||
and (
|
||||
(auftrag_fotos.position <> 'schaden' and status = 'zugewiesen')
|
||||
or (auftrag_fotos.position = 'schaden' and status in ('zugewiesen', 'unterwegs'))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,16 @@ create policy "Disponent Admin Readonly lesen alle Auftragsfotos im Storage"
|
|||
-- auftrag_fotos-INSERT-Policy aus Task 3): ohne dieses Praedikat wuerde
|
||||
-- die Policy fuer jede eingeloggte Rolle gelten, sobald deren auth.uid()
|
||||
-- zufaellig mit zugewiesen_an eines Auftrags uebereinstimmt.
|
||||
create policy "Fahrer laedt Fotos fuer eigenen zugewiesenen offenen Auftrag hoch"
|
||||
--
|
||||
-- Gleiche zweigeteilte Bedingung wie bei der auftrag_fotos-INSERT-Policy:
|
||||
-- Pflichtfotos nur bei status = 'zugewiesen', Schadensfotos zusaetzlich auch
|
||||
-- bei status = 'unterwegs'. Es gibt hier keine "position"-Spalte, nur den
|
||||
-- Dateipfad (`${auftragId}/${position}.jpg` bzw.
|
||||
-- `${auftragId}/schaden-<timestamp>-<i>.jpg`, siehe actions.ts) -- die
|
||||
-- Unterscheidung wird deshalb aus dem zweiten Pfadsegment abgeleitet.
|
||||
-- Policy-Name bewusst kurz gehalten (< 63 Byte, Postgres-Identifier-Limit)
|
||||
-- und nicht mehr auf "offen" bezogen, da sie jetzt auch fuer 'unterwegs' gilt.
|
||||
create policy "Fahrer laedt Auftragsfotos hoch"
|
||||
on storage.objects for insert
|
||||
with check (
|
||||
bucket_id = 'auftrag-fotos'
|
||||
|
|
@ -31,7 +40,10 @@ create policy "Fahrer laedt Fotos fuer eigenen zugewiesenen offenen Auftrag hoch
|
|||
select 1 from public.auftraege
|
||||
where id = (storage.foldername(name))[1]::uuid
|
||||
and zugewiesen_an = auth.uid()
|
||||
and status = 'zugewiesen'
|
||||
and (
|
||||
(split_part(name, '/', 2) not like 'schaden-%' and status = 'zugewiesen')
|
||||
or (split_part(name, '/', 2) like 'schaden-%' and status in ('zugewiesen', 'unterwegs'))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,211 @@
|
|||
begin;
|
||||
select plan(12);
|
||||
|
||||
insert into auth.users (id, email) values
|
||||
('aa111111-1111-1111-1111-111111111111', 'admin-fotos@auftraege.test.local'),
|
||||
('dd222222-2222-2222-2222-222222222222', 'disponent-fotos@auftraege.test.local'),
|
||||
('ff333333-3333-3333-3333-333333333333', 'fahrer-eins-fotos@auftraege.test.local'),
|
||||
('ff444444-4444-4444-4444-444444444444', 'fahrer-zwei-fotos@auftraege.test.local');
|
||||
|
||||
update public.profiles set role = 'admin' where id = 'aa111111-1111-1111-1111-111111111111';
|
||||
update public.profiles set role = 'disponent' where id = 'dd222222-2222-2222-2222-222222222222';
|
||||
update public.profiles set role = 'fahrer' where id = 'ff333333-3333-3333-3333-333333333333';
|
||||
update public.profiles set role = 'fahrer' where id = 'ff444444-4444-4444-4444-444444444444';
|
||||
|
||||
insert into public.orte (id, adresse, ansprechpartner) values
|
||||
('20111111-1111-1111-1111-111111111111', 'Hauptstr. 1, Musterstadt', 'Frau Muster'),
|
||||
('20222222-2222-2222-2222-222222222222', 'Nebenweg 2, Musterstadt', 'Herr Beispiel');
|
||||
|
||||
insert into public.fahrzeuge (id, kennzeichen) values
|
||||
('20333333-0000-0000-0000-000000000001', 'M-EF 789');
|
||||
|
||||
-- Auftrag A: dem Fahrer "eins" zugewiesen, status = 'zugewiesen' -- fuer die
|
||||
-- "eigener, noch nicht gestarteter Auftrag"-Faelle (Pflichtfoto UND
|
||||
-- Schadensfoto duerfen hier hochgeladen werden).
|
||||
insert into public.auftraege (
|
||||
id, abholort_id, zielort_id, fahrzeug_id, erstellt_von, status, zugewiesen_an, start_km
|
||||
) values (
|
||||
'20000000-0000-0000-0000-000000000001',
|
||||
'20111111-1111-1111-1111-111111111111',
|
||||
'20222222-2222-2222-2222-222222222222',
|
||||
'20333333-0000-0000-0000-000000000001',
|
||||
'dd222222-2222-2222-2222-222222222222',
|
||||
'zugewiesen',
|
||||
'ff333333-3333-3333-3333-333333333333',
|
||||
1000
|
||||
);
|
||||
|
||||
-- Auftrag B: dem Fahrer "zwei" zugewiesen -- aus Sicht von Fahrer "eins" ein
|
||||
-- fremder Auftrag, fuer die SELECT- und INSERT-RLS-Blockade-Faelle.
|
||||
insert into public.auftraege (
|
||||
id, abholort_id, zielort_id, fahrzeug_id, erstellt_von, status, zugewiesen_an, start_km
|
||||
) values (
|
||||
'20000000-0000-0000-0000-000000000002',
|
||||
'20111111-1111-1111-1111-111111111111',
|
||||
'20222222-2222-2222-2222-222222222222',
|
||||
'20333333-0000-0000-0000-000000000001',
|
||||
'dd222222-2222-2222-2222-222222222222',
|
||||
'zugewiesen',
|
||||
'ff444444-4444-4444-4444-444444444444',
|
||||
500
|
||||
);
|
||||
|
||||
-- Auftrag C: dem Fahrer "eins" zugewiesen, aber direkt mit status =
|
||||
-- 'unterwegs' angelegt (per INSERT, nicht per UPDATE) -- der
|
||||
-- Status-Uebergangstrigger aus Task 4 feuert nur BEFORE UPDATE, daher
|
||||
-- umgeht ein INSERT mit bereits gesetztem Zielstatus die "alle 8
|
||||
-- Pflichtfotos muessen existieren"-Vorbedingung. Das haelt diese Testdatei
|
||||
-- unabhaengig von auftraege_rls_test.sql und fokussiert sie ausschliesslich
|
||||
-- auf die auftrag_fotos/storage.objects-Policies statt auf den Trigger.
|
||||
insert into public.auftraege (
|
||||
id, abholort_id, zielort_id, fahrzeug_id, erstellt_von, status, zugewiesen_an, start_km
|
||||
) values (
|
||||
'20000000-0000-0000-0000-000000000003',
|
||||
'20111111-1111-1111-1111-111111111111',
|
||||
'20222222-2222-2222-2222-222222222222',
|
||||
'20333333-0000-0000-0000-000000000001',
|
||||
'dd222222-2222-2222-2222-222222222222',
|
||||
'unterwegs',
|
||||
'ff333333-3333-3333-3333-333333333333',
|
||||
2000
|
||||
);
|
||||
|
||||
-- Ein Foto + ein Storage-Objekt fuer Auftrag B, als postgres (RLS-frei)
|
||||
-- angelegt, damit die SELECT-RLS-Tests unten etwas zu verstecken haben.
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values (
|
||||
'20000000-0000-0000-0000-000000000002',
|
||||
'front',
|
||||
'20000000-0000-0000-0000-000000000002/front.jpg',
|
||||
'ff444444-4444-4444-4444-444444444444'
|
||||
);
|
||||
|
||||
insert into storage.buckets (id, name, public) values ('auftrag-fotos', 'auftrag-fotos', false)
|
||||
on conflict (id) do nothing;
|
||||
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000002/front.jpg', 'ff444444-4444-4444-4444-444444444444');
|
||||
|
||||
set local role authenticated;
|
||||
set local request.jwt.claims to '{"sub": "ff333333-3333-3333-3333-333333333333", "role": "authenticated"}';
|
||||
|
||||
-- 1) SELECT-RLS auftrag_fotos: Fahrer "eins" sieht keine Fotos des Fahrer
|
||||
-- "zwei" zugewiesenen (fremden) Auftrags B.
|
||||
select is_empty(
|
||||
$$ select id from public.auftrag_fotos where auftrag_id = '20000000-0000-0000-0000-000000000002' $$,
|
||||
'Fahrer sieht keine auftrag_fotos-Zeilen eines nicht zugewiesenen (fremden) Auftrags'
|
||||
);
|
||||
|
||||
-- 2) INSERT-RLS auftrag_fotos: Fahrer "eins" kann kein Foto fuer den
|
||||
-- fremden Auftrag B hochladen.
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values ('20000000-0000-0000-0000-000000000002', 'schaden', '20000000-0000-0000-0000-000000000002/schaden-x.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'42501',
|
||||
'new row violates row-level security policy for table "auftrag_fotos"',
|
||||
'Fahrer kann kein Foto fuer einen fremden/nicht zugewiesenen Auftrag hochladen (auftrag_fotos INSERT-RLS)'
|
||||
);
|
||||
|
||||
-- 3) Pflichtfoto bei status = 'zugewiesen' (Auftrag A) gelingt weiterhin.
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values ('20000000-0000-0000-0000-000000000001', 'front', '20000000-0000-0000-0000-000000000001/front.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Pflichtfoto fuer den eigenen Auftrag bei status = zugewiesen hochladen'
|
||||
);
|
||||
|
||||
-- 4) Pflichtfoto bei status = 'unterwegs' (Auftrag C) bleibt verboten.
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values ('20000000-0000-0000-0000-000000000003', 'front', '20000000-0000-0000-0000-000000000003/front.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'42501',
|
||||
'new row violates row-level security policy for table "auftrag_fotos"',
|
||||
'Fahrer kann ein Pflichtfoto NICHT hochladen, wenn der eigene Auftrag bereits status = unterwegs hat'
|
||||
);
|
||||
|
||||
-- 5) Schadensfoto bei status = 'zugewiesen' (Auftrag A) gelingt (bereits
|
||||
-- bisheriges Verhalten).
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values ('20000000-0000-0000-0000-000000000001', 'schaden', '20000000-0000-0000-0000-000000000001/schaden-1.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Schadensfoto fuer den eigenen Auftrag bei status = zugewiesen hochladen'
|
||||
);
|
||||
|
||||
-- 6) Schadensfoto bei status = 'unterwegs' (Auftrag C) gelingt jetzt auch --
|
||||
-- das ist das neue Verhalten aus dieser Fix-Runde (Important 1).
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into public.auftrag_fotos (auftrag_id, position, storage_path, uploaded_by)
|
||||
values ('20000000-0000-0000-0000-000000000003', 'schaden', '20000000-0000-0000-0000-000000000003/schaden-1.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Schadensfoto fuer den eigenen Auftrag AUCH bei status = unterwegs nachtragen (neues Verhalten)'
|
||||
);
|
||||
|
||||
-- 7) SELECT-RLS storage.objects: Fahrer "eins" sieht kein Storage-Objekt
|
||||
-- des fremden Auftrags B.
|
||||
select is_empty(
|
||||
$$ select id from storage.objects where bucket_id = 'auftrag-fotos' and name like '20000000-0000-0000-0000-000000000002/%' $$,
|
||||
'Fahrer sieht kein storage.objects-Objekt eines nicht zugewiesenen (fremden) Auftrags'
|
||||
);
|
||||
|
||||
-- 8) INSERT-RLS storage.objects: Fahrer "eins" kann kein Foto-Objekt fuer
|
||||
-- den fremden Auftrag B hochladen.
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000002/schaden-x.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'42501',
|
||||
'new row violates row-level security policy for table "objects"',
|
||||
'Fahrer kann kein Storage-Objekt fuer einen fremden/nicht zugewiesenen Auftrag hochladen (storage.objects INSERT-RLS)'
|
||||
);
|
||||
|
||||
-- 9) Pflicht-Pfad bei status = 'zugewiesen' (Auftrag A) gelingt weiterhin.
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000001/seitlich_rechts.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Pflicht-Foto-Objekt fuer den eigenen Auftrag bei status = zugewiesen hochladen'
|
||||
);
|
||||
|
||||
-- 10) Pflicht-Pfad bei status = 'unterwegs' (Auftrag C) bleibt verboten.
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000003/seitlich_rechts.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'42501',
|
||||
'new row violates row-level security policy for table "objects"',
|
||||
'Fahrer kann ein Pflicht-Foto-Objekt NICHT hochladen, wenn der eigene Auftrag bereits status = unterwegs hat'
|
||||
);
|
||||
|
||||
-- 11) Schaden-Pfad (Dateiname-Praefix "schaden-") bei status = 'zugewiesen'
|
||||
-- gelingt (bisheriges Verhalten).
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000001/schaden-1.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Schaden-Foto-Objekt fuer den eigenen Auftrag bei status = zugewiesen hochladen'
|
||||
);
|
||||
|
||||
-- 12) Schaden-Pfad bei status = 'unterwegs' gelingt jetzt auch -- neues
|
||||
-- Verhalten aus dieser Fix-Runde (Important 1), analog zu Test 6.
|
||||
select lives_ok(
|
||||
$$
|
||||
insert into storage.objects (bucket_id, name, owner)
|
||||
values ('auftrag-fotos', '20000000-0000-0000-0000-000000000003/schaden-1.jpg', 'ff333333-3333-3333-3333-333333333333')
|
||||
$$,
|
||||
'Fahrer kann ein Schaden-Foto-Objekt fuer den eigenen Auftrag AUCH bei status = unterwegs nachtragen (neues Verhalten)'
|
||||
);
|
||||
|
||||
select * from finish();
|
||||
rollback;
|
||||
|
|
@ -114,13 +114,61 @@ export async function fahrtBeginnen(auftragId: string, formData: FormData): Prom
|
|||
}
|
||||
}
|
||||
|
||||
const { error } = await supabase
|
||||
const { data, error } = await supabase
|
||||
.from("auftraege")
|
||||
.update({ status: "unterwegs", start_km: validation.startKm })
|
||||
.eq("id", auftragId);
|
||||
.eq("id", auftragId)
|
||||
.select("id");
|
||||
|
||||
if (error) {
|
||||
redirect(`/auftraege/${auftragId}?error=${encodeURIComponent(error.message)}`);
|
||||
if (error || !data || data.length === 0) {
|
||||
redirect(
|
||||
`/auftraege/${auftragId}?error=${encodeURIComponent(
|
||||
error ? error.message : "Fahrt konnte nicht begonnen werden (keine Berechtigung oder Auftrag nicht mehr im Status zugewiesen)."
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
redirect(`/auftraege/${auftragId}`);
|
||||
}
|
||||
|
||||
export async function schadenFotoNachtragen(auftragId: string, formData: FormData): Promise<void> {
|
||||
const supabase = await createClient();
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const schadenFiles = formData.getAll("foto_schaden").filter((f): f is File => f instanceof File && f.size > 0);
|
||||
|
||||
if (schadenFiles.length === 0) {
|
||||
redirect(`/auftraege/${auftragId}?error=${encodeURIComponent("Bitte mindestens ein Schadensfoto auswaehlen.")}`);
|
||||
}
|
||||
|
||||
// Gleicher Upload-Code-Pfad wie fuer die optionalen Schadensfotos in
|
||||
// fahrtBeginnen: Storage-Upload gefolgt von einem expliziten
|
||||
// auftrag_fotos-Insert mit position = "schaden", Fehler jeweils explizit
|
||||
// geprueft. Kein Statuswechsel und keine Pflichtfoto-Validierung hier --
|
||||
// diese Aktion darf laut Spec jederzeit waehrend der Fahrt (status =
|
||||
// 'unterwegs', aber auch weiterhin 'zugewiesen') Schadensfotos nachtragen.
|
||||
for (let i = 0; i < schadenFiles.length; i++) {
|
||||
const path = `${auftragId}/schaden-${Date.now()}-${i}.jpg`;
|
||||
const { error: uploadError } = await supabase.storage.from("auftrag-fotos").upload(path, schadenFiles[i]);
|
||||
if (uploadError) {
|
||||
redirect(
|
||||
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Upload fehlgeschlagen: ${uploadError.message}`)}`
|
||||
);
|
||||
}
|
||||
const { error: fotoError } = await supabase
|
||||
.from("auftrag_fotos")
|
||||
.insert({ auftrag_id: auftragId, position: "schaden", storage_path: path, uploaded_by: user.id });
|
||||
if (fotoError) {
|
||||
redirect(
|
||||
`/auftraege/${auftragId}?error=${encodeURIComponent(`Foto-Speichern fehlgeschlagen: ${fotoError.message}`)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
redirect(`/auftraege/${auftragId}`);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import Link from "next/link";
|
|||
import { loadAuftrag, findeFolgeauftrag } from "@/lib/auftraege/queries";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
import { PFLICHT_FOTO_POSITIONEN } from "@/lib/auftraege/foto-positionen";
|
||||
import { uebernehmen, fahrtBeginnen, fahrtBeenden, stornieren } from "./actions";
|
||||
import { uebernehmen, fahrtBeginnen, schadenFotoNachtragen, fahrtBeenden, stornieren } from "./actions";
|
||||
|
||||
export default async function AuftragDetailPage({
|
||||
params,
|
||||
|
|
@ -32,6 +32,7 @@ export default async function AuftragDetailPage({
|
|||
|
||||
const uebernehmenAction = uebernehmen.bind(null, auftrag.id);
|
||||
const fahrtBeginnenAction = fahrtBeginnen.bind(null, auftrag.id);
|
||||
const schadenFotoNachtragenAction = schadenFotoNachtragen.bind(null, auftrag.id);
|
||||
const fahrtBeendenAction = fahrtBeenden.bind(null, auftrag.id);
|
||||
const stornierenAction = stornieren.bind(null, auftrag.id);
|
||||
|
||||
|
|
@ -94,6 +95,24 @@ export default async function AuftragDetailPage({
|
|||
</form>
|
||||
)}
|
||||
|
||||
{auftrag.status === "unterwegs" && istEigenerAuftrag && (
|
||||
<form action={schadenFotoNachtragenAction} encType="multipart/form-data">
|
||||
<h2>Schadensfoto nachtragen</h2>
|
||||
<div>
|
||||
<label htmlFor="foto_schaden_nachtrag">Schadensfotos (mehrere möglich)</label>
|
||||
<input
|
||||
id="foto_schaden_nachtrag"
|
||||
name="foto_schaden"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<button type="submit">Foto nachtragen</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{auftrag.status === "abgeschlossen" && folgeauftrag && (
|
||||
<p>
|
||||
Anschlussauftrag verfügbar: <Link href={`/auftraege/${folgeauftrag.id}`}>Jetzt übernehmen</Link>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,26 @@
|
|||
import { redirect } from "next/navigation";
|
||||
import { createAuftrag } from "./actions";
|
||||
import { listOrte, listFahrzeuge } from "@/lib/auftraege/queries";
|
||||
import { loadProfile } from "@/lib/auth/profile";
|
||||
|
||||
export default async function NeuerAuftragPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ error?: string; vorgaenger_auftrag_id?: string }>;
|
||||
}) {
|
||||
const profileResult = await loadProfile();
|
||||
// Seitenebenen-Gate zusaetzlich zur INSERT-RLS-Policy auf `auftraege`
|
||||
// (admin/disponent-only): ohne diesen Check wuerde die Seite das Formular
|
||||
// auch Fahrern/Readonly anzeigen, obwohl ein Submit dann ohnehin an der
|
||||
// RLS-Policy scheitern wuerde -- das ist verwirrend UX statt eines echten
|
||||
// Sicherheitslecks, aber ein frueher Redirect ist die klarere Loesung.
|
||||
if (
|
||||
profileResult.status !== "ok" ||
|
||||
(profileResult.profile.role !== "admin" && profileResult.profile.role !== "disponent")
|
||||
) {
|
||||
redirect(`/auftraege?error=${encodeURIComponent("Nur Disponent/Admin duerfen Auftraege anlegen.")}`);
|
||||
}
|
||||
|
||||
const { error, vorgaenger_auftrag_id } = await searchParams;
|
||||
const [orte, fahrzeuge] = await Promise.all([listOrte(), listFahrzeuge()]);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ import { loadProfile } from "@/lib/auth/profile";
|
|||
import { listAuftraegeFuerListe } from "@/lib/auftraege/queries";
|
||||
import { AuftragListe } from "@/components/AuftragListe";
|
||||
|
||||
export default async function AuftraegePage() {
|
||||
export default async function AuftraegePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ error?: string }>;
|
||||
}) {
|
||||
const { error } = await searchParams;
|
||||
const profileResult = await loadProfile();
|
||||
if (profileResult.status !== "ok") {
|
||||
return null;
|
||||
|
|
@ -16,6 +21,7 @@ export default async function AuftraegePage() {
|
|||
return (
|
||||
<main>
|
||||
<h1>Aufträge</h1>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
{kannAnlegen && <Link href="/auftraege/neu">Neuen Auftrag anlegen</Link>}
|
||||
{istFahrer ? (
|
||||
<>
|
||||
|
|
|
|||
Loading…
Reference in New Issue