1
0
Fork 0
Commit Graph

245 Commits

Author SHA1 Message Date
Jonny c98e4ef28f feat: add mobile drawer navigation and restyle header 2026-07-06 11:54:02 +02:00
Jonny 11c893e1b9 feat: add UI primitives (Button, Card, Alert, FormField) and restyle login page 2026-07-06 11:37:15 +02:00
Jonny 83cbba1635 fix: remove unspecified .color-palette utility from globals.css 2026-07-06 11:29:03 +02:00
Jonny 2ab34dce92 feat: add Tailwind CSS v4 with Widmann brand tokens and Inter font 2026-07-06 10:05:49 +02:00
Jonny cdacc76fb4 docs: add design-system implementation plan
7 tasks: Tailwind v4 setup + brand tokens, UI primitives + login,
mobile drawer navigation, dashboard, Aufträge-Liste + StatusBadge,
Auftrag-Detail, Auftrag-anlegen. Pure presentation layer, no
Server-Action/RLS/schema changes.
2026-07-06 09:55:23 +02:00
Jonny 7f1df79b41 docs: add design-system spec (mobile-first, Widmann-Branding)
Brand tokens (colors, Inter font) extracted directly from widmannbewegt.de's
production CSS; logo SVG saved for later use. Covers layout/nav, reusable
UI primitives, and page-by-page application as a pure presentation-layer
sub-project on top of the existing Fundament and Auftragsverwaltung features.
2026-07-06 09:42:06 +02:00
Jonny c758dd2305 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>
2026-07-06 06:57:22 +02:00
Jonny 58e34a14a6 fix: close stornieren RLS gap and harden fahrtBeenden/stornieren
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.
2026-07-06 06:22:53 +02:00
Jonny 0334fb4f10 docs: fix stornieren RLS gap and fahrtBeenden silent-noop found by security review
Task 2's fahrer UPDATE policy only constrains zugewiesen_an in its
WITH CHECK, not the status value itself, so a fahrer could set their
own assigned order straight to 'storniert' even though the spec
reserves cancellation for Disponent/Admin. Live-verified the gap
(UPDATE 1 as fahrer before the fix). Extends Task 4's trigger with a
role-gated check on the 'storniert' target status plus a regression
test (plan(12) -> plan(13)). Also hardens fahrtBeenden/stornieren in
Task 11 to check affected-row counts (matching uebernehmen's existing
pattern) instead of silently "succeeding" when RLS blocks a write for
an unauthorized caller.
2026-07-05 22:43:10 +02:00
Jonny 4459a6cfcb feat: add fahrt-beenden, stornieren and folgeauftrag suggestion
Adds fahrtBeenden (unterwegs -> abgeschlossen with end_km validation)
and stornieren (any non-terminal status -> storniert) Server Actions,
plus findeFolgeauftrag to surface a linked follow-up order on the
detail page once an order is abgeschlossen.

kannStornieren uses a local admin/disponent role check rather than
canManageUsers, since the latter is scoped to user management and
would incorrectly hide the storno action from disponents.
2026-07-05 22:36:19 +02:00
Jonny ad15af965b docs: fix fahrtBeginnen photo write - upsert on partial index doesn't work
The plan's original upsert(onConflict: "auftrag_id,position") for
auftrag_fotos cannot work: PostgREST's onConflict generates an
unqualified ON CONFLICT clause that can't target Task 3's partial
unique index (position <> 'schaden'), and even a working ON CONFLICT
would hit RLS since only admin has UPDATE on auftrag_fotos. Switched
to plain insert with checked errors on both write paths, consistent
with the spec's "Loeschen/Ersetzen nur durch Admin" rule.
2026-07-05 22:19:02 +02:00
Jonny 89564e527d feat: add auftrag detail page with uebernehmen and fahrt-beginnen actions
fahrtBeginnen uses plain insert (not upsert) for auftrag_fotos writes:
the partial unique index from Task 3 (where position <> 'schaden') can't
be targeted by PostgREST's onConflict option (Postgres 42P10), and
fahrer have no UPDATE grant on auftrag_fotos anyway, so an upsert's
DO UPDATE branch could never succeed for them. Verified live against
the local Supabase stack that the original upsert-based approach
silently wrote zero photo rows, blocking every real fahrtBeginnen
attempt at the DB trigger.
2026-07-05 22:16:54 +02:00
Jonny d292d122c9 feat: add auftraege list page with role-aware sections 2026-07-05 21:45:27 +02:00
Jonny e85e9ce993 feat: add auftrag creation page and server action 2026-07-05 17:49:48 +02:00
Jonny 36e65cad48 feat: add server-side data access helpers for auftraege 2026-07-05 17:32:05 +02:00
Jonny 225504f3a9 feat: add fahrt validation helpers for km and required photos 2026-07-05 17:20:40 +02:00
Jonny 4407c6de0c feat: add auftrag-fotos storage bucket with RLS policies 2026-07-05 17:12:18 +02:00
Jonny e52a499b71 docs: fix invalid hex digit in readonly test-fixture UUID (r -> 0) 2026-07-05 17:03:28 +02:00
Jonny dd725b5027 feat: add auftrag status transition trigger with pgTAP coverage 2026-07-05 17:01:43 +02:00
Jonny bb4f276c72 feat: add auftrag_fotos table with RLS and required-photo constraint 2026-07-05 16:47:26 +02:00
Jonny 55c4ac5949 fix: gate auftraege RLS policies on user_role() to close readonly claim gap
Security review found two RLS gaps in the auftraege migration that exactly
followed the (flawed) plan:

- The fahrer UPDATE policy had no public.user_role() = 'fahrer' predicate,
  so any authenticated user -- including a readonly-role account (the
  default role for new signups) -- could self-assign any open order via
  the "status = 'offen'" branch of USING, since all app roles share the
  same Postgres role and only user_role() distinguishes them.
- The disponent/admin INSERT policy did not bind erstellt_von to
  auth.uid(), allowing a spoofed creator id on insert.

Adds public.user_role() = 'fahrer' to both USING and WITH CHECK on the
fahrer UPDATE policy, and erstellt_von = auth.uid() to the INSERT policy's
WITH CHECK. Column-level lockdown (fahrer changing abholort_id etc.) is
intentionally deferred to Task 4's trigger, not addressed here.

Verified behaviorally: with the pre-fix policy, a readonly-role user could
claim an open order (UPDATE 1); with the fix, the same attempt affects 0
rows. Migration amended in place since it was never applied outside this
local dev stack.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-05 11:27:27 +02:00
Jonny b576c4e3b1 docs: fix RLS role-gating gaps found by automated security review
The fahrer UPDATE policy on auftraege, the fahrer INSERT policy on
auftrag_fotos, and the storage upload policy all lacked an explicit
public.user_role() = 'fahrer' predicate, so any authenticated role
(including the default readonly signup role) could exploit the
status='offen' clause to self-assign open orders. Also adds identity
binding (erstellt_von/uploaded_by = auth.uid()) on inserts, and a
column-lockdown check in Task 4's trigger so a fahrer can't smuggle
changes to abholort_id/zielort_id/fahrzeug_id/erstellt_von/
vorgaenger_auftrag_id into an otherwise-legitimate update.
2026-07-05 11:18:58 +02:00
Jonny 8ed34cfa96 feat: add auftraege table with status enum and RLS 2026-07-05 11:08:47 +02:00
Jonny 0850f0ccfc feat: add orte and fahrzeuge lookup tables with RLS 2026-07-05 10:59:55 +02:00
Jonny f9bddc01a8 docs: add implementation plan for auftragsverwaltung sub-project
11 tasks covering the orte/fahrzeuge lookup pools, the auftraege
core table with RLS and a DB-enforced status transition trigger,
photo storage with RLS, and the driver/dispatcher-facing pages.
2026-07-05 10:53:57 +02:00
Jonny e9c9c36448 docs: add design spec for Auftragsverwaltung sub-project
Covers the full order lifecycle (create, assign, driver pickup with
km/photos, dropoff, vehicle chaining) building on the auth/roles
foundation, scoped separately from Kanban board, routing, and full
time tracking per CLAUDE.md's independent feature list.
2026-07-05 10:36:08 +02:00
Jonny bf7af326f4 docs: add root setup README and fix stale auth.user_role() reference
There was no end-to-end runbook for getting from a fresh clone to a
running dev environment -- the sequence was scattered across script
comments and .env.example. Add a root README.md covering secrets
generation, template rendering, docker compose up, migrations, first
admin user creation, and the non-Docker web/ dev alternative, plus a
heads-up that the admin@aushilfsfahrer.local test password was reset
out-of-band during implementation and isn't recorded anywhere.

Replace web/README.md's untouched create-next-app boilerplate (which
mentioned yarn/pnpm/bun and "Deploy on Vercel") with a one-line pointer
to the root README, since it was actively misleading for this
self-hosted Docker project.

Also fix the design spec still naming the helper auth.user_role() --
it was renamed to public.user_role() during Task 3 due to the
auth-schema lockdown; the migrations and plan already reflect this.
2026-07-05 00:45:39 +02:00
Jonny d03052ca73 test: cover profiles UPDATE RLS boundary and privilege-escalation trigger
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.
2026-07-05 00:45:27 +02:00
Jonny d812db7da3 fix: fall back to NEXT_PUBLIC_SUPABASE_URL when SUPABASE_INTERNAL_URL is unset
Adds graceful degradation for environments that don't have SUPABASE_INTERNAL_URL
configured. Uses nullish coalescing to fall back to NEXT_PUBLIC_SUPABASE_URL if
the new internal URL variable is unset, maintaining backward compatibility while
preserving the Docker-specific optimization.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-05 00:29:35 +02:00
Jonny 2f508ea5dd feat: containerize the Next.js app and wire it into docker-compose
Adds web/Dockerfile (multi-stage node:22-alpine build, standalone output)
and web/.dockerignore, and wires a `web` service into docker-compose.yaml
so the whole stack (self-hosted Supabase + Next.js) starts with a single
`docker compose up -d`.

Networking fix: Next.js inlines NEXT_PUBLIC_* env vars at build time into
every compiled bundle, including server-side ones (Server Actions, Server
Components, Middleware) - not just the browser bundle. Since
NEXT_PUBLIC_SUPABASE_URL must point at the externally-reachable
http://localhost:8000 for the browser, the server-side Supabase clients in
lib/supabase/server.ts and lib/supabase/middleware.ts got that same literal
baked in - which resolves to the web container itself (not kong) once
running in Docker, causing ECONNREFUSED on any server-side Supabase call
(most visibly signInWithPassword in the login server action).

Fix: introduce SUPABASE_INTERNAL_URL, a server-only env var without the
NEXT_PUBLIC_ prefix, so it's read at actual runtime rather than inlined at
build time. It points at http://kong:8000 in docker-compose.yaml (same
pattern already used by the studio service's internal SUPABASE_URL) and at
http://localhost:8000 in web/.env.local(.example) for non-Docker local dev,
where there's no container networking boundary. lib/supabase/client.ts
(browser-only) is untouched and keeps reading NEXT_PUBLIC_SUPABASE_URL.

Considered extra_hosts: ["localhost:host-gateway"] instead, but rejected it:
overriding what the literal string "localhost" resolves to inside a
container is unreliable (glibc's resolver typically still prioritizes the
container's own loopback), and is the kind of workaround that looks fixed
in a quick check and quietly breaks later.

Verified end-to-end against the running container via curl (unauth redirect,
real signInWithPassword through the login server action, authenticated
dashboard content, logout) with zero ECONNREFUSED in `docker compose logs
web` afterward, plus a local `npm run dev` smoke test to confirm non-Docker
development still works unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-05 00:25:01 +02:00
Jonny c236e61692 feat: add root layout, role-based navigation and dashboard 2026-07-04 16:14:53 +02:00
Jonny b397cb326b feat: add auth middleware with session refresh and redirects 2026-07-04 15:57:41 +02:00
Jonny 63866f7f50 feat: add login page with server action and validation 2026-07-04 15:47:54 +02:00
Jonny 7254923885 feat: add Supabase browser and server client helpers
- Add browser client helper (createClient) for client-side components
- Add server client helper (createClient) for server components and route handlers
- Add test for browser client functionality
- Update .gitignore to allow .env.local.example while ignoring .env*.local
- Install @supabase/supabase-js and @supabase/ssr packages

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:32:05 +02:00
Jonny a8ca6445cb fix: add reproducible render step for kong.yml and 99-roles.sql templates
generate-secrets.js only printed the four secret env vars; nothing rendered
volumes/db/init/99-roles.sql or volumes/api/kong.yml from their committed
.template files, so a fresh clone following the brief's own setup steps
would hit the auth/rest/storage crash-loops and Kong 401s already
diagnosed during the original task.

Add scripts/render-templates.js, which reads .env and writes both rendered
files with the real secrets substituted in. Document the full sequence
(generate secrets -> fill .env -> render templates -> docker compose up)
in the header comments of generate-secrets.js and .env.example.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:24:49 +02:00
Jonny e0a3e756d8 feat: add self-hosted Supabase stack via Docker Compose
Produktions-Stack (db, auth, rest, storage, meta, studio, kong) getrennt
vom lokalen CLI-Dev-Stack. Migrationen aus Task 2/3 wurden erfolgreich
angewendet und ein erster Admin-Nutzer angelegt.

Abweichungen vom urspruenglichen Plan (alle beim Testen des laufenden
Stacks gefunden und verifiziert):
- generate-secrets.js: POSTGRES_PASSWORD nutzt base64url statt base64,
  da "/" in base64-Passwoertern die Postgres-Connection-URI-Parser von
  gotrue/storage-api bricht.
- volumes/db/init/99-roles.sql(.template): das supabase/postgres-Image
  setzt POSTGRES_PASSWORD nur fuer die Rolle supabase_admin automatisch;
  authenticator/supabase_auth_admin/supabase_storage_admin blieben ohne
  Passwort. Zusaetzliches Init-Skript setzt sie explizit.
- volumes/api/kong.yml(.template): Kong 3.9.1 substituiert KEINE
  Umgebungsvariablen ($ANON_KEY/$SERVICE_ROLE_KEY) im deklarativen
  Config-Format (_transform ist ein Config-Migrations-Flag, kein
  Env-Templating) - alle echten Keys wurden mit 401 abgelehnt. Die
  Kong-Config wird jetzt lokal aus dem Template mit echten Werten
  gerendert (gitignored), analog zu roles.sql.
- storage-Healthcheck: "localhost" statt "127.0.0.1" loeste im Container
  zuerst zu ::1 auf, worauf storage-api nicht lauscht.
- studio: HOSTNAME=0.0.0.0 gesetzt, da Docker HOSTNAME sonst auf die
  Container-ID setzt und das Next.js-Standalone-Image daran bindet statt
  an alle Interfaces (bricht den eingebauten Image-Healthcheck).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 12:35:08 +02:00
Jonny 16f8b09606 docs: correct plan for auth schema lockdown and missing grants
Self-hosted Supabase now revokes CREATE on the auth schema from the
migration role, so the RLS helper lives in public.user_role() instead
of auth.user_role(). Also documents the authenticated grants that
Task 2's schema was missing (RLS alone doesn't grant access).
2026-07-04 12:00:44 +02:00
Jonny d13994b386 feat: add RLS policies and pgTAP tests for profiles 2026-07-04 11:58:09 +02:00
Jonny 92adebd710 fix: never derive new user role from raw_user_meta_data (privilege escalation)
Fixes a CRITICAL finding from automated security review of a9e67ce: the
handle_new_user() trigger read the role from
new.raw_user_meta_data ->> 'role', which is attacker-controllable in
certain GoTrue flows (OAuth, invite links). A user could set
role: admin in their own signup metadata and self-escalate.

Every new user now always gets role = 'readonly' on creation; an admin
must explicitly promote via SQL/Table Editor afterwards (enforced later
by the "Admins aktualisieren alle Profile" RLS policy in Task 3).

Edited the already-applied migration file directly rather than adding a
new one, since this project has no deployment/production data yet.

Verified: inserting a user with raw_user_meta_data = {"role": "admin"}
still results in role = readonly in public.profiles.
2026-07-04 11:48:26 +02:00
Jonny 2f2f354402 docs: fix plan to prevent role privilege escalation via user metadata
Automated security review flagged that reading `role` from
raw_user_meta_data in the profiles trigger lets a user set their own
role at account-creation time in some GoTrue flows (OAuth, invites).
New users now always start as readonly; admins promote them
explicitly afterwards via SQL/table editor.
2026-07-04 11:42:16 +02:00
Jonny a9e67ce04d feat: add profiles table, role enum and auto-create trigger 2026-07-04 11:30:13 +02:00
Jonny 704fb83a58 chore: scaffold Next.js app with Vitest 2026-07-04 10:58:26 +02:00
Jonny 4b83a19552 chore: ignore .worktrees/ directory 2026-07-04 10:52:45 +02:00
Jonny a1e08fb1d0 docs: add implementation plan for foundation (auth & roles)
Nine-task plan covering Next.js scaffold, Supabase schema/RLS/pgTAP,
the self-hosted Docker Compose stack, and the login/middleware/
dashboard flow that later subprojects build on.
2026-07-04 10:38:25 +02:00
Jonny 0643bef299 chore: initial commit - requirements and foundation design spec
Sets up Aushilfsfahrer as its own repository with the project
requirements (CLAUDE.md) and the design spec for the foundation
subproject (auth, roles, infra).
2026-07-04 10:27:07 +02:00