Files
t5de-hub/apps/web/app/console/console-nav.tsx
T
dhkatzandClaude Opus 5.5 370ae0646a
Pull request / title (pull_request) Successful in 1s
CI / test (pull_request) Successful in 1m1s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped
feat: permissions, a console for everyone who manages something, and catalog management
Phase 1 of docs/console.md: permissions as resource:action strings in role
bundles at a scope; the console for anyone controlling a catalog, product
or room, with a tagged audit log scoped by permission and filters;
catalog settings (rating ceiling, upload policy), key rotation, operators,
membership (approval, invitations, bans) enforced when getting and
wearing products, delisting, suspension, and the catalogs' changes feed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 23:19:15 -08:00

58 lines
2.2 KiB
TypeScript

import { notFound, redirect } from "next/navigation";
import { cache } from "react";
import { NavLink } from "@/components/header-client";
import { api, getMe, isModerator, unwrap, type ConsoleData, type Person } from "@/lib/api";
/** The signed-in moderator, or off to sign in; others get not found (these pages aren't for them). */
export async function requireModerator(path: string): Promise<Person> {
const me = await getMe();
if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`);
if (!isModerator(me)) notFound();
return me;
}
/** The console as this person sees it (once per request); undefined if it isn't for them. */
const loadConsole = cache(async (): Promise<ConsoleData | undefined> => {
const answer = await api.console.get();
if (answer.error) return undefined;
return unwrap(answer);
});
/**
* The signed-in person and their console, or off to sign in. People who manage nothing get not found: the console
* is for those controlling a product, catalog or room.
*/
export async function requireConsole(path: string): Promise<{ me: Person; console: ConsoleData }> {
const me = await getMe();
if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`);
const data = await loadConsole();
if (!data) notFound();
return { me, console: data };
}
type Section = ConsoleData["sections"][number];
// Products are managed on their own pages for now; settings are on the overview.
const tabs: { section: Section; href: string; label: string }[] = [
{ section: "overview", href: "/console", label: "Overview" },
{ section: "catalogs", href: "/console/catalogs", label: "Catalogs" },
{ section: "people", href: "/console/people", label: "People" },
{ section: "audit", href: "/console/audit", label: "Audit" },
];
/** The console's sections this person may see. */
export async function ConsoleNav() {
const sections = new Set<Section>((await loadConsole())?.sections ?? ["overview"]);
return (
<nav className="mb-8 flex gap-1 border-b pb-3 text-sm">
{tabs
.filter((t) => sections.has(t.section))
.map((t) => (
<NavLink key={t.section} href={t.href} exact={t.section === "overview"}>
{t.label}
</NavLink>
))}
</nav>
);
}