mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-06 04:37:52 +01:00
The approver has to get the monthly report to a referring social worker, who can't log in to the admin report page — and app email isn't reliably deliverable (unauthenticated sending domain). So deliver it the way the codebase already delivers deliverables: an unguessable public bearer link. - Migration 137 `report_shares` (token, user_id, month, revoked_at) — keyed by (user_id, month), since a running month may have no timecard row yet. - `report-shares.ts` service: ensure/lookup/revoke, mirroring the deliverables share_token pattern. - Extract the report body into a shared, presentational `<MonthlyReportSheet>` (+ neutral `<ReportPrintButton>`), reused by the admin page and the new public page — no behaviour change to the admin sheet. - Public `/r/[token]` route (view + print, never indexed, no auth); `/r/` added to proxy BYPASS_INTL. - `<ReportShareCard>` on the admin report page: create / copy / revoke the link. Same access rule as viewing the report (owner or timecard approver). Migration already applied + recorded on prod. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
21 lines
948 B
SQL
21 lines
948 B
SQL
-- Public share tokens for the Monatsrapport.
|
|
--
|
|
-- A report is addressed by (user_id, month) — a running month may have no
|
|
-- timecard row yet, so the token cannot live on `timecards`; it gets its own
|
|
-- table. The token is an unguessable bearer capability (like deliverables'
|
|
-- share_token); revoked_at lets an approver kill a link that was shared too
|
|
-- widely. No enums, no CHECK constraints (per CLAUDE.md §DB).
|
|
|
|
CREATE TABLE IF NOT EXISTS report_shares (
|
|
token text PRIMARY KEY,
|
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
month text NOT NULL, -- YYYY-MM
|
|
created_by uuid REFERENCES users(id) ON DELETE SET NULL,
|
|
revoked_at timestamptz,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
-- One (active or revoked) row per report — ensureReportShareToken revives it.
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_report_shares_user_month
|
|
ON report_shares (user_id, month);
|