From 61e0393f012fae049ce45d9354fa4a92c852aedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sun, 8 Nov 2026 22:15:31 +0100 Subject: [PATCH] Support the read-only calendar role, show "Vorstand", fix link buttons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Read-only role: /admin/me's permissions decide via canEditCalendar (lib/permissions.ts, mirrors the API's canWrite: only `access` writes). Read-only accounts see everything but get no "Neuer Termin", no "+", no "Veröffentlichen"; an event opens as "Termin ansehen" with locked fields. A "Nur lesen" badge in the header explains why. The API refuses their writes regardless. - The management calendar is labelled "Vorstand"; the slug stays `management` for the API, URLs and iCal links. - The subscription dialog's Apple/Google links are plain anchors styled with buttonVariants instead of Base UI Buttons rendering an , which warned in dev and would have given them role="button". Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 3 +++ app/admin/layout.tsx | 12 ++++++++- app/admin/page.tsx | 33 ++++++++++++++---------- components/admin/AdminSession.tsx | 7 +++++ components/admin/EventList.tsx | 2 +- components/admin/EventListItem.tsx | 5 ++-- components/admin/EventSheet.tsx | 25 ++++++++++++++---- components/admin/SubscriptionsDialog.tsx | 19 ++++++++------ docs/architecture.md | 8 ++++++ docs/features.md | 6 +++++ docs/gotchas.md | 4 +++ docs/rewrite-plan.md | 2 +- lib/calendars.ts | 3 ++- lib/permissions.test.ts | 33 ++++++++++++++++++++++++ lib/permissions.ts | 18 +++++++++++++ lib/types.ts | 7 +++++ 16 files changed, 155 insertions(+), 32 deletions(-) create mode 100644 lib/permissions.test.ts create mode 100644 lib/permissions.ts diff --git a/CLAUDE.md b/CLAUDE.md index 9fff938..c7c509f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,6 +66,9 @@ around: - This app can never read or verify the session. It calls `GET /admin/me` and believes the answer; the API's `requireAppAccess('calendar')` is the actual gate. `/admin/me` answers 200 for an account without the calendar permission - check `apps`. +- A calendar grant is `access` (may change things) or `read` (only look). Hide write controls + with `useCanEdit()` / `canEditCalendar` (`lib/permissions.ts`), which mirrors the API's + `canWrite`. Any new write control must check it. - 401 and 403 mean different things and must not be collapsed. 401 means "nobody is signed in" and is the only one worth redirecting to the login page - redirecting on 403 produces a loop where signing in succeeds and lands straight back on the refusal. See `app/admin/layout.tsx`. diff --git a/app/admin/layout.tsx b/app/admin/layout.tsx index 51a4afa..e1f84d1 100644 --- a/app/admin/layout.tsx +++ b/app/admin/layout.tsx @@ -1,6 +1,6 @@ "use client"; -import { LogOutIcon, RefreshCwIcon } from "lucide-react"; +import { EyeIcon, LogOutIcon, RefreshCwIcon } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; @@ -11,6 +11,7 @@ import { Skeleton } from "@/components/ui/skeleton"; import { Toaster } from "@/components/ui/sonner"; import { goToAdminLogin, signOut } from "@/lib/admin-auth"; import { api, ApiError } from "@/lib/api"; +import { canEditCalendar } from "@/lib/permissions"; import type { AdminUser } from "@/lib/types"; type Failure = "denied" | "unavailable"; @@ -82,6 +83,15 @@ export default function AdminLayout({ children }: { children: React.ReactNode }) ) : ( )} + {me && !canEditCalendar(me) && ( + + + Nur lesen + + )} {me && } + {canEdit && ( + + )} openSheet({ kind: "edit", event })} - onPublish={setConfirmPublish} + onPublish={canEdit ? setConfirmPublish : undefined} onClearQuery={() => update({ query: "" })} /> {/* Phones: a thumb-reach button instead of the header one. */} - + {canEdit && ( + + )} { } return user; }; + +/** + * Whether the account may change events. False for the read-only role: then + * the admin area shows everything but offers no way to change it. + */ +export const useCanEdit = (): boolean => canEditCalendar(useAdminUser()); diff --git a/components/admin/EventList.tsx b/components/admin/EventList.tsx index f052c33..f27a2e1 100644 --- a/components/admin/EventList.tsx +++ b/components/admin/EventList.tsx @@ -39,7 +39,7 @@ export function EventList({ /** Index into `events` to show the "Heute" marker in front of (`events.length` = after the last); null for none. */ todayMarker: number | null; onOpen?: (event: CalendarEvent) => void; - onPublish: (event: CalendarEvent) => void; + onPublish?: (event: CalendarEvent) => void; onClearQuery: () => void; }) { if (noCalendars) { diff --git a/components/admin/EventListItem.tsx b/components/admin/EventListItem.tsx index 57be2a8..4f639e5 100644 --- a/components/admin/EventListItem.tsx +++ b/components/admin/EventListItem.tsx @@ -23,7 +23,8 @@ export function EventListItem({ now: Date; publishing: boolean; onOpen?: (event: CalendarEvent) => void; - onPublish: (event: CalendarEvent) => void; + /** Absent for a read-only account: then drafts show no publish button. */ + onPublish?: (event: CalendarEvent) => void; }) { const { start } = occurrence(event, now); const block = dateBlock(start); @@ -86,7 +87,7 @@ export function EventListItem({ {repeat} )} - {event.status === "DRAFT" && ( + {event.status === "DRAFT" && onPublish && ( + + ) : (
{original && ( <> @@ -298,6 +312,7 @@ export function EventSheet({
+ )} )} diff --git a/components/admin/SubscriptionsDialog.tsx b/components/admin/SubscriptionsDialog.tsx index a789143..9ea0780 100644 --- a/components/admin/SubscriptionsDialog.tsx +++ b/components/admin/SubscriptionsDialog.tsx @@ -2,7 +2,7 @@ import { CalendarPlusIcon, CheckIcon, CircleAlertIcon, CopyIcon, RefreshCwIcon } from "lucide-react"; import { useState } from "react"; -import { Button } from "@/components/ui/button"; +import { Button, buttonVariants } from "@/components/ui/button"; import { Dialog, DialogContent, @@ -114,16 +114,19 @@ export function SubscriptionsDialog() { {subscription.icalUrl}
- - +