Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c142c45edf | ||
|
|
61e0393f01 | ||
|
|
1971d2bd6f |
No files matched your search
@@ -66,6 +66,9 @@ around:
|
|||||||
- This app can never read or verify the session. It calls `GET /admin/me` and believes the
|
- 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
|
answer; the API's `requireAppAccess('calendar')` is the actual gate. `/admin/me` answers 200
|
||||||
for an account without the calendar permission - check `apps`.
|
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
|
- 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
|
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`.
|
loop where signing in succeeds and lands straight back on the refusal. See `app/admin/layout.tsx`.
|
||||||
|
|||||||
+11
-1
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { LogOutIcon, RefreshCwIcon } from "lucide-react";
|
import { EyeIcon, LogOutIcon, RefreshCwIcon } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -11,6 +11,7 @@ import { Skeleton } from "@/components/ui/skeleton";
|
|||||||
import { Toaster } from "@/components/ui/sonner";
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
import { goToAdminLogin, signOut } from "@/lib/admin-auth";
|
import { goToAdminLogin, signOut } from "@/lib/admin-auth";
|
||||||
import { api, ApiError } from "@/lib/api";
|
import { api, ApiError } from "@/lib/api";
|
||||||
|
import { canEditCalendar } from "@/lib/permissions";
|
||||||
import type { AdminUser } from "@/lib/types";
|
import type { AdminUser } from "@/lib/types";
|
||||||
|
|
||||||
type Failure = "denied" | "unavailable";
|
type Failure = "denied" | "unavailable";
|
||||||
@@ -82,6 +83,15 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
|
|||||||
) : (
|
) : (
|
||||||
<Skeleton className="hidden h-4 w-24 sm:block" />
|
<Skeleton className="hidden h-4 w-24 sm:block" />
|
||||||
)}
|
)}
|
||||||
|
{me && !canEditCalendar(me) && (
|
||||||
|
<span
|
||||||
|
className="inline-flex h-6 items-center gap-1 rounded-full bg-muted px-2 text-xs font-medium text-muted-foreground"
|
||||||
|
title="Dein Konto darf den Kalender ansehen, aber nichts ändern."
|
||||||
|
>
|
||||||
|
<EyeIcon aria-hidden className="size-3.5" />
|
||||||
|
Nur lesen
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{me && <SubscriptionsDialog />}
|
{me && <SubscriptionsDialog />}
|
||||||
<Button variant="ghost" size="sm" onClick={() => void signOut()} aria-label="Abmelden">
|
<Button variant="ghost" size="sm" onClick={() => void signOut()} aria-label="Abmelden">
|
||||||
<LogOutIcon />
|
<LogOutIcon />
|
||||||
|
|||||||
+8
-1
@@ -6,6 +6,7 @@ import { toast } from "sonner";
|
|||||||
import { CalendarChips } from "@/components/admin/CalendarChips";
|
import { CalendarChips } from "@/components/admin/CalendarChips";
|
||||||
import { EventList } from "@/components/admin/EventList";
|
import { EventList } from "@/components/admin/EventList";
|
||||||
import { EventSheet, type SheetMode } from "@/components/admin/EventSheet";
|
import { EventSheet, type SheetMode } from "@/components/admin/EventSheet";
|
||||||
|
import { useCanEdit } from "@/components/admin/AdminSession";
|
||||||
import { EventsToolbar } from "@/components/admin/EventsToolbar";
|
import { EventsToolbar } from "@/components/admin/EventsToolbar";
|
||||||
import { PublishDialog } from "@/components/admin/PublishDialog";
|
import { PublishDialog } from "@/components/admin/PublishDialog";
|
||||||
import { useEvents } from "@/components/admin/useEvents";
|
import { useEvents } from "@/components/admin/useEvents";
|
||||||
@@ -32,6 +33,8 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
function EventsPage() {
|
function EventsPage() {
|
||||||
const [state, update] = useListState();
|
const [state, update] = useListState();
|
||||||
|
// Read-only role: everything visible, no way to change it (the API refuses writes anyway).
|
||||||
|
const canEdit = useCanEdit();
|
||||||
const { events, loads, reload, refresh, upsertEvent, removeEvent } = useEvents();
|
const { events, loads, reload, refresh, upsertEvent, removeEvent } = useEvents();
|
||||||
// Fixed per visit: "upcoming" should not reshuffle while someone is looking at it.
|
// Fixed per visit: "upcoming" should not reshuffle while someone is looking at it.
|
||||||
const [now] = useState(() => new Date());
|
const [now] = useState(() => new Date());
|
||||||
@@ -138,10 +141,12 @@ function EventsPage() {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{canEdit && (
|
||||||
<Button onClick={newEvent} className="hidden sm:inline-flex">
|
<Button onClick={newEvent} className="hidden sm:inline-flex">
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
Neuer Termin
|
Neuer Termin
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<EventsToolbar
|
<EventsToolbar
|
||||||
@@ -183,11 +188,12 @@ function EventsPage() {
|
|||||||
publishingId={publishingId}
|
publishingId={publishingId}
|
||||||
todayMarker={todayMarker}
|
todayMarker={todayMarker}
|
||||||
onOpen={(event) => openSheet({ kind: "edit", event })}
|
onOpen={(event) => openSheet({ kind: "edit", event })}
|
||||||
onPublish={setConfirmPublish}
|
onPublish={canEdit ? setConfirmPublish : undefined}
|
||||||
onClearQuery={() => update({ query: "" })}
|
onClearQuery={() => update({ query: "" })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Phones: a thumb-reach button instead of the header one. */}
|
{/* Phones: a thumb-reach button instead of the header one. */}
|
||||||
|
{canEdit && (
|
||||||
<Button
|
<Button
|
||||||
onClick={newEvent}
|
onClick={newEvent}
|
||||||
size="icon-lg"
|
size="icon-lg"
|
||||||
@@ -196,6 +202,7 @@ function EventsPage() {
|
|||||||
>
|
>
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
<EventSheet
|
<EventSheet
|
||||||
key={sheet.key}
|
key={sheet.key}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
import { canEditCalendar } from "@/lib/permissions";
|
||||||
import type { AdminUser } from "@/lib/types";
|
import type { AdminUser } from "@/lib/types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,3 +20,9 @@ export const useAdminUser = (): AdminUser => {
|
|||||||
}
|
}
|
||||||
return user;
|
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());
|
||||||
@@ -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. */
|
/** Index into `events` to show the "Heute" marker in front of (`events.length` = after the last); null for none. */
|
||||||
todayMarker: number | null;
|
todayMarker: number | null;
|
||||||
onOpen?: (event: CalendarEvent) => void;
|
onOpen?: (event: CalendarEvent) => void;
|
||||||
onPublish: (event: CalendarEvent) => void;
|
onPublish?: (event: CalendarEvent) => void;
|
||||||
onClearQuery: () => void;
|
onClearQuery: () => void;
|
||||||
}) {
|
}) {
|
||||||
if (noCalendars) {
|
if (noCalendars) {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export function EventListItem({
|
|||||||
now: Date;
|
now: Date;
|
||||||
publishing: boolean;
|
publishing: boolean;
|
||||||
onOpen?: (event: CalendarEvent) => void;
|
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 { start } = occurrence(event, now);
|
||||||
const block = dateBlock(start);
|
const block = dateBlock(start);
|
||||||
@@ -86,7 +87,7 @@ export function EventListItem({
|
|||||||
{repeat}
|
{repeat}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{event.status === "DRAFT" && (
|
{event.status === "DRAFT" && onPublish && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="xs"
|
size="xs"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { CircleAlertIcon, CopyIcon, LoaderCircleIcon, Trash2Icon, XIcon } from "lucide-react";
|
import { CircleAlertIcon, CopyIcon, EyeIcon, LoaderCircleIcon, Trash2Icon, XIcon } from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { useAdminUser } from "@/components/admin/AdminSession";
|
import { useAdminUser, useCanEdit } from "@/components/admin/AdminSession";
|
||||||
import { EventForm, fieldId } from "@/components/admin/EventForm";
|
import { EventForm, fieldId } from "@/components/admin/EventForm";
|
||||||
import { useMediaQuery } from "@/components/admin/useMediaQuery";
|
import { useMediaQuery } from "@/components/admin/useMediaQuery";
|
||||||
import {
|
import {
|
||||||
@@ -84,6 +84,9 @@ export function EventSheet({
|
|||||||
onDuplicate: (event: CalendarEvent) => void;
|
onDuplicate: (event: CalendarEvent) => void;
|
||||||
}) {
|
}) {
|
||||||
const user = useAdminUser();
|
const user = useAdminUser();
|
||||||
|
// Read-only role: the sheet becomes a view - same fields, nothing to save, delete or duplicate.
|
||||||
|
// The page never opens it in "new" or "duplicate" mode for such an account.
|
||||||
|
const readOnly = !useCanEdit();
|
||||||
const desktop = useMediaQuery("(min-width: 640px)");
|
const desktop = useMediaQuery("(min-width: 640px)");
|
||||||
|
|
||||||
// What "unchanged" means. Moves forward after a partial save (moved, but the
|
// What "unchanged" means. Moves forward after a partial save (moved, but the
|
||||||
@@ -223,13 +226,13 @@ export function EventSheet({
|
|||||||
noValidate
|
noValidate
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void save();
|
if (!readOnly) void save();
|
||||||
}}
|
}}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<SheetHeader className="flex-row items-start justify-between gap-3 border-b p-4">
|
<SheetHeader className="flex-row items-start justify-between gap-3 border-b p-4">
|
||||||
<div className="flex flex-col gap-0.5">
|
<div className="flex flex-col gap-0.5">
|
||||||
<SheetTitle>{TITLES[mode.kind]}</SheetTitle>
|
<SheetTitle>{readOnly ? "Termin ansehen" : TITLES[mode.kind]}</SheetTitle>
|
||||||
<SheetDescription className={mode.kind === "edit" ? "line-clamp-1" : undefined}>
|
<SheetDescription className={mode.kind === "edit" ? "line-clamp-1" : undefined}>
|
||||||
{mode.kind === "edit"
|
{mode.kind === "edit"
|
||||||
? mode.event.name
|
? mode.event.name
|
||||||
@@ -244,7 +247,7 @@ export function EventSheet({
|
|||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
|
|
||||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-5">
|
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-5">
|
||||||
<EventForm form={form} errors={showErrors ? errors : {}} disabled={busy} onChange={setForm} />
|
<EventForm form={form} errors={showErrors ? errors : {}} disabled={busy || readOnly} onChange={setForm} />
|
||||||
{original && <Metadata event={original} />}
|
{original && <Metadata event={original} />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -257,6 +260,17 @@ export function EventSheet({
|
|||||||
)}
|
)}
|
||||||
{/* Labels follow the footer's own width (container query), not the window's: the
|
{/* Labels follow the footer's own width (container query), not the window's: the
|
||||||
side panel is capped, so a wide window says nothing about the room in here. */}
|
side panel is capped, so a wide window says nothing about the room in here. */}
|
||||||
|
{readOnly ? (
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<p className="flex flex-1 items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<EyeIcon aria-hidden className="size-4 shrink-0" />
|
||||||
|
Du hast für den Kalender nur Lesezugriff.
|
||||||
|
</p>
|
||||||
|
<Button type="button" variant="outline" onClick={requestClose}>
|
||||||
|
Schließen
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div className="@container flex items-center gap-2">
|
<div className="@container flex items-center gap-2">
|
||||||
{original && (
|
{original && (
|
||||||
<>
|
<>
|
||||||
@@ -298,6 +312,7 @@ export function EventSheet({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { CalendarPlusIcon, CheckIcon, CircleAlertIcon, CopyIcon, RefreshCwIcon } from "lucide-react";
|
import { CalendarPlusIcon, CheckIcon, CircleAlertIcon, CopyIcon, RefreshCwIcon } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button, buttonVariants } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -114,16 +114,19 @@ export function SubscriptionsDialog() {
|
|||||||
{subscription.icalUrl}
|
{subscription.icalUrl}
|
||||||
</code>
|
</code>
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Button variant="outline" size="xs" render={<a href={toWebcal(subscription.icalUrl)} />}>
|
{/* Plain links that only look like buttons. Rendering them through Base UI's
|
||||||
|
Button made them role="button" (and warned without nativeButton={false}). */}
|
||||||
|
<a href={toWebcal(subscription.icalUrl)} className={buttonVariants({ variant: "outline", size: "xs" })}>
|
||||||
Apple Kalender
|
Apple Kalender
|
||||||
</Button>
|
</a>
|
||||||
<Button
|
<a
|
||||||
variant="outline"
|
href={toGoogleCalendar(subscription.icalUrl)}
|
||||||
size="xs"
|
target="_blank"
|
||||||
render={<a href={toGoogleCalendar(subscription.icalUrl)} target="_blank" rel="noopener noreferrer" />}
|
rel="noopener noreferrer"
|
||||||
|
className={buttonVariants({ variant: "outline", size: "xs" })}
|
||||||
>
|
>
|
||||||
Google Kalender
|
Google Kalender
|
||||||
</Button>
|
</a>
|
||||||
<Button variant="outline" size="xs" onClick={() => void copy(subscription)}>
|
<Button variant="outline" size="xs" onClick={() => void copy(subscription)}>
|
||||||
{copied === calendar.slug ? <CheckIcon /> : <CopyIcon />}
|
{copied === calendar.slug ? <CheckIcon /> : <CopyIcon />}
|
||||||
{copied === calendar.slug ? "Kopiert" : "Link kopieren"}
|
{copied === calendar.slug ? "Kopiert" : "Link kopieren"}
|
||||||
|
|||||||
@@ -8,9 +8,17 @@ Done items move to the bottom.
|
|||||||
- **List the calendars.** Ids, slugs and names are hardcoded in `lib/calendars.ts` and must be kept in
|
- **List the calendars.** Ids, slugs and names are hardcoded in `lib/calendars.ts` and must be kept in
|
||||||
step with `calendarNames` in `events.router.ts`. An endpoint would make a new calendar a data change.
|
step with `calendarNames` in `events.router.ts`. An endpoint would make a new calendar a data change.
|
||||||
- **All calendars in one request.** The admin list makes five parallel requests on every load.
|
- **All calendars in one request.** The admin list makes five parallel requests on every load.
|
||||||
- **Restore / history.** Every save already writes a row to `event_versions`, and delete is a
|
- **Restore.** Every save already writes a row to `event_versions`, and delete is a
|
||||||
`DELETED` version - so "Wiederherstellen" and a change history are possible without schema changes,
|
`DELETED` version - so "Wiederherstellen" and a change history are possible without schema changes,
|
||||||
only endpoints are missing. The UI's delete dialog says it can't be undone "hier".
|
only endpoints are missing. The UI's delete dialog says it can't be undone "hier".
|
||||||
|
- **Log moves.** Create, edit and delete each append a full version to `event_versions` with who
|
||||||
|
(`version_created_by_user_id`) and when - but `PUT /move/:id` only runs
|
||||||
|
`UPDATE events SET calendar_id = …`: who moved an event, when, and from which calendar is recorded
|
||||||
|
nowhere (`event_versions` has no calendar column). Found 2026-11-08; deferred by the user. Fix:
|
||||||
|
add `calendar_id` to `event_versions` and write a version on move too.
|
||||||
|
- **Show the history in the UI.** With an endpoint like `GET /calendar/events/:id/versions`, the edit
|
||||||
|
sheet could list who changed what and when. Today the UI shows only "Erstellt von" and "Zuletzt
|
||||||
|
geändert von"; the full history is only reachable via SQL on `event_versions`.
|
||||||
- **Don't return deleted events** from the admin feed (or behind a flag). They arrive as rows with
|
- **Don't return deleted events** from the admin feed (or behind a flag). They arrive as rows with
|
||||||
every field `null` except `status`, and the client has to know to drop them.
|
every field `null` except `status`, and the client has to know to drop them.
|
||||||
- **Richer recurrence.** `repeatFrequency` goes out as `RRULE:FREQ=<value>` with no interval, end
|
- **Richer recurrence.** `repeatFrequency` goes out as `RRULE:FREQ=<value>` with no interval, end
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ the **API** sets on `.nachklang.art`; it is shared by calendar, feedback, ticket
|
|||||||
`GET /admin/me` answers **200** for an account without the calendar permission; only `apps` shows
|
`GET /admin/me` answers **200** for an account without the calendar permission; only `apps` shows
|
||||||
it. The layout's `apps.includes("calendar")` check is load-bearing.
|
it. The layout's `apps.includes("calendar")` check is load-bearing.
|
||||||
|
|
||||||
|
**Read-only role.** `/admin/me` also returns `permissions: [{app, role}]`. `lib/permissions.ts`
|
||||||
|
(`canEditCalendar`) mirrors the API's `canWrite`: only a calendar grant with role `access` may
|
||||||
|
change anything; `read` - or any role the app doesn't know - is read-only. Without `permissions`
|
||||||
|
(an API from before the role) it falls back to `apps`. The UI reads it through `useCanEdit()`
|
||||||
|
(`AdminSession.tsx`) and hides every write control; `EventSheet` turns into a view. Enforcement
|
||||||
|
is the API's: `requireAppAccess` refuses non-GET requests from `read` grants with 403. See the
|
||||||
|
API's `docs/admin-roles.md`.
|
||||||
|
|
||||||
## Data flow (admin)
|
## Data flow (admin)
|
||||||
|
|
||||||
- `components/admin/useEvents.ts` loads all five calendars in parallel from
|
- `components/admin/useEvents.ts` loads all five calendars in parallel from
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ What the calendar app does, as of the Next.js rewrite (September 2026).
|
|||||||
Sign-in happens in the admin app (one account for all Nachklang apps). Accounts need the calendar
|
Sign-in happens in the admin app (one account for all Nachklang apps). Accounts need the calendar
|
||||||
permission; without it the page says so instead of redirecting.
|
permission; without it the page says so instead of redirecting.
|
||||||
|
|
||||||
|
**Two levels** (granted in the admin app): *Vollzugriff* (`access`) can do everything below;
|
||||||
|
*Nur lesen* (`read`, since 2026-11-08 in this app) sees every calendar, draft and subscription link
|
||||||
|
but changes nothing - no "Neuer Termin", no "+", no "Veröffentlichen", and opening an event shows
|
||||||
|
"Termin ansehen" with locked fields and only "Schließen". A "Nur lesen" badge in the header says
|
||||||
|
why. The API refuses read-only writes anyway (403); the UI just doesn't offer them.
|
||||||
|
|
||||||
**List**
|
**List**
|
||||||
- All calendars in one list, grouped by month, colour-coded per calendar.
|
- All calendars in one list, grouped by month, colour-coded per calendar.
|
||||||
- Calendar chips toggle calendars on and off, with a count each; Geburtstage is off by default.
|
- Calendar chips toggle calendars on and off, with a count each; Geburtstage is off by default.
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ Collected during the rewrite (September 2026); the progress log in
|
|||||||
and `sheet.tsx`.
|
and `sheet.tsx`.
|
||||||
- **Base UI, not Radix:** toggles expose `aria-pressed` (not `data-state=on`), triggers take a
|
- **Base UI, not Radix:** toggles expose `aria-pressed` (not `data-state=on`), triggers take a
|
||||||
`render` prop (not `asChild`), menu radio items stay open unless `closeOnClick` is set.
|
`render` prop (not `asChild`), menu radio items stay open unless `closeOnClick` is set.
|
||||||
|
- **A link that looks like a button is a plain `<a className={buttonVariants(…)}>`**, not
|
||||||
|
`<Button render={<a …/>}>`. Through Base UI's Button it warns in dev ("expected a native
|
||||||
|
<button>", shown as Next's "2 issues" badge) and, with `nativeButton={false}`, gets
|
||||||
|
`role="button"` - screen readers then announce a link as a button.
|
||||||
- **Base UI Select ignores synthetic `click()`s**; automated tests need real pointer or keyboard input.
|
- **Base UI Select ignores synthetic `click()`s**; automated tests need real pointer or keyboard input.
|
||||||
- **Closed dialogs stay in the DOM** with `data-closed` until their exit animation ends - in a hidden
|
- **Closed dialogs stay in the DOM** with `data-closed` until their exit animation ends - in a hidden
|
||||||
tab that never happens. Query `[data-open]` when checking what's open.
|
tab that never happens. Query `[data-open]` when checking what's open.
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ Decisions made while implementing (not asked explicitly - revisit if wrong):
|
|||||||
- Recurring events appear under "Kommend" and "Alle", never under "Vergangen".
|
- Recurring events appear under "Kommend" and "Alle", never under "Vergangen".
|
||||||
- A yearly event on 29 Feb falls on 28 Feb in common years.
|
- A yearly event on 29 Feb falls on 28 Feb in common years.
|
||||||
- An unknown `status` from the API is treated (and saved back) as `PRIVATE`, never as `PUBLIC`.
|
- An unknown `status` from the API is treated (and saved back) as `PRIVATE`, never as `PUBLIC`.
|
||||||
- Calendar labels: Öffentlich, Mitglieder, Chor, Management, Geburtstage.
|
- Calendar labels: Öffentlich, Mitglieder, Chor, Management, Geburtstage. (2026-11-08: "Management" renamed to "Vorstand" at the user's request; the slug stays `management`.)
|
||||||
- New events default to `DRAFT`, like the Angular app.
|
- New events default to `DRAFT`, like the Angular app.
|
||||||
Facts found along the way (move to `docs/gotchas.md` in phase 8):
|
Facts found along the way (move to `docs/gotchas.md` in phase 8):
|
||||||
- The API returns raw DB rows: `wholeDay` is most likely `0`/`1` (inferred from the MariaDB
|
- The API returns raw DB rows: `wholeDay` is most likely `0`/`1` (inferred from the MariaDB
|
||||||
|
|||||||
+2
-1
@@ -59,7 +59,8 @@ export const CALENDARS: readonly Calendar[] = [
|
|||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
slug: "management",
|
slug: "management",
|
||||||
label: "Management",
|
// Shown as "Vorstand" (user's wording, 2026-11-08); the slug stays "management" - it's the API's name.
|
||||||
|
label: "Vorstand",
|
||||||
defaultVisible: true,
|
defaultVisible: true,
|
||||||
dotClass: "bg-amber-500",
|
dotClass: "bg-amber-500",
|
||||||
badgeClass: "bg-amber-50 text-amber-900 ring-amber-200",
|
badgeClass: "bg-amber-50 text-amber-900 ring-amber-200",
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { canEditCalendar } from "@/lib/permissions";
|
||||||
|
|
||||||
|
describe("canEditCalendar", () => {
|
||||||
|
it("allows changes with the access role", () => {
|
||||||
|
expect(canEditCalendar({ apps: ["calendar"], permissions: [{ app: "calendar", role: "access" }] })).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("refuses them with the read role", () => {
|
||||||
|
expect(canEditCalendar({ apps: ["calendar"], permissions: [{ app: "calendar", role: "read" }] })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("only counts calendar grants - full access elsewhere doesn't help", () => {
|
||||||
|
const user = {
|
||||||
|
apps: ["calendar", "tickets", "admin"],
|
||||||
|
permissions: [
|
||||||
|
{ app: "calendar", role: "read" },
|
||||||
|
{ app: "tickets", role: "access" },
|
||||||
|
{ app: "admin", role: "access" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(canEditCalendar(user)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats an unknown future role as read-only, like the API's canWrite", () => {
|
||||||
|
expect(canEditCalendar({ apps: ["calendar"], permissions: [{ app: "calendar", role: "redeem" }] })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to apps when an older API sends no permissions", () => {
|
||||||
|
expect(canEditCalendar({ apps: ["calendar"] })).toBe(true);
|
||||||
|
expect(canEditCalendar({ apps: ["tickets"] })).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import type { AdminUser } from "@/lib/types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May this account change calendar events? Mirrors `canWrite` in the API's
|
||||||
|
* admin.schema.ts (docs/admin-roles.md there): only a grant with the role
|
||||||
|
* `access` allows changes; `read` ("Nur lesen") sees everything and changes
|
||||||
|
* nothing. The API refuses the writes regardless - this only decides which
|
||||||
|
* controls to show.
|
||||||
|
*
|
||||||
|
* An API that predates roles sends no `permissions`. Then every calendar user
|
||||||
|
* could write, so that is what this answers too.
|
||||||
|
*/
|
||||||
|
export const canEditCalendar = (user: Pick<AdminUser, "apps" | "permissions">): boolean => {
|
||||||
|
if (!user.permissions) {
|
||||||
|
return user.apps.includes("calendar");
|
||||||
|
}
|
||||||
|
return user.permissions.some((p) => p.app === "calendar" && p.role === "access");
|
||||||
|
};
|
||||||
@@ -82,5 +82,12 @@ export interface AdminUser {
|
|||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
fullName: string;
|
fullName: string;
|
||||||
|
/** The distinct apps the account may open at all, whatever the role. */
|
||||||
apps: string[];
|
apps: string[];
|
||||||
|
/**
|
||||||
|
* The full (app, role) grants: `access` = may change things, `read` = may only
|
||||||
|
* look. Missing on an API from before the read-only role (2026-10-29).
|
||||||
|
* See lib/permissions.ts.
|
||||||
|
*/
|
||||||
|
permissions?: { app: string; role: string }[];
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user