Commit Graph
100 Commits
Author SHA1 Message Date
Leon Tonhäuser f899417b1e Update portal dependencies for security advisories 2026-11-30 19:30:30 +01:00
Leon Tonhäuser 69264ce165 Secure Sakani portal and show full album titles 2026-11-30 19:14:57 +01:00
Leon TonhäuserandClaude Opus 5.5 c40ccf77cf chore: drop parallel-run setup, document direct rollout and rollback
The UI goes live on the main domain directly, so the second-instance
compose file and the AUTO_RULE_SYNC_DISABLED switch are not needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:30:44 +01:00
Leon TonhäuserandClaude Opus 5.5 affa046b4a fix: name the editorial sidebar Redaktionsportal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:26:42 +01:00
Leon TonhäuserandClaude Opus 5.5 9e938e4d07 feat: redesign portal UI with Sakani UI and add release notes
Replace the hand-rolled Tailwind/shadcn look with Sakani UI across the
editorial area, the admin area and all signed-out pages.

- AppShell (Sakani Sidebar + TopBar) for /redaktion and /admin, with a
  mobile drawer, theme toggle, sign-out, legal links and a "Was ist neu"
  button; PublicShell for login, registration, password, 2FA and errors.
- Shared primitives (Button, Card, Input, PageHeader) now render Sakani;
  components/ui/sakani.tsx is the client boundary for Server Components
  (Sakani ships no "use client") and adds FormSelect (native form value)
  and DataTable (element cells from the server).
- Legacy CSS variables map onto Sakani tokens; globals.css shrinks from
  ~2200 to ~700 lines. Geist replaces Inter. recharts/lucide-react dropped
  (charts via Sakani BarChart).
- Release notes popup per area, shown once per version (localStorage) and
  reopenable from the sidebar; native <dialog> for focus trapping.
- Fixes found while testing: TOTP field reused the typed password in
  clear text, modal dialogs sat top-left, invisible unchecked checkboxes
  in dark mode.
- Parallel run: compose.parallel.yaml, AUTO_RULE_SYNC_DISABLED switch and
  docs/operations.md §8 (start, rollback, cutover).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:24:05 +01:00
Leon Tonhäuser 453bece72c docs: preserve deployment and migration notes 2026-11-30 16:42:10 +01:00
Leon Tonhäuser bdf6399b35 fix: skip inaccessible album grants in global search 2026-11-30 16:42:10 +01:00
Leon Tonhäuser abe072b2d1 feat: admin hints with auto-expiry shown in album overview 2026-09-11 17:30:15 +02:00
Leon Tonhäuser 2a5a2f3815 feat: show outstanding unbilled amount next to net price in editorial overview
Grouped SUM over usages with billingStatus open/reopened (same selectable
set as the billing page; voided excluded) per editorial, rendered as an
amber-highlighted 'Offen' suffix in each card footer.
2026-09-01 17:23:38 +02:00
Leon Tonhäuser 0931ffc777 feat: add admin albums tab with access overview and bulk grants
New /admin/alben page: all Immich albums with per-album editorial grant
chips (link + one-click revoke) and a bulk-grant form (multiple albums x
multiple editorials, select-all, search). bulkGrantAlbums validates album
existence once via listAlbums, skips already-active pairs, and commits
each pair in its own transaction with full audit attribution.
2026-09-01 17:17:02 +02:00
Leon Tonhäuser 0b65fbba16 fix: rebuild migration history as baseline so migrate works on prod
Squash the 13 historical migrations into one generated baseline whose
journal entry reuses the original 0000 timestamp: the migrator skips it
on every existing database (prod journal stuck at 0006) and applies it
only on fresh ones. Parity with the old chain verified via pg_dump diff
plus fresh/existing/prod-simulated drizzle-kit migrate runs. Historical
files move to drizzle-history/pre-squash-2026-08/ for integration tests
that exercise legacy migration behavior.

Also repair db tests that already failed before this change:
- raw SQL targeted users, but the table has always been "user"
- membership recheck mocked legacy getAsset.albums instead of searchPhotos
- audit rollback assertion walks drizzle's wrapped error cause chain
- keyset index probe pinned to NULLS LAST ordering, removing a planner
  cost tie-break that flipped with index creation order
2026-08-25 11:56:52 +02:00
Leon Tonhäuser 2949149170 docs: record prod migration-journal debt and two_factor field contract 2026-08-25 03:32:52 +02:00
Leon Tonhäuser 11cde23cdb fix: complete two_factor schema to full plugin field set
Adds failedVerificationCount and lockedUntil (brute-force tracking
maintained by the two-factor plugin). The adapter rejects any
two-factor endpoint while declared fields are missing from the drizzle
schema; verified was already added in the previous commit.
2026-08-25 03:27:51 +02:00
Leon Tonhäuser f42f4d5d2d fix: add missing two_factor.verified column required by plugin
The two-factor plugin reads/writes a verified boolean on the twoFactor
model (set true by verify-totp); without it the drizzle adapter rejects
every /two-factor/enable call.
2026-08-25 03:13:02 +02:00
Leon Tonhäuser 0d939593c8 feat: enforce admin 2FA, step-up auth, stronger password policy
Implements OWASP audit recommendations P1-P3:

P1 - Two-factor authentication (TOTP) mandatory for admins:
- better-auth twoFactor plugin; new two_factor table + user flag
  (migration 0010, MUST run before deploying the app)
- requireAdmin throws TWO_FACTOR_REQUIRED without a finished setup;
  pages redirect to the new /zwei-faktor wizard which uses a weak
  guard (allowWithoutTwoFactor) so admins can never lock themselves
  out. Wizard lives outside /admin to avoid layout redirect loops.
- login flow handles twoFactorRedirect and asks for the TOTP code;
  backup codes are shown once during enablement

P2 - Step-up for destructive operations (ASVS 2.5.4):
- hardDeleteEditorialAction and resetUsageDataAction reject sessions
  older than 15 minutes (SESSION_STALE) with actionable German
  messages instead of throwing opaque digests

P3 - Password policy (NIST 800-63B):
- minimum length raised from 8 to 12 plus common-password denylist,
  enforced for registration AND reset/change via a before-hook
2026-08-25 02:30:58 +02:00
Leon Tonhäuser 9308b46d84 feat: unarchive editorials and restore archived grants
Adds an "Archivierung aufheben" action on the editorial detail page:
clears the archive markers, reactivates suspended accounts and
re-activates exactly the album grants that were revoked by the archive
step (matched via the archive timestamp, skipping albums that received
a fresh active grant in the meantime).
2026-08-25 01:38:20 +02:00
Leon Tonhäuser c9d3f3d1dc feat: reset editorial usage data; fix hard delete FK order
Admins can now wipe an editorial's usage footprint (usages, download
events, billing reports incl. items and related audit rows) so test
accounts no longer pollute dashboard statistics. Grants, price, status
and login stay untouched; the action is confirmed by typing the
editorial name.

Hard delete previously failed with FK violations as soon as a usage had
ever been billed or an address saved:
- billing_report_items (restrict -> usages) were never deleted
- billing_address_versions were deleted before the referencing
  current_billing_address_version_id and their self-referencing
  superseded_by_id, both restrict

Both are now handled in correct FK order inside the transaction; the
audit trail of the deleted editorial is purged and verification tokens
are removed.
2026-08-25 01:28:34 +02:00
Leon Tonhäuser c6b69eb88d fix: survive empty-string env vars from compose
Docker Compose passes undeclared variables as empty strings
(CRON_SECRET="" etc.), which crashed env validation while loading the
instrumentation hook. A throwing register() made Next.js answer every
route with 500 while the process stayed alive.

- parse optional CRON_SECRET / AUTO_RULE_SYNC_INTERVAL_SECONDS via
  plain preprocess helpers that map blank strings to unset (zod v4
  does not accept preprocess-produced undefined through .optional())
- guard instrumentation register() so scheduler failures can never
  break request handling
2026-08-25 01:16:13 +02:00
Leon Tonhäuser dd60fd6ee6 feat: auto-assign new Immich albums via keyword rules
Auto-assignment rules were only applied when an admin clicked
"Regeln jetzt anwenden". New albums created in Immich therefore
never reached editorials automatically.

- applyAllRules() syncs every active editorial's keywords against the
  full album list in one pass and grants matches as system actor
- in-process scheduler (src/instrumentation.ts) runs the sync every
  AUTO_RULE_SYNC_INTERVAL_SECONDS (default 120s)
- POST /api/cron/album-sync allows external triggers via CRON_SECRET
- overlapping sync runs coalesce to avoid duplicate grants/emails
2026-08-25 01:05:04 +02:00
Leon Tonhäuser a3dc56778d fix: prioritize authorized search album 2026-08-12 17:58:27 +02:00
Leon Tonhäuser 9aa79cbce9 feat: enable downloads from search results 2026-08-12 16:45:42 +02:00
Leon Tonhäuser cccb214229 docs: plan search result downloads 2026-08-12 16:40:50 +02:00
Leon Tonhäuser 9903d18b84 docs: specify search result downloads 2026-08-12 16:38:30 +02:00
Leon Tonhäuser 61b1dbe350 fix: restore mobile menu active contrast 2026-08-11 18:01:16 +02:00
Leon Tonhäuser d8c3508db2 docs: plan mobile menu active contrast 2026-08-11 17:54:39 +02:00
Leon Tonhäuser 3e0221b149 docs: specify mobile menu active contrast 2026-08-11 17:53:36 +02:00
Leon Tonhäuser f7a311dece Merge branch 'codex/mobile-portal-navigation' 2026-08-11 17:41:17 +02:00
Leon Tonhäuser 60d5a95651 fix: keep mobile portal menu reachable 2026-08-11 17:35:26 +02:00
Leon Tonhäuser e328267763 fix: centralize protected page access 2026-08-11 17:31:23 +02:00
Leon Tonhäuser 844b8f7afd feat: add portal error recovery page 2026-08-11 17:17:09 +02:00
Leon Tonhäuser 0085c721af feat: expose portal navigation on mobile 2026-08-11 17:14:52 +02:00
Leon Tonhäuser 1279f46b1f fix: redirect expired portal sessions 2026-08-11 17:13:44 +02:00
Leon Tonhäuser 9089dce74a fix: size mobile portal menu controls 2026-08-11 17:11:32 +02:00
Leon Tonhäuser b1ef4a8186 docs: plan session expiry recovery 2026-08-11 17:10:42 +02:00
Leon Tonhäuser ec5ed8b22a feat: add accessible mobile portal menu 2026-08-11 17:06:23 +02:00
Leon Tonhäuser 56f21a5289 docs: specify session expiry recovery 2026-08-11 17:06:23 +02:00
Leon Tonhäuser a98c7bc8ee docs: plan mobile portal navigation 2026-08-11 17:02:43 +02:00
Leon Tonhäuser 3a1f4274a4 docs: specify mobile portal navigation 2026-08-11 16:49:47 +02:00
Leon Tonhäuser c1bd620d91 fix: link approval emails to sign-in 2026-08-11 16:30:51 +02:00
Leon Tonhäuser 60ef5ddab9 fix: use runtime legal page URLs 2026-08-11 16:17:34 +02:00
Leon Tonhäuser 86dfe8053d fix: harden production flows and user messaging 2026-08-11 16:07:13 +02:00
Leon Tonhäuser 52dce168dd style: add underline to acknowledgement links, update .env.example 2026-08-11 14:58:08 +02:00
Leon TonhäuserandClaude 21d41c7017 docs: record archiver v8 export-is-a-class gotcha in AI_MEMORY
Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:48:14 +02:00
Leon TonhäuserandClaude 5a76c4fbb4 fix: bulk-download 500 — archiver v8 export is a class, not a callable
archiver v8 changed its CJS export from a function to an object of class
constructors ({ Archiver, ZipArchive, TarArchive, JsonArchive }). The route
still called archiver('zip', opts), which throws `TypeError: archiver is not
a function` — a deterministic throw in the main flow, returning 500.

This was masked until the prior membership fix: before it, the empty
assetToGrantedAlbum map made the route 404 at "No valid assets found"
*before* reaching the archiver line. Once the map populated and downloads
were authorized, execution reached archiver('zip') and threw.

Fixed: `new archiver.ZipArchive({ zlib: { level: 0 } })` — same
pipe/append/finalize/abort interface. Verified the full round-trip
(append → finalize → Readable.toWeb → drain) produces a valid PK zip.

Also surface the server error code in DownloadLightboxForm so future
failures show the real code (status + {code}) in the browser console and
alert instead of a generic "Download fehlgeschlagen".

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:48:01 +02:00
Leon TonhäuserandClaude 8eadd1f408 fix: bulk-download repeat intents, error mapping, leaner membership map
The bulk-download handler still returned 500 after the membership fix.
Three issues:

1. Repeat downloads were broken: the handler passed priorUsages[0].id
   (the usage id) straight as downloadId, but claimAuthorized looks up
   download_events.id (the intent id) — so repeat assets never matched
   and were silently skipped. Now calls createRepeatDownload to mint a
   proper repeat intent, matching the single-download flow.

2. The catch block returned a generic 500 for every error, hiding the
   cause (the user only saw "Download fehlgeschlagen"). Added
   mappedBulkError so UsageAccountingError surfaces as its real code
   (503 IMMICH_UNAVAILABLE, 404 ASSET_NOT_IN_ALBUM, …) and the server
   log keeps the full stack.

3. The assetId→album map was built by fetching up to 1000 assets per
   granted album WITH withExif, then createNewUsage re-fetched per
   asset — heavy enough to time Immich out under load. The map only
   needs ids, so it now passes withExif:false (searchPhotos gained a
   withExif option, default true to preserve the gallery's orientation
   filter and masonry aspect ratios).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:40:27 +02:00
Leon TonhäuserandClaude ca5f79e193 docs: correct AI_MEMORY album-membership guidance for current Immich
getAlbum no longer returns assets on current Immich (AlbumService.get uses
{ withAssets: false }), so the old "getAlbum + iterate album.assets" best
practice is wrong and caused the download-404 bug. Document the
search/metadata id+albumIds membership check now in use.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:26:16 +02:00
Leon TonhäuserandClaude 6a31e5f411 fix: download 404 — Immich getAlbum no longer returns assets
The previous getAlbum fix (removing ?withoutAssets=true) was insufficient:
current Immich's GET /albums/:id NEVER returns assets — AlbumService.get
calls findOrFail with { withAssets: false } and the withoutAssets param is
gone. So album.assets was always empty and every download still failed with
ASSET_NOT_IN_ALBUM → 404. The AI_MEMORY "getAlbum + iterate album.assets"
guidance was stale (written for an older Immich API).

Membership is now verified via /search/metadata with an id + albumIds filter,
which returns the asset only if it belongs to the album. This is the
authoritative test (asset.albums is unreliable for older assets too).

- usages/service.ts: loadRequestedAlbum checks isAssetInAlbum via searchPhotos
  before fetching the album name; getAlbum now only provides albumName.
- bulk-download/route.ts: build the assetId→album map via searchPhotos per
  granted album instead of the empty getAlbum().assets iteration.
- immich client/types: add optional `id` to the searchPhotos input.
- tests: usages mocks now stub searchPhotos; the 13 pre-existing service
  test failures (mock returned getAlbum without assets → TypeError) are
  resolved — 20/20 pass.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:25:55 +02:00
Leon TonhäuserandClaude 962e2c7dc2 fix: download 404, next/image thumbnail 400, and cross-album search
Three production bugs on redaktionen.leon-tonhaeuser.de:

1. Download 404 (POST /api/download-intents → 404). getAlbum requested
   ?withoutAssets=true, so album.assets was always empty and the usages
   membership check (album.assets.some(id)) always failed → ASSET_NOT_IN_ALBUM
   → 404. Same root cause broke bulk-download's assetToGrantedAlbum map.
   Removed withoutAssets so consumers that authorize via album.assets get the
   real list; grants/thumbnail consumers ignore the extra data.

2. _next/image 400 on thumbnail proxy. next/image's optimizer choked on the
   watermarked streaming thumbnail response. Thumbnails are already
   server-resized to 800px, so the optimizer added nothing — switched
   leuchtkasten + admin AlbumGrid to plain <img>, matching photo-gallery.

3. Cross-album search "finds nothing". Immich albumIds is AND across albums
   (PR #18985): one /search/metadata call with all granted ids requires the
   asset to be in EVERY album, so single-album photos never match. Album-
   internal search passed one id so it worked. Fan out per granted album and
   merge; callers already paginate in-app.

Also drop the jahr filter from the album-internal search form (unnecessary
within a single album); backend still honors a jahr query param.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:12:19 +02:00
Leon TonhäuserandClaude f1ed89ea67 fix: remove duplicate legal links on login and registration pages
The root layout already renders <LegalFooter/> (Impressum, Datenschutz,
Nutzungsbedingungen) on every page. The login page defined its own local
LegalFooter with the same three links, and the registration form carried a
standalone Impressum link — so Impressum (and on login, all three) appeared
twice. Drop the redundant per-page copies; the global footer covers them.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 14:00:13 +02:00
Leon TonhäuserandClaude a7df6bd60a feat: redesign album overview to match photo grid + surface download/merkzettel errors
Album overview:
- AlbumContactSheet now uses cover tiles in the photo-gallery aesthetic:
  object-fit: cover, 4/3 tiles, persistent bottom gradient with album name
  + photo count, hover zoom. Drops the old 3:2 contain tiles + monospace
  caption strip.

Diagnostics (download + merkzettel both failed silently for the user):
- UsageDialog now reads the server's { code } from /api/download-intents and
  maps each stable error code (FORBIDDEN, NOT_FOUND, UPSTREAM_UNAVAILABLE,
  ACCOUNTING_UNAVAILABLE, ...) to a specific German message instead of the
  generic "try again". The fallback includes the raw code so unmapped
  failures stay actionable when reported back.
- LightboxToggleButton logs the caught server-action error to the console
  (and notes the dev terminal) instead of reverting the optimistic toggle
  with no signal. Root cause still needs the live error; this makes it
  visible.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 13:52:15 +02:00
Leon TonhäuserandClaude a3ec068cac feat: redesign photo overview (masonry + lightbox) and fix hoch/quer search
The album search could not distinguish portrait from landscape: the format
filter ran client-side over a single 60-item page and relied on exifInfo that
Immich never returned (no withExif flag), so the orientation guard fell
through and every photo matched every filter. Pagination links also dropped
format/jahr on the next page.

- immich/client: send withExif: true on /search/metadata so
  exifImageWidth/Height are populated for orientation filtering and masonry
  aspect ratios.
- albums/filter (new): filter + paginate across the full fetched set so total,
  page slice and has-more-pages stay consistent with active filters; both the
  album detail and the cross-album search pages use it.
- albums/photo-gallery (new client component): masonry grid with native
  EXIF aspect ratios (object-fit: cover, no more 3:2 letterboxing), hover
  overlay with filename/date + merken/lizenzieren/vergrößern, and a
  full-screen lightbox with keyboard nav (Esc/arrow keys).
- catalog-content: drop the old PhotoContactSheet; keep AlbumContactSheet and
  thread format/jahr through PhotoPagination links.
- Album detail search form restyled to the editorial design system (sharp ink
  borders) instead of the shadcn rounded card.
- Tests: filter.test.ts covers the orientation/year/pagination logic;
  catalog-content.test.tsx updated to the gallery + lightbox structure;
  immich client test expects withExif: true.

Skipped: global search form still uses shadcn styling (visually inconsistent
but functionally fixed); albums > 1000 photos lose tail items (noted with a
ponytail ceiling comment).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 13:36:46 +02:00
Leon Tonhäuser b81cd7c3e2 docs: update AI Memory with watermark, responsive emails and image styling quirks 2026-08-11 13:14:45 +02:00
Leon Tonhäuser dad8e07ec5 feat: responsive mobile email layouts with native dark mode support 2026-08-11 13:12:41 +02:00
Leon Tonhäuser fe2f82244d fix: resolve typescript compilation error with sharp buffer in thumbnail handler 2026-08-11 13:10:31 +02:00
Leon Tonhäuser 7e85b35486 fix: watermark svg xlink, object-contain for vertical images, remove duplicate search form 2026-08-11 13:07:30 +02:00
Leon Tonhäuser 986828893b fix: bypass broken asset.albums authorization check for thumbnails 2026-08-11 13:01:12 +02:00
Leon Tonhäuser ed957e6559 docs: update AI memory with recent fixes and architectural knowledge 2026-08-11 12:52:23 +02:00
Leon Tonhäuser 9fdd76645c feat: batched auto-rules emails, thumbnail fallback, and approve form 2026-08-11 12:52:01 +02:00
Leon Tonhäuser 4667615ed0 feat: implement hard delete, email notifications, watermark, and fix bulk download 2026-08-11 12:28:39 +02:00
Leon Tonhäuser 8dd1e10fea fix: bulk download streaming reliability 2026-08-11 12:03:08 +02:00
Leon Tonhäuser d9d69ed861 fix: comprehensive portal audit - bugfixes, performance, security, logo
Critical bugs:
- Fix bulk-download: UUID idempotency key, input validation, error handling, parallel asset validation
- Fix leuchtkasten 404 link -> album page with search
- Fix revalidatePath [id] -> [albumId]
- Fix PDF crash on null invoiceNumber

Logo:
- Fix dimensions (1000x1000), dark mode support (logo-white.png), max-height constraint

UI bugs:
- Fix unsafe Date method calls (6 files)
- Fix album UUID shown instead of name in catalog
- Fix global search downloads (albumId from asset)
- Add null guard for lightbox asset map

Performance:
- Parallelize admin dashboard queries (Promise.all)
- Lazy-load recharts via next/dynamic
- Add thumbnail caching headers (24h + ETag)
- Reduce duplicate Immich API calls in usage service
- Add DB index on usages(createdAt)
- Add optimizePackageImports for lucide-react, recharts

Security:
- Input validation on bulk-download (max 100 items, UUID format, purpose length)
- Verify security headers present in next.config.ts
2026-08-11 11:50:12 +02:00
Leon Tonhäuser 0576d946c5 fix: resolve remaining typescript errors 2026-08-11 11:27:44 +02:00
Leon Tonhäuser f4c06cbc95 fix: type errors 2026-08-11 11:24:37 +02:00
Leon Tonhäuser 6631530dcb fix: usage-accounting.test.ts syntax error 2026-08-11 11:22:46 +02:00
Leon Tonhäuser 64147a3282 Merge branch 'codex/immich-redaktionsportal' into main 2026-08-11 11:19:30 +02:00
Leon Tonhäuser 70ebcc9cd5 feat: standardizer changes 2026-08-11 11:19:10 +02:00
Leon Tonhäuser 4a9da65901 feat: redesign dashboard, add lightbox bulk download, and standardize ui 2026-08-11 11:18:39 +02:00
Leon Tonhäuser 8728308fc6 feat: complete UI design system refactoring and fix TS build errors 2026-08-11 03:38:34 +02:00
Leon Tonhäuser 0b1ffdfdfc feat: Add flatrate billing model for editorial accounts 2026-08-11 03:27:10 +02:00
Leon Tonhäuser 699580a6a0 chore: generate drizzle migration for archived_at and auto_rules 2026-08-11 03:05:10 +02:00
Leon Tonhäuser fcd2a08cd0 fix: resolve UI issues (image aspect ratio, footer padding, logo size, animations, hydration) 2026-08-11 03:04:01 +02:00
Leon Tonhäuser 6e25739e6e fix: restore approveEditorialAction and fix AlbumGrid type signature 2026-08-11 02:55:25 +02:00
Leon Tonhäuser e555069ee1 feat: merge cross-album search, auto-rules, album UI redesign, editorial archiving and pdf download into main 2026-08-11 02:53:19 +02:00
Leon Tonhäuser 375e5b8b7d feat: add cross-album search, auto-rules, album UI redesign, editorial archiving and pdf download 2026-08-11 02:53:15 +02:00
Leon TonhäuserandClaude 8dfaf8284e fix: support Immich v3 search/metadata cursor pagination
Immich v3 (server runs v3.1.0) returns search `nextPage` as an opaque cursor
string instead of a page number. The client schema validated `nextPage` as
`number`, so every album open failed schema validation and surfaced as
"Fotos momentan nicht erreichbar" (the catalog catch swallows the real
IMMICH_INVALID_RESPONSE into IMMICH_UNAVAILABLE).

Accept `string | number` for nextPage/previousPage in the schema and the
ImmichSearchPage type; we only use nextPage as a has-more-pages signal.
Pagination links are now derived from the current page number (currentPage ± 1)
instead of the returned nextPage value, since the v3 cursor can't be used as a
page number. Album page passes the normalized current page through.

Add a client test locking the v3 cursor-string response.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 02:23:21 +02:00
Leon TonhäuserandClaude 089f5f7035 fix: album assignment + approval error handling
Album assignment 500'd with IMMICH_UNAVAILABLE because grantAlbum verified the
album via getAlbum, which pulled the full album incl. all assets — large albums
blew the 15s timeout. Request ?withoutAssets=true so Immich returns metadata
only (no consumer reads .assets); make assets optional in the schema.

Album thumbnails 500'd because next/image rejected the ?albumId= query string
(images.localPatterns). Switch the album page to a plain <img>, matching the
editorial catalog (next/image was used in exactly one place).

Overhaul action error handling: grantAlbumAction/revokeAlbumAction/approveEditorialAction
returned a thrown Error, which Next.js turns into an opaque error-digest page —
the German message never reached the admin. They now return {ok,message}; new
client AlbumGrantForm + ApproveForm use useActionState to show the message
inline. Auth (requireAdmin) still throws (guarded by the layout). Update both
action test files to the result contract.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 02:09:16 +02:00
Leon TonhäuserandClaude 7aeceee078 feat: unify admin dashboard shell, add logout button
Admin used an undefined `.portal-shell` class plus the landing-page `.masthead`
markup, so the layout had no background/min-height and CSS "kackte rein".
Generalize PortalShell to take brand/nav props, switch admin/layout.tsx to it
(dark portal masthead + BrandLogo + admin nav), and pass the editorial nav from
redaktion/layout.tsx so both surfaces share one shell.

Add a LogoutButton client component (Better Auth signOut → hard navigate to
/anmelden) rendered into the masthead.

Style the admin content that had no rules: `.content-section dl/dt/dd` mirrors
`.editorial-section dl` (admin detail page), `.editorial-list` mirrors
`.billing-editorial-list` (Redaktionen index, replacing browser bullets),
`.portal-signout` for the dark masthead. Mobile: meta wraps, dl goes single
column.

Update logo.test.tsx to PortalShell's new required props.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 01:54:59 +02:00
Leon TonhäuserandClaude 23b251be7c fix(auth): declare role as additionalField so sessions include it
Better Auth's parseUserOutput filters the session user to declared fields
only (filterOutputFields over getFields(options,'user','output')). The drizzle
adapter selects the custom `role` column, but because it was never declared in
the Better Auth config, parseUserOutput stripped it — session.user.role was
always undefined. That broke two things: the root redirect fell through to
/redaktion/alben for admins (role !== 'ADMIN'), and requireAdmin threw
ADMIN_REQUIRED on every /admin page (role !== 'ADMIN').

Declare role via user.additionalFields (the documented custom-field API; the
`fields` map only renames core columns). input:false keeps it unsettable on
signUp — the DB default and the admin seed own it — and defaultValue matches
the column default so inserts never send null into the NOT NULL portalRole enum.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 01:41:18 +02:00
Leon TonhäuserandClaude 7cb168e846 feat(auth): specific German login error messages by Better Auth code
LoginForm mapped every signIn failure to one generic sentence. Better Auth
returns distinct codes in signIn order — password check, then
requireEmailVerification (EMAIL_NOT_VERIFIED), then the session.create.before
hook canCreateSession (FAILED_TO_CREATE_SESSION). Map those to specific
messages: unverified email, not-yet-approved account, invalid credentials.
canCreateSession returns true only for ADMIN or editorial status 'active', and
onEmailVerified → markPendingApproval leaves verified editorials at
pending_approval until an admin approves — so the not-approved message is the
common post-verification login block.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 01:28:29 +02:00
Leon TonhäuserandClaude 7e50c7c2fd fix(admin): add /admin index redirect and point root redirect at it
/admin had no index page (only /admin/redaktionen, /abrechnungen, /audit),
so authenticated admins hitting /admin — including the admin layout's
wordmark link — got a 404. Add src/app/admin/page.tsx that redirects to
/admin/redaktionen, and point the root home redirect at the same path so
post-login doesn't 404.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 00:43:29 +02:00
Leon TonhäuserandClaude cc2079db77 fix(home): redirect authenticated users to their portal home
The root page was a static public landing that always shows a
'Zum Portal' button pointing at /anmelden, and /anmelden never
redirects authenticated users. After login the callbackURL '/' landed
on this static page, so the user saw the login form again — the
post-login loop. Make / an async server component that reads the
session and redirects to /admin (admin) or /redaktion/alben (editorial);
unauthenticated users still see the landing.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 00:19:52 +02:00
Leon TonhäuserandClaude 3316365b73 fix(csp): allow inline scripts so Next.js client forms hydrate
script-src was 'self' with no 'unsafe-inline' and no nonce, so the
browser blocked Next.js App Router's inline hydration scripts (RSC
flight data + bootstrap). React never hydrated, so every client form's
handler never attached and the browser fell back to a native GET submit
— login dumped email/password into the URL and did nothing, and the
registration/reset forms were equally dead. Add 'unsafe-inline' to
script-src; per-request nonces via middleware remain the upgrade path.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 00:06:39 +02:00
Leon TonhäuserandClaude e6baaddca6 fix(preflight): check /api/albums instead of removed /api/server-info/ping
Current Immich removed /api/server-info/ping (returns 404 'Cannot GET
/api/server-info/ping'), so the preflight IMMICH check always failed
even though the API and key are fine. /api/albums is the endpoint the
portal actually depends on and requires a valid key with album.read
scope, so a 200 there confirms reachability + auth.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:55:40 +02:00
Leon TonhäuserandClaude 33b9076cd3 fix(auth): generate UUID ids to match uuid schema columns
Better Auth's default id generator emits a nanoid-style string, but
every id column in the schema is typed uuid. Better Auth passes its
generated id explicitly on insert (bypassing the column defaultRandom),
so Postgres rejected every signUp/session/verification insert with
'invalid input syntax for type uuid'. This broke live registration and
the admin seed alike. Configure advanced.database.generateId to return
crypto.randomUUID() so ids match the schema.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:41:47 +02:00
Leon TonhäuserandClaude 2c495ab32a fix(env): correct DATABASE_URL host in .env.example to portal-db
The compose database service is named portal-db, but .env.example
shipped DATABASE_URL pointing at host 'postgres'. Copying the example
and changing only the password left deployments resolving an
unreachable host (EAI_AGAIN postgres), while the spinner hid the
failed migrate and a stale portal-db-data volume made it look applied.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:31:19 +02:00
Leon TonhäuserandClaude 5ebde42aba ops: use external immich_default network
Immich's Compose creates the external network as immich_default, not
immich-net. Rename the external network reference so portal-app and
the preflight ops service attach to the existing network instead of
failing with 'network immich-net declared as external, but could not
be found'.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:25:25 +02:00
Leon TonhäuserandClaude 013036ea81 ops: add migrate/seed/preflight compose profile for clean fresh setup
The portal database lives on an internal-only network and is not exposed to
the host, so `pnpm drizzle-kit migrate` and admin seeding cannot run from the
host. Add one-shot `ops`-profile services built from the builder stage that run
migrations, seed the first admin, and run the preflight smoke test against the
real env from inside the network. Share the app env via an x-portal-env anchor.

Update the runbook to use the new commands.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:14:02 +02:00
Leon TonhäuserandClaude 6fc095a161 ops: add preflight smoke test for env + DB/SMTP/Immich connectivity
scripts/preflight.ts validates that every required env var is set, then
checks live connectivity to the database, the Better Auth adapter (instance
builds + user table readable), SMTP and Immich. Prints OK/FAIL per check
and exits non-zero on any failure. Run it when bringing up the box to catch
missing env vars and dead connections before going live.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:09:24 +02:00
Leon TonhäuserandClaude 268ea7544e fix: wire editorial approval, harden registration, set production auth URL
- Wire admin approval UI to editorialService.approveEditorial so editorial
  accounts can move pending_approval -> active and log in. The approve button
  was permanently disabled and the service unreachable, so editorial users
  could never sign in.
- Surface non-validation errors (e.g. SMTP failures) on the registration
  form instead of silently redirecting to the confirmation page.
- Set BETTER_AUTH_URL default to the production domain in .env.example and
  compose.yaml so verification/reset links and the login origin check
  resolve against the live origin.
- Add scripts/check-smtp.ts to verify SMTP connectivity against the
  configured transport.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 23:06:13 +02:00
Leon Tonhäuser 907beb6e42 ops: copy scripts folder to runner stage in Dockerfile 2026-08-10 22:47:59 +02:00
Leon Tonhäuser ed83cdf185 feat: add admin seed script 2026-08-10 22:44:32 +02:00
Leon Tonhäuser 976d7e0fef ops: include drizzle migrations in standalone image runner stage 2026-08-10 22:31:55 +02:00
Leon Tonhäuser ab8c035d99 merge: merge codex/immich-redaktionsportal into main 2026-08-10 21:52:53 +02:00
Leon Tonhäuser a06d51b746 chore: update root gitignore 2026-08-10 21:52:49 +02:00
Leon Tonhäuser 9c0d43b1ec test: add portal end-to-end quality gates 2026-08-10 21:51:25 +02:00
Leon Tonhäuser f7481d4cde ops: add portal deployment and backup runbook 2026-08-10 21:47:53 +02:00
Leon Tonhäuser 21871bb9ff feat: harden portal security and auditability 2026-08-10 21:46:54 +02:00
Leon TonhäuserandClaude 7f1ecd9322 feat: finalize immutable billing reports
Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 18:19:13 +02:00
Leon TonhäuserandClaude a384c4c35e fix: deterministic pdf render and restore pnpm pin
- Revert packageManager from pnpm@11.16.0 back to pnpm@10.34.5
  (restore the plan's pinned version; the PATH pnpm is unaffected).
- Inject a deterministic PDFKit document /ID derived from
  SHA-256(snapshot.documentId) so the same snapshot always produces
  byte-identical output, making the stored SHA-256 a verifiable
  integrity fingerprint.
- Add covering test: render same fixture twice, assert bytes.equals()
  and sha256 equality.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 18:04:18 +02:00
Leon TonhäuserandClaude 89d76e2711 feat: render billing usage pdf
Add the immutable PDF renderer for "Nutzungsnachweis" billing reports.

- src/modules/billing/types.ts: BillingReportSnapshot self-contained type
  (address, selected positions, repeat downloads, net total in cents,
  report/invoice metadata, period, document ID, legal notice).
- src/modules/pdf/document.ts: pdfmake document definition builder with
  monochrome invoice layout (black logo, sender/recipient blocks, rounded
  black summary panel, repeated black table headers, light-gray rows,
  German dates, cents-derived totals, page numbers, document ID, invoice
  reference, legal separation notice).
- src/modules/pdf/render.ts: renderBillingPdf → { bytes, sha256 } using
  pdfmake 0.3 with IBM Plex Mono (OFL) embedded via the VFS.
- scripts/render-pdf-fixture.ts: stress fixture generator (1 row, 60 rows,
  long address, long fields, umlauts, 3-page case) into tmp/pdfs/.
- tests/fixtures/billing-report.ts: deterministic reportFixture (60,00 EUR).
- tsconfig.json: server-only path alias for tsx script execution.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-10 17:54:19 +02:00