Neue Policy fuer Ersteller-Anzeige im Auftrag (Task 2/3 folgen). Bestehende
Assertion "Fahrer sieht nur das eigene Profil" testete eine Einschraenkung,
die dieses Feature bewusst aufhebt -- Erwartungswert und Titel angepasst,
statt der Policy, auf Anweisung des Plan-Autors.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCHRPWuV3bd37NJhW2NK6P
- Add migration 20260818120000_auftrag_fotos_optional_trigger.sql that replaces
check_auftrag_status_transition() function, removing ONLY the photo-count check
while preserving all other validation (start_km, end_km, uebergabe_bestaetigt_at,
status transitions, column lockdown, role-based restrictions)
- Update pgTAP test: plan(13) -> plan(12), replace photo-mandatory test with
test verifying transition succeeds without photos
- Completes DB-level optional photos feature (app-level optional already done in Task 1)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCHRPWuV3bd37NJhW2NK6P
Page and CSV export now both render shift timestamps in Europe/Berlin
consistently (previously CSV used UTC, page used server-local time,
causing the same shift to show different clock times in each place).
Also adds a partial unique index so two near-simultaneous Kommen
requests for the same fahrer can no longer create two open shifts --
the existing app-layer check was check-then-act with no DB backstop.
INSERT policy now requires a fahrer's own shift to start open and
uncorrected (geht_um/korrigiert_von/korrigiert_am all null) — closes a
gap where a fahrer could forge a pre-corrected row. Also shortens a
policy name that exceeded Postgres' 63-byte identifier limit and was
being silently truncated.
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>
Security review (automated scan + Task 11 reviewer) found a fahrer could
storniere their own assigned order because Task 2's fahrer UPDATE policy
only constrains zugewiesen_an, never status. Adds a role-gated check to
the status trigger (only admin/disponent may set status='storniert') plus
a pgTAP regression test. Also hardens fahrtBeenden/stornieren to check
affected-row counts instead of silently redirecting to a success page on
a blocked update.
Live-verified: fahrer storno attempt now rejected by the trigger; normal
fahrer fahrtBeenden flow unaffected. db reset + test db (21/21), build,
and npm test (17/17) all pass.
Final review found the RLS test suite only covered SELECT, never the
actual security-relevant path: a non-admin changing a profile's role.
Add pgTAP coverage for a fahrer's own-role UPDATE being blocked by RLS
(0 rows affected, role unchanged), the positive admin-can-update-others
case, and a regression test for handle_new_user() ignoring
raw_user_meta_data.role so a future edit reintroducing that read fails
loudly instead of quietly reopening the escalation hole.
Also add a migration giving the admin UPDATE policy an explicit
WITH CHECK (behavior unchanged, since Postgres already falls back to
USING for UPDATE policies without one) to document the pattern for
future sub-projects copying this RLS setup.