Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions src/app/anomalies/anomalies-client.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -45,6 +46,7 @@ interface MergedRow {

export function AnomaliesClient({ timeline }: AnomaliesClientProps) {
const [filter, setFilter] = useState<Filter>("all");
const canAct = !isRestricted(useViewer(), "anomalies.actions");

const openAnomalies = timeline.anomalies.filter((a) => !a.resolvedAt);
const resolvedAnomalies = timeline.anomalies.filter((a) => a.resolvedAt);
Expand Down Expand Up @@ -172,14 +174,14 @@ export function AnomaliesClient({ timeline }: AnomaliesClientProps) {
{a.message}
</td>
<td className="px-4 py-3">
<Link
href={`/users/${encodeURIComponent(a.userEmail ?? "")}`}
<UserLink
email={a.userEmail ?? ""}
className="text-blue-400 hover:text-blue-300 text-xs"
>
{a.userEmail === "team"
? "team"
: (a.userEmail ?? "unknown").split("@")[0]}
</Link>
</UserLink>
</td>
<td
className="px-4 py-3 text-zinc-500 text-xs whitespace-nowrap"
Expand All @@ -203,7 +205,7 @@ export function AnomaliesClient({ timeline }: AnomaliesClientProps) {
</span>
</td>
<td className="text-right px-4 py-3 whitespace-nowrap space-x-1.5">
{inc && status !== "resolved" && (
{canAct && inc && status !== "resolved" && (
<>
{status !== "acknowledged" && (
<button
Expand Down
23 changes: 7 additions & 16 deletions src/app/dashboard-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,13 @@ export function DashboardClient({ initialData }: DashboardClientProps) {
const [minStr, maxStr] = exhaustionParam.split("-");
const min = parseInt(minStr ?? "0", 10);
const max = parseInt(maxStr ?? "999", 10);
fetch("/api/analytics")
.then((r) => r.json())
.then(
(analytics: {
planExhaustion?: { users: Array<{ email: string; days_to_exhaust: number }> };
}) => {
const matching = (analytics.planExhaustion?.users ?? []).filter(
(u) => u.days_to_exhaust >= min && u.days_to_exhaust <= max,
);
setExhaustionFilter({
label: `Plan exhausted day ${min}–${max}`,
emails: new Set(matching.map((u) => u.email)),
});
},
)
.catch(() => {});
const matching = initialData.planExhaustion.filter(
(u) => u.days_to_exhaust >= min && u.days_to_exhaust <= max,
);
setExhaustionFilter({
label: `Plan exhausted day ${min}–${max}`,
emails: new Set(matching.map((u) => u.email)),
});
}
const saved = localStorage.getItem("dashboard-days");
if (saved) {
Expand Down
14 changes: 6 additions & 8 deletions src/app/insights/insights-client.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import React, { useCallback, useEffect, useMemo, useState } from "react";
import { UserLink } from "@/components/access";
import {
AreaChart,
Area,
Expand Down Expand Up @@ -809,9 +810,9 @@ function ClientVersionsSection({
<td colSpan={4} className="pb-1">
<div className="pl-5 py-1 space-y-0.5">
{v.users.map((u) => (
<a
<UserLink
key={u.email}
href={`/users/${encodeURIComponent(u.email)}`}
email={u.email}
className="block text-[11px] text-zinc-400 hover:text-blue-400 transition-colors"
>
{u.name}
Expand All @@ -820,7 +821,7 @@ function ClientVersionsSection({
needs update
</span>
)}
</a>
</UserLink>
))}
</div>
</td>
Expand Down Expand Up @@ -942,12 +943,9 @@ function PlanExhaustionSection({
return (
<tr key={u.email} className="border-b border-zinc-800/30 hover:bg-zinc-800/30">
<td className="py-1">
<a
href={`/users/${encodeURIComponent(u.email)}`}
className="text-zinc-300 hover:text-blue-400"
>
<UserLink email={u.email} className="text-zinc-300 hover:text-blue-400">
{u.name || u.email}
</a>
</UserLink>
</td>
<td className={`text-right py-1 font-mono font-bold ${dayColor}`}>
Day {u.days_to_exhaust}
Expand Down
57 changes: 31 additions & 26 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Link from "next/link";
import { NavLinks } from "@/components/nav-links";
import { UpgradeBanner } from "@/components/upgrade-banner";
import { UserMenu } from "@/components/user-menu";
import { ViewerProvider } from "@/components/access";
import { getViewer } from "@/lib/access";
import { auth, signOut } from "@/auth";
import "./globals.css";

Expand All @@ -15,38 +17,41 @@ export const metadata: Metadata = {

export default async function RootLayout({ children }: { children: React.ReactNode }) {
const session = process.env.AUTH_SECRET ? await auth() : null;
const viewer = getViewer(session?.user?.email);

return (
<html lang="en" className="dark">
<body className="min-h-screen">
<nav className="border-b border-zinc-800 bg-zinc-950/80 backdrop-blur-sm sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-11">
<div className="flex items-center gap-1">
<Link href="/" className="flex items-center gap-2 mr-4">
<Image src="/logo.png" alt="" width={22} height={22} aria-hidden />
<span className="text-sm font-semibold text-white">Cursor Tracker</span>
</Link>
<NavLinks />
</div>
<div className="flex items-center gap-2">
<UpgradeBanner />
{session?.user && (
<UserMenu
name={session.user.name ?? session.user.email ?? "User"}
email={session.user.email ?? ""}
image={session.user.image ?? undefined}
signOutAction={async () => {
"use server";
await signOut({ redirectTo: "/login" });
}}
/>
)}
<ViewerProvider value={viewer}>
<nav className="border-b border-zinc-800 bg-zinc-950/80 backdrop-blur-sm sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-11">
<div className="flex items-center gap-1">
<Link href="/" className="flex items-center gap-2 mr-4">
<Image src="/logo.png" alt="" width={22} height={22} aria-hidden />
<span className="text-sm font-semibold text-white">Cursor Tracker</span>
</Link>
<NavLinks />
</div>
<div className="flex items-center gap-2">
<UpgradeBanner />
{session?.user && (
<UserMenu
name={session.user.name ?? session.user.email ?? "User"}
email={session.user.email ?? ""}
image={session.user.image ?? undefined}
signOutAction={async () => {
"use server";
await signOut({ redirectTo: "/login" });
}}
/>
)}
</div>
</div>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">{children}</main>
</nav>
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">{children}</main>
</ViewerProvider>
</body>
</html>
);
Expand Down
Loading
Loading