Support the read-only calendar role, show "Vorstand", fix link buttons
Test and deploy / test (pull_request) Successful in 2m18s
Test and deploy / deploy (pull_request) Skipped

- 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 <a>, which warned in
  dev and would have given them role="button".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PaddyandClaude Opus 5.5 committed 2026-11-08 22:15:31 +01:00
1 parent 1971d2bd6f
commit 61e0393f01
16 files changed
+155 -32

No files matched your search

+2 -1
View File
@@ -59,7 +59,8 @@ export const CALENDARS: readonly Calendar[] = [
{
id: 3,
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,
dotClass: "bg-amber-500",
badgeClass: "bg-amber-50 text-amber-900 ring-amber-200",
+33
View File
@@ -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);
});
});
+18
View File
@@ -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");
};
+7
View File
@@ -82,5 +82,12 @@ export interface AdminUser {
id: string;
email: string;
fullName: string;
/** The distinct apps the account may open at all, whatever the role. */
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 }[];
}