mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
Separate admins' own content from managing other users
- Short links, Link pages and Overview now show only the admin's own namespace and root; other users' content moved to Administration - Administration lists users with their link/page/click counts; each opens /~/admin/users/<name> with that user's pages and links and lets admins create content in their namespace - other users' pages open under /~/admin/users/<name>/…, keep the Administration section active and link back to the user - one PageTable component for all lists, so search and the namespace filter (All / mine / Root, admins only) behave the same everywhere - the create dialog offers admins only their own namespace and root; the existing-link picker groups links by namespace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+39
-3
@@ -33,19 +33,47 @@ export function linkHandler(to: string) {
|
||||
export type Route =
|
||||
| { name: "overview" }
|
||||
| { name: "list"; kind: PageKind }
|
||||
| { name: "detail"; kind: PageKind; id: number; tab: string | undefined }
|
||||
/** `owner` is set when an admin opens another user's page via Administration. */
|
||||
| { name: "detail"; kind: PageKind; id: number; tab: string | undefined; owner?: string }
|
||||
| { name: "tokens" }
|
||||
| { name: "admin" }
|
||||
| { name: "adminUser"; username: string }
|
||||
| { name: "notFound" };
|
||||
|
||||
const KIND_SEGMENT: Record<string, PageKind> = { links: "redirect", pages: "linkpage" };
|
||||
|
||||
// The signed-in user. Pages of other users are addressed through Administration,
|
||||
// so the admin's own and root content stays separate from managing everyone else's.
|
||||
let viewer: string | null = null;
|
||||
export function setViewer(username: string) {
|
||||
viewer = username;
|
||||
}
|
||||
|
||||
const isOtherUsers = (namespace: string | undefined) => namespace !== undefined && namespace !== "" && namespace !== viewer;
|
||||
|
||||
export function listPath(kind: PageKind): string {
|
||||
return kind === "redirect" ? "/~/links" : "/~/pages";
|
||||
}
|
||||
|
||||
export function detailPath(page: { id: number; kind: PageKind }, tab?: string): string {
|
||||
return `${listPath(page.kind)}/${page.id}${tab ? `/${tab}` : ""}`;
|
||||
export function adminUserPath(username: string): string {
|
||||
return `/~/admin/users/${encodeURIComponent(username)}`;
|
||||
}
|
||||
|
||||
export function detailPath(page: { id: number; kind: PageKind; namespace?: string }, tab?: string): string {
|
||||
const segment = page.kind === "redirect" ? "links" : "pages";
|
||||
const base = isOtherUsers(page.namespace) ? `${adminUserPath(page.namespace!)}/${segment}` : `/~/${segment}`;
|
||||
return `${base}/${page.id}${tab ? `/${tab}` : ""}`;
|
||||
}
|
||||
|
||||
// Where "back" leads from a page: its owner's admin view for other users' pages, otherwise the list.
|
||||
export function backPath(page: { kind: PageKind; namespace: string }): string {
|
||||
return isOtherUsers(page.namespace) ? adminUserPath(page.namespace) : listPath(page.kind);
|
||||
}
|
||||
|
||||
// Replaces the current URL (no new history entry), e.g. to correct a link to the canonical address.
|
||||
export function replacePath(to: string) {
|
||||
history.replaceState(null, "", to);
|
||||
listeners.forEach((l) => l());
|
||||
}
|
||||
|
||||
export function parseRoute(path: string): Route {
|
||||
@@ -53,6 +81,14 @@ export function parseRoute(path: string): Route {
|
||||
if (p === "/~") return { name: "overview" };
|
||||
if (p === "/~/tokens") return { name: "tokens" };
|
||||
if (p === "/~/admin") return { name: "admin" };
|
||||
|
||||
const user = p.match(/^\/~\/admin\/users\/([^/]+)(?:\/(links|pages)\/(\d+)(?:\/([a-z]+))?)?$/);
|
||||
if (user) {
|
||||
const username = decodeURIComponent(user[1]!);
|
||||
if (!user[2]) return { name: "adminUser", username };
|
||||
return { name: "detail", kind: KIND_SEGMENT[user[2]]!, id: Number(user[3]), tab: user[4], owner: username };
|
||||
}
|
||||
|
||||
const m = p.match(/^\/~\/(links|pages)(?:\/(\d+)(?:\/([a-z]+))?)?$/);
|
||||
if (m) {
|
||||
const kind = KIND_SEGMENT[m[1]!]!;
|
||||
|
||||
Reference in New Issue
Block a user