diff --git a/.env.example b/.env.example index 268a6ea..72bccf0 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,13 @@ AUTH_GOOGLE_ID= # Google OAuth client ID AUTH_GOOGLE_SECRET= # Google OAuth client secret AUTH_ALLOWED_DOMAIN= # e.g. yourcompany.com (only this domain can sign in) AUTH_ALLOWED_EMAILS= # comma-separated allowlist, e.g. admin@example.com,viewer@example.com +AUTH_UNRESTRICTED_EMAILS= # comma-separated, lifts RESTRICTED_FEATURES for these signed-in emails (the displayed role is unchanged) AUTH_TRUST_HOST=true # required when behind a reverse proxy (Fly.io, Vercel, etc.) AUTH_URL= # public URL, e.g. https://your-app.fly.dev (auto-detected locally) +# Features restricted for Cursor members and anonymous visitors, comma-separated (optional, none by default) +# Values: insights, anomalies, anomalies.actions, user-details, settings, settings.actions +# *.actions = every .actions value (anomalies.actions, settings.actions) +RESTRICTED_FEATURES= + ELEVENLABS_API_KEY= diff --git a/README.md b/README.md index 8ec8246..54e8f96 100644 --- a/README.md +++ b/README.md @@ -445,6 +445,31 @@ When both are set, either match grants access. When neither is set, any Google a - Sign-in page appears automatically when auth is enabled - User avatar and sign-out menu appear in the nav bar +### Access Control + +Optionally align dashboard permissions with Cursor roles. It is off by default. The role is read from Cursor using the sign-in email. + +```bash +RESTRICTED_FEATURES=settings,anomalies.actions,user-details +AUTH_UNRESTRICTED_EMAILS=cto@example.com # optional, lifts the restriction for identified emails, members or not in Cursor (the displayed role is unchanged) +``` + +- `RESTRICTED_FEATURES` is a comma-separated list of features reserved to unrestricted users. A value also restricts its dotted sub-values: + +| Value | Restricts | +| ------------------- | --------------------------------------------------------------------------------------- | +| `insights` | The Insights page | +| `anomalies` | The Anomalies page | +| `anomalies.actions` | Acknowledge and Resolve | +| `user-details` | Other members' detail pages (links greyed out), the person's own page stays available | +| `settings` | The Settings page and its API | +| `settings.actions` | Settings becomes read-only: save, group management, HiBob import and restore are hidden | +| `*.actions` | Every `.actions` value: `anomalies.actions` and `settings.actions` | + +- Cursor `owner` and `free-owner` (plus the emails above) are never restricted, without changing the role displayed +- Cursor `member`, emails with no Cursor account and anonymous visitors (no sign-in) are restricted +- Nothing is restricted when the list is empty + --- ## API Endpoints diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 3e7f76a..c7435e5 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -133,6 +133,17 @@ ### Billing Groups -- Group management: create, rename, assign members +- Group management: create, rename, assign members (Cursor role badge per member) - HiBob CSV import with change preview - Backup export/import + +--- + +## Access Control (optional, `RESTRICTED_FEATURES`) + +**Cursor roles applied to the dashboard.** + +- Unrestricted: Cursor `owner` / `free-owner`, or listed in `AUTH_UNRESTRICTED_EMAILS` +- Everyone else (members, unknown emails, anonymous) loses the features listed in `RESTRICTED_FEATURES` +- Values: `insights`, `anomalies`, `anomalies.actions` (no Ack/Resolve), `user-details` (other members' pages greyed out and blocked), `settings`, `settings.actions` (read-only Settings); `*.actions` covers every `.actions` value +- A value also restricts its dotted sub-values; the Overview is never restricted diff --git a/src/app/anomalies/anomalies-client.tsx b/src/app/anomalies/anomalies-client.tsx index 7e3ad63..bad41f4 100644 --- a/src/app/anomalies/anomalies-client.tsx +++ b/src/app/anomalies/anomalies-client.tsx @@ -1,7 +1,8 @@ "use client"; import { useState } from "react"; -import Link from "next/link"; +import { UserLink, useViewer } from "@/components/access"; +import { isRestricted } from "@/lib/types"; import { StatCard } from "@/components/dashboard/stat-card"; import { timeAgo } from "@/lib/date-utils"; import type { Anomaly, Incident } from "@/lib/types"; @@ -45,6 +46,7 @@ interface MergedRow { export function AnomaliesClient({ timeline }: AnomaliesClientProps) { const [filter, setFilter] = useState("all"); + const canAct = !isRestricted(useViewer(), "anomalies.actions"); const openAnomalies = timeline.anomalies.filter((a) => !a.resolvedAt); const resolvedAnomalies = timeline.anomalies.filter((a) => a.resolvedAt); @@ -172,14 +174,14 @@ export function AnomaliesClient({ timeline }: AnomaliesClientProps) { {a.message} - {a.userEmail === "team" ? "team" : (a.userEmail ?? "unknown").split("@")[0]} - + - {inc && status !== "resolved" && ( + {canAct && inc && status !== "resolved" && ( <> {status !== "acknowledged" && ( + {!readOnly && ( + + )} -
+
)}
-
+ - + ); } @@ -343,7 +348,7 @@ interface ImportPreview { applied?: number; } -function BillingGroupsManager() { +function BillingGroupsManager({ readOnly }: { readOnly: boolean }) { const [groups, setGroups] = useState([]); const [filter, setFilter] = useState("unassigned"); const [search, setSearch] = useState(""); @@ -561,14 +566,16 @@ function BillingGroupsManager() { onClick={() => setShowBackup(true)} className="px-3 py-1 bg-zinc-700 hover:bg-zinc-600 text-zinc-200 rounded-md text-[11px] font-medium transition-colors" > - Import / Export - - + {!readOnly && ( + + )} @@ -609,17 +616,19 @@ function BillingGroupsManager() { <> {g.name} ({g.member_count}) - + {!readOnly && ( + + )} )} @@ -661,12 +670,14 @@ function BillingGroupsManager() { ) : ( - + !readOnly && ( + + ) )} @@ -713,8 +724,9 @@ function BillingGroupsManager() { Name Email + Role Current Group - Reassign to + {!readOnly && Reassign to} @@ -724,29 +736,34 @@ function BillingGroupsManager() { {member.name || "—"} {member.email} - {currentGroup?.name ?? "—"} - - + + + {currentGroup?.name ?? "—"} + {!readOnly && ( + + + + )} ); })} @@ -1091,16 +1108,18 @@ function BillingGroupsManager() { > Export - + {!readOnly && ( + + )}