Public: anyone can read this; the crew can change it.

Access 3, web pages: the two known partings are decided, then each page's own isAdmin and sign-in check is deleted and may() alone decides #18430

opened this

Merged 11h 12m ago, live in production

mason/forge:mason/18424-access-3-web-pages-the-two-known-parting → main 0 commits fork

  • Merged. mason/18424-access-3-web-pages-the-two-known-parting was merged into main as d4ae8b7.

Review

Sign in to review this change.
145 files changed +596 −584
docs/ROLES.md +8 −6
@@ -112,13 +112,15 @@ small pack that expands when git reads it still costs CPU and memory.
112112
113113 ## Inline checks in a moved door
114114
115 The repository routes under `src/http/api/` and the MCP tools (`src/http/mcp.ts`,
116 `src/http/mcp/`) have moved to `may` (Access 3, #18406), so a new line in them
117 that gates on `isAdmin`, on `scopeAllows(…, "rw")` or on `!ctx.auth.user` fails
115 The repository routes under `src/http/api/`, the MCP tools (`src/http/mcp.ts`,
116 `src/http/mcp/`) and the web pages (`src/web/pages/`) have moved to `may` (Access 3,
117 #18406, #18424), so a new line in them that gates on `isAdmin`, on
118 `scopeAllows(…, "rw")` or on `!ctx.auth.user` fails
118119 `test/door-inline-checks.test.ts`, which names the file and line and the helper to
119 ask instead: `adminPage` or `mayBeside(ctx, door, "forge.administer", old)` for an
120 admin, `mayBeside(ctx, door, "forge.write", old)` (`mayToolWrite(ctx)` in the MCP) for
121 a write, `signedInPage` for an account. Only gate shapes count: a role passed on
120 ask instead: `adminPage(ctx)` or `personAdminPage(ctx)` on a page and
121 `holds(db, principalOf(ctx.auth), "forge.administer")` on a route for an admin,
122 `holds(db, principalOf(ctx.auth), "forge.write")` (`mayToolWrite(ctx)` in the MCP) for
123 a write, `signedInPage(ctx)` for an account. Only gate shapes count: a role passed on
122124 for display is a read, and `scopeAllows(…, "admin")` is a token's reach, not a
123125 role. The lines that stay are listed in `DOOR_LINES` (`src/design/door_checks.ts`),
124126 each with a reason; the list only shrinks, because an entry whose line is gone
docs/features/may.md +7 −7
@@ -47,13 +47,13 @@ something asks `forge.write` with the credential you send, so an `ro` token is t
4747 (`src/http/mcp/tool_may.ts`). The old scope floor was worked out beside it until the count under `mcp <tool>` held
4848 nothing a request can make (#18405); `may`'s answer is now the only one. The terminal's "What I can do" lists `forge.write` with the rest.
4949
50 **The web pages ask it.** A page only the admin sees asks `forge.administer`, and a page that needs you signed in asks
51 by what the request does: `forge.read` to open it (GET), `forge.write` to change something (POST), both with the
52 credential you send (`src/http/page_may.ts`). An `ro` token that opens its own page is no parting; one that posts is.
53 An anonymous visit to a signed-in page parts on `forge.read`, which is open to all: that row says the page needs more
54 than reading. The page's old check (`isAdmin`, an account
55 behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is
56 `web <page>`, the page's module. Nothing you can open on the web changes while the count is read.
50 **The web pages ask it alone.** Web pages have one access check: `may`, through `src/http/page_may.ts`, asked of the
51 account behind the request. A page only the admin sees asks `forge.administer` (`adminPage`; `personAdminPage` where the
52 page is a person's and an admin agent is turned away, as before), and a page that needs you signed in asks `forge.write`
53 (`signedInPage`), which every account holds and nobody without one does: an anonymous visit is told `unauthorized` and
54 sent to sign in, as before. A token's scope is judged where it was, by the form a change reads, so an `ro` token opens
55 what its account opens and is refused the changes it was refused before. The pages' inline `isAdmin` and signed-in
56 checks are gone (#18424), and `test/door-inline-checks.test.ts` keeps them gone from `src/web/pages/`.
5757
5858 **The infrastructure pages and the cloud API ask it alone.** Every `/infra` page and change, and
5959 `GET /api/v1/cloud/accounts`, decide by `forge.administer` (`src/http/infra_routes.ts`, `src/http/api/cloud.ts`);
src/core/access_disagreement.ts +2 −2
@@ -35,8 +35,8 @@ export function noteDisagreement(
3535
3636 /**
3737 * Ask `may` beside `old`, the answer of the check it is replacing, and count a parting under
38 * `door`: what every door in shadow does (`http/may_beside.ts`, the terminal's palette, the game
39 * grants). Returns what `may` said; a door still in shadow keeps its old answer itself.
38 * `door`: what every door in shadow does (the terminal's palette, the game grants). Returns what
39 * `may` said; a door still in shadow keeps its old answer itself.
4040 */
4141 export function askBeside(db: Database, asking: Principal, door: string, action: Action, old: boolean, resource?: Resource): boolean {
4242 const said = holds(db, asking, action, resource);
src/design/door_checks.ts +20 −10
@@ -2,10 +2,10 @@
22 * The inline access check does not come back into a moved door (#18406, Access 3's last step). The
33 * repository routes under `src/http/api/`, the MCP tools (`src/http/mcp.ts`, `src/http/mcp/`), the
44 * infrastructure pages and the cloud API (`src/http/infra_routes.ts`, `src/http/api/cloud.ts`)
5 * now ask `may`; this ratchet reads their source and finds each line that gates on the account
6 * inline: a refusal on `isAdmin` (`!user.isAdmin`, `isAdmin !== true`, or `isAdmin` in an `if`), a
7 * `scopeAllows(…, "rw")` write floor, or a signed-out test (`!ctx.auth.user`, `ctx.auth.user ===
8 * undefined` in a condition).
5 * and the web pages (`src/web/pages/`, #18424) now ask `may`; this ratchet reads their source and
6 * finds each line that gates on the account inline: a refusal on `isAdmin` (`!user.isAdmin`,
7 * `isAdmin !== true`, or `isAdmin` in an `if`), a `scopeAllows(…, "rw")` write floor, or a
8 * signed-out test (`!ctx.auth.user`, `ctx.auth.user === undefined` in a condition).
99 *
1010 * Only gate shapes count: a role passed on for display (`familyView(app, user.isAdmin === true)`)
1111 * is a read, not a door, and is not matched. `scopeAllows(…, "admin")` is how far a token reaches,
@@ -29,15 +29,15 @@ export interface DoorFound {
2929
3030 /** What to ask instead, by the check found. */
3131 const HELPER: Record<DoorCheck, string> = {
32 isAdmin: `adminPage(ctx, door, old) or mayBeside(ctx, door, "forge.administer", old)`,
33 scopeAllows: `mayBeside(ctx, door, "forge.write", old) (mayToolWrite in the MCP)`,
34 signedOut: "signedInPage(ctx, door)",
32 isAdmin: `adminPage(ctx) or personAdminPage(ctx) on a page, holds(db, principalOf(ctx.auth), "forge.administer") on a route`,
33 scopeAllows: `holds(db, principalOf(ctx.auth), "forge.write") (mayToolWrite in the MCP)`,
34 signedOut: "signedInPage(ctx)",
3535 };
3636
3737 /** The fix that ends each finding: which helper, or which list line to delete. */
3838 export const DOOR_FIX = {
3939 newLine: (c: DoorCheck): string =>
40 `Fix: ask ${HELPER[c]} (src/http/page_may.ts, src/http/may_beside.ts); never add the line to DOOR_LINES in src/design/door_checks.ts.`,
40 `Fix: ask ${HELPER[c]} (src/http/page_may.ts, src/core/may.ts); never add the line to DOOR_LINES in src/design/door_checks.ts.`,
4141 gone: "Fix: the check is gone, so delete its entry from DOOR_LINES in src/design/door_checks.ts; lowering is the right move.",
4242 } as const;
4343
@@ -63,12 +63,12 @@ const MOVED = new Set(["src/http/mcp.ts", "src/http/infra_routes.ts"]);
6363
6464 /**
6565 * The files the moved doors live in: repository route modules and the cloud API under
66 * src/http/api, the infrastructure pages, and the MCP.
66 * src/http/api, the infrastructure pages, the MCP, and the web pages.
6767 */
6868 export function doorSources(root: string): Source[] {
6969 const api = tsSources(root, "src/http/api").filter((f) => f.text.includes("/api/v1/repos/") || f.path === "src/http/api/cloud.ts");
7070 const mcp = tsSources(root, "src/http").filter((f) => MOVED.has(f.path));
71 return [...api, ...mcp, ...tsSources(root, "src/http/mcp")];
71 return [...api, ...mcp, ...tsSources(root, "src/http/mcp"), ...tsSources(root, "src/web/pages")];
7272 }
7373
7474 /** A line that keeps its inline check, by file and exact trimmed text, and why. Only shrinks. */
@@ -80,6 +80,7 @@ export interface DoorLine {
8080
8181 const NOT_ONLY_HERE = "an admin-only tool hidden as not found; moves when the tool's own rule asks may";
8282 const ADMIN_READ = "an admin-only read refused by name; moves when the tool's own rule asks may";
83 const SHOWN = "the account shown, not the one asking";
8384
8485 export const DOOR_LINES: readonly DoorLine[] = [
8586 { file: "src/http/api/issues.ts", text: "if (ctx.auth.user === undefined) {", why: "which door a stranger is shown, not whether they pass" },
@@ -110,6 +111,15 @@ export const DOOR_LINES: readonly DoorLine[] = [
110111 { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads what it stands on");', why: ADMIN_READ },
111112 { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its off-site backup lane");', why: ADMIN_READ },
112113 { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its CSP violations");', why: ADMIN_READ },
114 { file: "src/web/pages/home_flow.ts", text: "if (!isAdmin) return [];", why: "plain data in: the caller asked may and passes its answer" },
115 { file: "src/web/pages/home_flow.ts", text: "if (!viewer.isAdmin) return null;", why: "plain data in: the caller asked may and passes its answer" },
116 { file: "src/web/pages/everyday.ts", text: 'if (user.isAdmin && user.kind === "user") return everydayForm(ctx, user, false);', why: SHOWN },
117 { file: "src/web/pages/everyday.ts", text: 'if (!admin?.isAdmin) return new Response("not found", { status: 404 });', why: "the admin an everyday account is paired with, not the one asking" },
118 { file: "src/web/pages/repo.ts", text: "if (!isAdmin(ctx, repo)) return null;", why: "a repository's admin, asked through canAdmin" },
119 { file: "src/web/pages/accounts.ts", text: 'const actionable = a.kind === "user" && !a.isAdmin && a.removedAt === null;', why: SHOWN },
120 { file: "src/web/pages/accounts.ts", text: "const ordinary = !user.isAdmin;", why: SHOWN },
121 { file: "src/web/pages/new-forge.ts", text: "if (user?.isAdmin !== true || plans.every((p) => p.key === FREE)) return null;", why: "a render helper handed the account, which shows a field and gates nothing" },
122 { file: "src/web/pages/reports.ts", text: 'if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "rw"))', why: "a token's scope, judged where it was" },
113123 ];
114124
115125 const key = (file: string, text: string): string => `${file}\n${text}`;
src/http/may_beside.ts deleted −15
@@ -1,15 +0,0 @@
1 /**
2 * `may` asked beside the check it is replacing (#18091, #18092, #18395): the principal the
3 * request carries is asked `action`, and where its answer parts from `old` one row is counted in
4 * `access_disagreement` under `door` (`core/access_disagreement.ts`). Returns what `may` said; a
5 * door still in shadow returns its old answer itself.
6 */
7
8 import { askBeside } from "../core/access_disagreement.ts";
9 import type { Action } from "../core/may.ts";
10 import { principalOf } from "../core/principal.ts";
11 import type { Ctx } from "./context.ts";
12
13 export function mayBeside(ctx: Ctx, door: string, action: Action, old: boolean): boolean {
14 return askBeside(ctx.app.db, principalOf(ctx.auth), door, action, old);
15 }
src/http/page_may.ts +24 −26
@@ -1,38 +1,36 @@
11 /**
2 * The web pages ask `may` in shadow (#18395), as the repository routes (`http/repo_may.ts`) and
3 * the MCP tools (`http/mcp/tool_may.ts`) did before them: a page's old gate (`isAdmin`, a signed-in
4 * account) still decides, `may(principal, action)` is worked out beside it, and where the two part
5 * one row is counted in `access_disagreement` (door `web <page>`, the action, the kind of
6 * principal; no account, token or repository). Nobody's access changes here.
2 * The web pages' one access check (#18424, Access 3): `may` alone decides who opens a page, as it
3 * does for `/infra` (`http/infra_routes.ts`). The inline `isAdmin` and signed-in checks the pages
4 * held are gone, and `test/door-inline-checks.test.ts` keeps them gone.
75 *
6 * `may` is asked of the account behind the request (`principalOfUser`), never of the token's scope:
7 * a token's scope is judged where it was before, by the form a change reads
8 * (`readForm(ctx, scope)`) or the action it calls, so nobody's access moved when the inline checks
9 * went.
10 *
11 * - `signedInPage`: a page that needs an account asks `forge.write`, the action every account holds
12 * over what is its own and nobody without one does (`may` says `unauthorized`). `forge.read` is
13 * open to all, so asking it was the parting the shadow counted for an anonymous visit (#18400).
814 * - `adminPage`: a page only the forge's admin sees asks `forge.administer`.
9 * - `signedInPage`: a page that needs an account asks by what the request does. A read (GET, HEAD)
10 * asks `forge.read`, so an `ro` token that reads its own page is no parting; a write asks
11 * `forge.write`, which an `ro` token is refused. An anonymous read parts on `forge.read`
12 * (open to all) from the sign-in gate (accounts only): that is a real difference, and the row
13 * says so.
15 * - `personAdminPage`: the admin pages that are a person's, never an agent's, ask the same and that
16 * the account is not an agent (an admin agent is refused there, as before).
1417 */
1518
16 import type { Action } from "../core/may.ts";
19 import { holds, type Action } from "../core/may.ts";
20 import { principalOfUser } from "../core/principal.ts";
1721 import type { User } from "../core/users.ts";
1822 import type { Ctx } from "./context.ts";
19 import { mayBeside } from "./may_beside.ts";
20
21 /** Ask `may` beside the old answer, count a parting, and return the old answer. */
22 function shadow(ctx: Ctx, page: string, action: Action, old: boolean): boolean {
23 mayBeside(ctx, `web ${page}`, action, old);
24 return old;
25 }
26
27 /** The admin gate of `page`: `old` is the inline check's answer, and still the one that counts. */
28 export const adminPage = (ctx: Ctx, page: string, old: boolean): boolean => shadow(ctx, page, "forge.administer", old);
2923
3024 /** A request with an account behind it. */
3125 export type SignedIn = Ctx & { auth: Ctx["auth"] & { user: User } };
3226
33 /** What a request to a page does, as `may` names it: reading, or a change. */
34 export const pageAction = (method: string): Action => (method === "GET" || method === "HEAD" ? "forge.read" : "forge.write");
27 const asks = (ctx: Ctx, action: Action): boolean => holds(ctx.app.db, principalOfUser(ctx.auth.user), action);
3528
36 /** The sign-in gate of `page`: is there an account? Asked of `may` beside it. */
37 export const signedInPage = (ctx: Ctx, page: string): ctx is SignedIn =>
38 shadow(ctx, page, pageAction(ctx.request.method), ctx.auth.user !== undefined);
29 /** Is there an account behind the request? `may` answers `forge.write` of it. */
30 export const signedInPage = (ctx: Ctx): ctx is SignedIn => asks(ctx, "forge.write");
31
32 /** Does the account behind the request administer the forge? */
33 export const adminPage = (ctx: Ctx): ctx is SignedIn => asks(ctx, "forge.administer");
34
35 /** The forge's admin, and a person rather than an agent: the admin pages that are a person's. */
36 export const personAdminPage = (ctx: Ctx): ctx is SignedIn => adminPage(ctx) && ctx.auth.user.kind !== "agent";
src/web/pages/access.ts +1 −1
@@ -19,7 +19,7 @@ import { accountSections } from "./origins.ts";
1919 // GET /settings/access
2020 export function accessPage(ctx: Ctx): Response {
2121 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
22 if (!signedInPage(ctx, "access")) return signInFirst(ctx);
22 if (!signedInPage(ctx)) return signInFirst(ctx);
2323 const user = ctx.auth.user;
2424 const ua = ctx.url.searchParams.get("ua")?.slice(0, 100) ?? "";
2525 const path = ctx.url.searchParams.get("path")?.slice(0, 200) ?? "";
src/web/pages/account.ts +27 −27
@@ -9,7 +9,7 @@
99 * has been read once.
1010 */
1111
12 import { signedInPage } from "../../http/page_may.ts";
12 import { signedInPage, adminPage } from "../../http/page_may.ts";
1313 import { UPSTREAM_REPO } from "../../core/upstream.ts";
1414 import { emptyNote } from "../empty_words.ts";
1515 import { resendVerification } from "../../actions/verify.ts";
@@ -256,7 +256,7 @@ function dotfilesView(ctx: Ctx, error?: string): Html {
256256
257257 // POST /settings/dotfiles
258258 export async function dotfilesUpdate(ctx: Ctx): Promise<Response> {
259 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
259 if (!signedInPage(ctx)) return signInFirst(ctx);
260260 const form = await readForm(ctx, "admin");
261261 if (form instanceof Response) return form;
262262 const saved = setDotfilesRepo(ctx.app.db, ctx.auth.user, field(form, "repo"));
@@ -316,7 +316,7 @@ function parentLinkView(ctx: Ctx): Html {
316316
317317 // POST /settings/parent/unlink
318318 export async function parentUnlink(ctx: Ctx): Promise<Response> {
319 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
319 if (!signedInPage(ctx)) return signInFirst(ctx);
320320 const form = await readForm(ctx, "admin");
321321 if (form instanceof Response) return form;
322322 const issuer = parentIssuerOf(ctx.app.config);
@@ -329,7 +329,7 @@ export async function parentUnlink(ctx: Ctx): Promise<Response> {
329329
330330 // POST /settings/edge/link
331331 export async function edgeLink(ctx: Ctx): Promise<Response> {
332 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
332 if (!signedInPage(ctx)) return signInFirst(ctx);
333333 const form = await readForm(ctx, "admin");
334334 if (form instanceof Response) return form;
335335 const login = edgeIdentity(ctx.request, activeEdgeToken(ctx.app));
@@ -353,7 +353,7 @@ export async function edgeLink(ctx: Ctx): Promise<Response> {
353353
354354 // POST /settings/edge/unlink
355355 export async function edgeUnlink(ctx: Ctx): Promise<Response> {
356 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
356 if (!signedInPage(ctx)) return signInFirst(ctx);
357357 const form = await readForm(ctx, "admin");
358358 if (form instanceof Response) return form;
359359 if (unlinkEdgeLogin(ctx.app.db, ctx.auth.user.id))
@@ -384,7 +384,7 @@ function unverifiedNotice(ctx: Ctx): Html {
384384
385385 // POST /settings/email/verify
386386 export async function resendVerifyLink(ctx: Ctx): Promise<Response> {
387 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
387 if (!signedInPage(ctx)) return signInFirst(ctx);
388388 const form = await readForm(ctx);
389389 if (form instanceof Response) return form;
390390 const sent = await resendVerification(ctx.app, ctx.auth.user);
@@ -596,7 +596,7 @@ export function appearancePage(ctx: Ctx): Response {
596596
597597 // GET /settings/shells
598598 export function shellsPage(ctx: Ctx): Response {
599 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
599 if (!signedInPage(ctx)) return signInFirst(ctx);
600600 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
601601 const body = html`${dotfilesView(ctx)}${shellsView(ctx, ctx.auth.user)}`;
602602 return timePhase(ctx.request, "render", () => accountShell(ctx, "shells", "Shells", body));
@@ -604,7 +604,7 @@ export function shellsPage(ctx: Ctx): Response {
604604
605605 // POST /settings/shells/:id/stop
606606 export async function shellStop(ctx: Ctx): Promise<Response> {
607 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
607 if (!signedInPage(ctx)) return signInFirst(ctx);
608608 const form = await readForm(ctx, "admin");
609609 if (form instanceof Response) return form;
610610 const id = ctx.params.id ?? "";
@@ -614,7 +614,7 @@ export async function shellStop(ctx: Ctx): Promise<Response> {
614614
615615 // POST /settings/shells/stop-idle
616616 export async function shellsStopIdle(ctx: Ctx): Promise<Response> {
617 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
617 if (!signedInPage(ctx)) return signInFirst(ctx);
618618 const form = await readForm(ctx, "admin");
619619 if (form instanceof Response) return form;
620620 return flashTo(ctx, "/settings/shells", { message: stoppedIdleSays(stopIdleShells(ctx.app, ctx.auth.user.id)) });
@@ -633,7 +633,7 @@ function hostedBackupRow(dataDir: string): Html | null {
633633
634634 // GET /settings
635635 export function accountPage(ctx: Ctx): Response {
636 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
636 if (!signedInPage(ctx)) return signInFirst(ctx);
637637 const user = ctx.auth.user;
638638 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
639639 // Read in the order the page lays them out; each phase is named for what it reads.
@@ -665,7 +665,7 @@ export function accountPage(ctx: Ctx): Response {
665665
666666 // POST /settings/notify
667667 export async function notifyUpdate(ctx: Ctx): Promise<Response> {
668 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
668 if (!signedInPage(ctx)) return signInFirst(ctx);
669669 const form = await readForm(ctx, "admin");
670670 if (form instanceof Response) return form;
671671 const saved = setNotifyUrl(ctx.app.db, ctx.auth.user.id, field(form, "url"));
@@ -690,7 +690,7 @@ export async function notifyUpdate(ctx: Ctx): Promise<Response> {
690690
691691 // POST /settings/focus
692692 export async function focusUpdate(ctx: Ctx): Promise<Response> {
693 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
693 if (!signedInPage(ctx)) return signInFirst(ctx);
694694 if (ctx.auth.user.kind !== "user") return forbiddenPage(ctx, "A focus is a person's, not an agent's.");
695695 const form = await readForm(ctx, "admin");
696696 if (form instanceof Response) return form;
@@ -705,7 +705,7 @@ export async function focusUpdate(ctx: Ctx): Promise<Response> {
705705
706706 // POST /settings
707707 export async function accountUpdate(ctx: Ctx): Promise<Response> {
708 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
708 if (!signedInPage(ctx)) return signInFirst(ctx);
709709 const form = await readForm(ctx, "admin");
710710 if (form instanceof Response) return form;
711711 const displayName = field(form, "displayName").trim();
@@ -786,7 +786,7 @@ function passwordView(error?: {
786786
787787 // GET /settings/password
788788 export function passwordPage(ctx: Ctx): Response {
789 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
789 if (!signedInPage(ctx)) return signInFirst(ctx);
790790 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
791791 const standing = closeStanding(ctx.app.db, ctx.auth.user.id);
792792 const body = html`${passwordView()}${closeView(ctx, standing)}`;
@@ -796,7 +796,7 @@ export function passwordPage(ctx: Ctx): Response {
796796
797797 // POST /settings/password
798798 export async function passwordUpdate(ctx: Ctx): Promise<Response> {
799 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
799 if (!signedInPage(ctx)) return signInFirst(ctx);
800800 const form = await readForm(ctx, "admin");
801801 if (form instanceof Response) return form;
802802 const current = field(form, "current");
@@ -915,7 +915,7 @@ function tokensView(ctx: Ctx): Html {
915915 );
916916 // A site admin's token acts as admin whatever its scope (#596),
917917 // so the list says so beside it (#12466).
918 const actsAsAdmin = ctx.auth.user!.isAdmin ? badge(ACTS_AS_ADMIN_WORDS) : null;
918 const actsAsAdmin = adminPage(ctx) ? badge(ACTS_AS_ADMIN_WORDS) : null;
919919 const list = tokens.length === 0
920920 ? emptyNote("noAccessCodesYet")
921921 : html`<ul class="list setting-list">
@@ -979,7 +979,7 @@ function tokensView(ctx: Ctx): Html {
979979
980980 // GET /settings/tokens
981981 export function tokensPage(ctx: Ctx): Response {
982 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
982 if (!signedInPage(ctx)) return signInFirst(ctx);
983983 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
984984 const body = tokensView(ctx);
985985 return timePhase(ctx.request, "render", () => accountShell(ctx, "tokens", "Access codes", body));
@@ -987,7 +987,7 @@ export function tokensPage(ctx: Ctx): Response {
987987
988988 // POST /settings/tokens
989989 export async function tokenCreate(ctx: Ctx): Promise<Response> {
990 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
990 if (!signedInPage(ctx)) return signInFirst(ctx);
991991 // Minting a token must come from the account itself — a browser session,
992992 // the platform edge's sign-in, or the password — never from another token
993993 // (no privilege bootstrapping). readForm below refuses a cross-site post.
@@ -998,7 +998,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> {
998998 if (form instanceof Response) return form;
999999 // A site admin's token acts as admin, whatever its scope: minted only on
10001000 // purpose (#596), never by a form left at its defaults.
1001 if (ctx.auth.user.isAdmin && field(form, "aiAdmin") !== "on")
1001 if (adminPage(ctx) && field(form, "aiAdmin") !== "on")
10021002 return flashTo(ctx, "/settings/tokens", {
10031003 tone: "danger",
10041004 message: "You are the forge's admin: tick that you mean to give this access code admin, or make it from your everyday account.",
@@ -1024,7 +1024,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> {
10241024
10251025 // POST /settings/tokens/:id/delete
10261026 export async function tokenDelete(ctx: Ctx): Promise<Response> {
1027 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1027 if (!signedInPage(ctx)) return signInFirst(ctx);
10281028 const form = await readForm(ctx, "admin");
10291029 if (form instanceof Response) return form;
10301030 const revoked = deleteToken(ctx.app, ctx.auth.user, ctx.params.id ?? "");
@@ -1037,7 +1037,7 @@ export async function tokenDelete(ctx: Ctx): Promise<Response> {
10371037
10381038 // POST /settings/sessions/:id/delete
10391039 export async function sessionDelete(ctx: Ctx): Promise<Response> {
1040 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1040 if (!signedInPage(ctx)) return signInFirst(ctx);
10411041 const form = await readForm(ctx, "admin");
10421042 if (form instanceof Response) return form;
10431043 const user = ctx.auth.user;
@@ -1056,7 +1056,7 @@ export async function sessionDelete(ctx: Ctx): Promise<Response> {
10561056
10571057 // POST /settings/sessions/end-others
10581058 export async function sessionsOthersDelete(ctx: Ctx): Promise<Response> {
1059 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1059 if (!signedInPage(ctx)) return signInFirst(ctx);
10601060 const form = await readForm(ctx, "admin");
10611061 if (form instanceof Response) return form;
10621062 const done = signOutElsewhere(ctx.app, ctx.auth.user, cookieValue(ctx.request, "forge_session"));
@@ -1142,7 +1142,7 @@ function keysOff(ctx: Ctx): Response {
11421142
11431143 // GET /settings/keys
11441144 export function keysPage(ctx: Ctx): Response {
1145 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1145 if (!signedInPage(ctx)) return signInFirst(ctx);
11461146 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11471147 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
11481148 const body = keysView(ctx, { name: "", key: "" });
@@ -1151,7 +1151,7 @@ export function keysPage(ctx: Ctx): Response {
11511151
11521152 // POST /settings/keys
11531153 export async function keyCreate(ctx: Ctx): Promise<Response> {
1154 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1154 if (!signedInPage(ctx)) return signInFirst(ctx);
11551155 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11561156 // A key outlives the token and opens the terminal, so an rw token is
11571157 // refused here as over the API and MCP (#14762); a session is admin.
@@ -1184,7 +1184,7 @@ export async function keyCreate(ctx: Ctx): Promise<Response> {
11841184
11851185 // POST /settings/keys/:id/delete
11861186 export async function keyDelete(ctx: Ctx): Promise<Response> {
1187 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1187 if (!signedInPage(ctx)) return signInFirst(ctx);
11881188 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11891189 // A key outlives the token and opens the terminal, so an rw token is
11901190 // refused here as over the API and MCP (#14762); a session is admin.
@@ -1278,7 +1278,7 @@ function closeRefused(ctx: Ctx, said: CloseSaid): Response {
12781278
12791279 // POST /settings/account/close
12801280 export async function accountClose(ctx: Ctx): Promise<Response> {
1281 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1281 if (!signedInPage(ctx)) return signInFirst(ctx);
12821282 if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF);
12831283 const user = ctx.auth.user;
12841284 const form = await readForm(ctx, "admin");
@@ -1304,7 +1304,7 @@ const CLOSE_ITSELF = "Closing an account, or keeping it, is asked from the accou
13041304
13051305 // POST /settings/account/keep
13061306 export async function accountKeep(ctx: Ctx): Promise<Response> {
1307 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
1307 if (!signedInPage(ctx)) return signInFirst(ctx);
13081308 if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF);
13091309 const form = await readForm(ctx, "admin");
13101310 if (form instanceof Response) return form;
src/web/pages/accounts.ts +15 −15
@@ -141,8 +141,8 @@ function wayBackForms(ctx: Ctx): Html | null {
141141
142142 // POST /settings/accounts/:username/way-back — the link, shown once on the page.
143143 export async function wayBackAct(ctx: Ctx): Promise<Response> {
144 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
145 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
144 if (!signedInPage(ctx)) return signInFirst(ctx);
145 if (!adminPage(ctx)) return notFoundPage(ctx);
146146 const form = await readForm(ctx, "admin");
147147 if (form instanceof Response) return form;
148148 const username = ctx.params.username ?? "";
@@ -179,7 +179,7 @@ export function accountsPage(ctx: Ctx): Response {
179179
180180 /** The page, with what an act needs said first (`notice`) when it did not finish. */
181181 function accountsView(ctx: Ctx, notice?: Html, status = 200): Response {
182 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
182 if (!signedInPage(ctx)) return signInFirst(ctx);
183183 const user = ctx.auth.user;
184184 const listed = timePhase(ctx.request, "accounts", () =>
185185 listAccounts(ctx.app, user),
@@ -340,8 +340,8 @@ function isOtherAdmin(ctx: Ctx, username: string): boolean {
340340
341341 // GET /settings/accounts/:username — one person, on one screen, with what an admin may do
342342 export function personSignInsPage(ctx: Ctx): Response {
343 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
344 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
343 if (!signedInPage(ctx)) return signInFirst(ctx);
344 if (!adminPage(ctx)) return notFoundPage(ctx);
345345 const username = ctx.params.username ?? "";
346346 const named = getUserByName(ctx.app.db, username);
347347 // An organization has no sign-ins: its page is its model grant and spend ceilings.
@@ -441,8 +441,8 @@ export function personSignInsPage(ctx: Ctx): Response {
441441 // POST /settings/accounts/:username/(reset|end-sessions)
442442 export function accessAct(act: "reset" | "end-sessions") {
443443 return async (ctx: Ctx): Promise<Response> => {
444 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
445 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
444 if (!signedInPage(ctx)) return signInFirst(ctx);
445 if (!adminPage(ctx)) return notFoundPage(ctx);
446446 const form = await readForm(ctx, "admin");
447447 if (form instanceof Response) return form;
448448 const username = ctx.params.username ?? "";
@@ -468,8 +468,8 @@ export function accessAct(act: "reset" | "end-sessions") {
468468 // POST /settings/accounts/:username/(tokens|sessions)/:id/delete
469469 export function signInAct(what: "token" | "session") {
470470 return async (ctx: Ctx): Promise<Response> => {
471 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
472 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
471 if (!signedInPage(ctx)) return signInFirst(ctx);
472 if (!adminPage(ctx)) return notFoundPage(ctx);
473473 const form = await readForm(ctx, "admin");
474474 if (form instanceof Response) return form;
475475 const username = ctx.params.username ?? "";
@@ -503,8 +503,8 @@ const DONE: Readonly<Record<Act, string>> = {
503503 // POST /settings/accounts/:username/(suspend|unsuspend|remove)
504504 export function accountAct(act: Act) {
505505 return async (ctx: Ctx): Promise<Response> => {
506 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
507 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
506 if (!signedInPage(ctx)) return signInFirst(ctx);
507 if (!adminPage(ctx)) return notFoundPage(ctx);
508508 const form = await readForm(ctx, "admin");
509509 if (form instanceof Response) return form;
510510 const username = ctx.params.username ?? "";
@@ -548,8 +548,8 @@ export function accountAct(act: Act) {
548548
549549 // GET /settings/accounts/:username/retire — everything removal would take; removes nothing
550550 export function retirePage(ctx: Ctx): Response {
551 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
552 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
551 if (!signedInPage(ctx)) return signInFirst(ctx);
552 if (!adminPage(ctx)) return notFoundPage(ctx);
553553 const username = ctx.params.username ?? "";
554554 const plan = retirementPlan(ctx.app, ctx.auth.user, username);
555555 if (!plan.ok)
@@ -606,8 +606,8 @@ export function retirePage(ctx: Ctx): Response {
606606
607607 // POST /settings/accounts/:username/retire
608608 export async function retireAct(ctx: Ctx): Promise<Response> {
609 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
610 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
609 if (!signedInPage(ctx)) return signInFirst(ctx);
610 if (!adminPage(ctx)) return notFoundPage(ctx);
611611 const form = await readForm(ctx, "admin");
612612 if (form instanceof Response) return form;
613613 const username = ctx.params.username ?? "";
src/web/pages/admin-limits.ts +8 −8
@@ -29,7 +29,7 @@ import { btn, confirmAction, icon, row, time } from "../ui.ts";
2929 import { emptyList } from "../empty_words.ts";
3030 import { plansRow } from "../settings/plans.ts";
3131 import { accountSections } from "./origins.ts";
32 import { adminPage } from "../../http/page_may.ts";
32 import { personAdminPage } from "../../http/page_may.ts";
3333
3434 // GET /admin/limits
3535 export function limitsPage(ctx: Ctx): Response {
@@ -258,7 +258,7 @@ export function limitsPage(ctx: Ctx): Response {
258258 // POST /admin/limits
259259 export async function limitsSet(ctx: Ctx): Promise<Response> {
260260 // Checked before the body is read: a non-admin learns nothing of the door.
261 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
261 if (!personAdminPage(ctx))
262262 return notFoundPage(ctx);
263263 const form = await readForm(ctx, "admin");
264264 if (form instanceof Response) return form;
@@ -294,7 +294,7 @@ export async function limitsSet(ctx: Ctx): Promise<Response> {
294294
295295 // POST /admin/quotas
296296 export async function quotasSet(ctx: Ctx): Promise<Response> {
297 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
297 if (!personAdminPage(ctx))
298298 return notFoundPage(ctx);
299299 const form = await readForm(ctx, "admin");
300300 if (form instanceof Response) return form;
@@ -315,7 +315,7 @@ export async function quotasSet(ctx: Ctx): Promise<Response> {
315315
316316 // POST /admin/signup
317317 export async function signupSet(ctx: Ctx): Promise<Response> {
318 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
318 if (!personAdminPage(ctx))
319319 return notFoundPage(ctx);
320320 const form = await readForm(ctx, "admin");
321321 if (form instanceof Response) return form;
@@ -332,7 +332,7 @@ export async function signupSet(ctx: Ctx): Promise<Response> {
332332
333333 // POST /admin/agent-start
334334 export async function agentStartSet(ctx: Ctx): Promise<Response> {
335 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
335 if (!personAdminPage(ctx)) return notFoundPage(ctx);
336336 const form = await readForm(ctx, "admin");
337337 if (form instanceof Response) return form;
338338 const changed = changeAgentStart(ctx.app, ctx.auth.user, field(form, "agent_start"));
@@ -348,7 +348,7 @@ export async function agentStartSet(ctx: Ctx): Promise<Response> {
348348
349349 // POST /admin/billing-links
350350 export async function billingLinksSet(ctx: Ctx): Promise<Response> {
351 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
351 if (!personAdminPage(ctx)) return notFoundPage(ctx);
352352 const form = await readForm(ctx, "admin");
353353 if (form instanceof Response) return form;
354354 const changed = changeBillingLinks(
@@ -368,7 +368,7 @@ export async function billingLinksSet(ctx: Ctx): Promise<Response> {
368368
369369 // POST /admin/invites
370370 export async function inviteMint(ctx: Ctx): Promise<Response> {
371 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
371 if (!personAdminPage(ctx))
372372 return notFoundPage(ctx);
373373 const form = await readForm(ctx, "admin");
374374 if (form instanceof Response) return form;
@@ -390,7 +390,7 @@ export async function inviteMint(ctx: Ctx): Promise<Response> {
390390
391391 // POST /admin/invites/:id/revoke
392392 export async function inviteRevoke(ctx: Ctx): Promise<Response> {
393 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
393 if (!personAdminPage(ctx))
394394 return notFoundPage(ctx);
395395 const form = await readForm(ctx, "admin");
396396 if (form instanceof Response) return form;
src/web/pages/advisories.ts +2 −2
@@ -14,10 +14,10 @@ import { field, readForm } from "../form.ts";
1414 import { html } from "../html.ts";
1515 import { flashTo, page } from "../layout.ts";
1616 import { badge, btn, disclosure, empty, listCard, row } from "../ui.ts";
17 import { adminPage } from "../../http/page_may.ts";
17 import { personAdminPage, signedInPage } from "../../http/page_may.ts";
1818
1919 const gate = (ctx: Ctx): Response | undefined =>
20 !ctx.auth.user ? signInFirst(ctx) : adminPage(ctx, "advisories", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx);
20 !signedInPage(ctx) ? signInFirst(ctx) : personAdminPage(ctx) ? undefined : notFoundPage(ctx);
2121
2222 const line = (a: Seen) =>
2323 row({
src/web/pages/app_templates.ts +3 −4
@@ -15,12 +15,11 @@ import { flashTo, page } from "../layout.ts";
1515 import { btn, empty, field as formField, icon, row } from "../ui.ts";
1616 import { emptyLine } from "../empty_words.ts";
1717 import { accountSections } from "./origins.ts";
18 import { adminPage } from "../../http/page_may.ts";
18 import { adminPage, signedInPage } from "../../http/page_may.ts";
1919
2020 function denied(ctx: Ctx): Response | undefined {
21 const user = ctx.auth.user;
22 if (!user) return signInFirst(ctx);
23 if (adminPage(ctx, "app_templates", user.isAdmin && user.kind === "user")) return undefined;
21 if (!signedInPage(ctx)) return signInFirst(ctx);
22 if (adminPage(ctx) && ctx.auth.user.kind === "user") return undefined;
2423 return page(
2524 {
2625 ctx,
src/web/pages/app_variants.ts +1 −1
@@ -99,7 +99,7 @@ type Verb = (ctx: Ctx, repo: NonNullable<ReturnType<typeof loadRepo>>, form: For
9999 async function mutate(ctx: Ctx, verb: Verb): Promise<Response> {
100100 const repo = loadRepo(ctx);
101101 if (!repo) return notFoundPage(ctx);
102 if (!signedInPage(ctx, "app_variants")) return signInFirst(ctx);
102 if (!signedInPage(ctx)) return signInFirst(ctx);
103103 const form = await readForm(ctx, "rw");
104104 if (form instanceof Response) return form;
105105 return verb(ctx, repo, form);
src/web/pages/apps.ts +4 −4
@@ -438,7 +438,7 @@ function newAppForm(
438438
439439 // GET /apps/new
440440 export async function newAppPage(ctx: Ctx): Promise<Response> {
441 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
441 if (!signedInPage(ctx)) return signInFirst(ctx);
442442 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
443443 const picks = plannerOffered(ctx);
444444 const offered = await timePhaseAsync(ctx.request, "templates", () => templateChoices(ctx.app, ctx.auth.user));
@@ -462,7 +462,7 @@ export async function newAppPage(ctx: Ctx): Promise<Response> {
462462
463463 // POST /apps/new
464464 export async function newAppSubmit(ctx: Ctx): Promise<Response> {
465 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
465 if (!signedInPage(ctx)) return signInFirst(ctx);
466466 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
467467 const form = await readForm(ctx, "rw");
468468 if (form instanceof Response) return form;
@@ -814,7 +814,7 @@ function appsOpenResponse(ctx: Ctx): Response {
814814 // up: a private app and a name nobody holds answer alike (#13678).
815815 const target = resolveAppHostname(ctx.app, runtime.options.domain, host);
816816 if (target === undefined) return notFoundPage(ctx);
817 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
817 if (!signedInPage(ctx)) return signInFirst(ctx);
818818 if (target === "unknown") return notFoundPage(ctx);
819819 const repo = getRepoById(ctx.app.db, target.app.repoId);
820820 if (!repo) return notFoundPage(ctx);
@@ -865,7 +865,7 @@ async function envForm(
865865 ): Promise<{ repo: Repo; env: string; user: User } | Response> {
866866 const repo = loadRepo(ctx);
867867 if (!repo) return notFoundPage(ctx);
868 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
868 if (!signedInPage(ctx)) return signInFirst(ctx);
869869 const form = await readForm(ctx, "rw");
870870 if (form instanceof Response) return form;
871871 return { repo, env: ctx.params.env ?? "", user: ctx.auth.user };
src/web/pages/archive.ts +2 −1
@@ -19,6 +19,7 @@ import { html, type Html } from "../html.ts";
1919 import { page, redirect } from "../layout.ts";
2020 import { time } from "../time_element.ts";
2121 import { btn, row, rowList } from "../ui.ts";
22 import { signedInPage } from "../../http/page_may.ts";
2223
2324 const KIND_WORD: Record<ArchivedKind, string> = { app: "app", repository: "repository", conversation: "conversation" };
2425
@@ -84,8 +85,8 @@ async function move(ctx: Ctx, user: User, kind: string, id: string, archived: bo
8485
8586 /** The two posts: unarchive (its receipt's Undo archives again) and its undo. */
8687 async function archivePost(ctx: Ctx, archived: boolean): Promise<Response> {
88 if (!signedInPage(ctx)) return signInFirst(ctx);
8789 const user = ctx.auth.user;
88 if (!user) return signInFirst(ctx);
8990 const form = await readForm(ctx, "admin");
9091 if (form instanceof Response) return form;
9192 const kind = String(form.get("kind") ?? "");
src/web/pages/audit.ts +1 −1
@@ -385,7 +385,7 @@ export async function auditCsv(ctx: Ctx): Promise<Response> {
385385 export async function auditProbeSubmit(ctx: Ctx): Promise<Response> {
386386 const repo = loadRepo(ctx);
387387 if (!repo) return notFoundPage(ctx);
388 if (!signedInPage(ctx, "audit")) return signInFirst(ctx);
388 if (!signedInPage(ctx)) return signInFirst(ctx);
389389 const form = await readForm(ctx, "rw");
390390 if (form instanceof Response) return form;
391391 if (!canWrite(ctx.app.db, repo, ctx.auth.user))
src/web/pages/backups.ts +6 −6
@@ -57,8 +57,8 @@ import { badge, btn, fileSize, icon, row, time } from "../ui.ts";
5757 import { accountSections } from "./origins.ts";
5858
5959 function requireAdmin(ctx: Ctx): Response | undefined {
60 if (!signedInPage(ctx, "backups")) return signInFirst(ctx);
61 if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
60 if (!signedInPage(ctx)) return signInFirst(ctx);
61 if (!adminPage(ctx)) return notFoundPage(ctx);
6262 return undefined;
6363 }
6464
@@ -227,7 +227,7 @@ function drilled(d: ResilienceRow): Html {
227227
228228 /** Each failure domain and its last drill; nothing when the viewer may not read them. */
229229 function domainsCard(ctx: Ctx): Html | null {
230 if (!ctx.auth.user) return null;
230 if (!signedInPage(ctx)) return null;
231231 const listed = listResilience(ctx.app, ctx.auth.user);
232232 if (!listed.ok) return null;
233233 const rows = listed.value.map((d) => {
@@ -291,7 +291,7 @@ export async function backupsPage(ctx: Ctx): Promise<Response> {
291291
292292 /** GET /settings/backups/live — the moving part alone, which the page refetches on an event. */
293293 export async function backupsLive(ctx: Ctx): Promise<Response> {
294 if (!adminPage(ctx, "backups", ctx.auth.user?.isAdmin === true)) return fragment(html``, { status: 404 });
294 if (!adminPage(ctx)) return fragment(html``, { status: 404 });
295295 const svc = snapshotsOf(ctx.app);
296296 if (svc === undefined || svc.store === undefined) return fragment(html``, { status: 404 });
297297 return fragment(await movingPart(ctx, svc, svc.store), { request: ctx.request });
@@ -657,8 +657,8 @@ export function lanesCard(ctx: Ctx): Html | "" {
657657
658658 /** POST /settings/backups/drill — restore the newest snapshot, keep what came of it. */
659659 export async function backupsDrill(ctx: Ctx): Promise<Response> {
660 if (!signedInPage(ctx, "backups")) return signInFirst(ctx);
661 if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin))
660 if (!signedInPage(ctx)) return signInFirst(ctx);
661 if (!adminPage(ctx))
662662 return new Response("Forbidden", {
663663 status: 403,
664664 headers: { "content-type": "text/plain; charset=utf-8" },
src/web/pages/billing.ts +15 −17
@@ -5,7 +5,7 @@
55 * Anyone else gets the not-found page.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
8 import { signedInPage, personAdminPage } from "../../http/page_may.ts";
99 import { sshOn } from "../../settings/ssh.ts";
1010 import { emptyNote } from "../empty_words.ts";
1111 import { ledBlock } from "./visitors.ts";
@@ -44,8 +44,6 @@ interface Shown {
4444 readonly link: string;
4545 }
4646
47 const isPerson = (ctx: Ctx): boolean => ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent";
48
4947 const day = (iso: string): string => iso.slice(0, 10);
5048
5149 /** The Codes section: make one, copy it once, then one line per code with its one action. */
@@ -109,7 +107,7 @@ const codeWords = (e: CodeError): string => (e === "not_found" ? "Not found" : C
109107 * not a loss.
110108 */
111109 function soldSection(ctx: Ctx): Html | null {
112 if (!isPerson(ctx)) return null;
110 if (!personAdminPage(ctx)) return null;
113111 const sold = soldRows(ctx.app.db);
114112 if (sold.length === 0) return null;
115113 return html`<section class="settings-block" id="sold" data-sold>
@@ -148,7 +146,7 @@ function linksSection(ctx: Ctx, r: Refused | undefined): Html | null {
148146
149147 /** The one billing-portal address every paying forge's Plan row links to. */
150148 function portalSection(ctx: Ctx, r: Refused | undefined): Html | null {
151 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return null;
149 if (!personAdminPage(ctx)) return null;
152150 return html`<section class="settings-block" id="portal">
153151 <h2>Billing portal</h2>
154152 <p class="muted small">Stripe's customer-portal sign-in. A forge that pays through Stripe links its owner here to change a card; empty shows no link.</p>
@@ -161,7 +159,7 @@ function portalSection(ctx: Ctx, r: Refused | undefined): Html | null {
161159
162160 // POST /settings/billing/portal
163161 export async function billingSetPortal(ctx: Ctx): Promise<Response> {
164 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
162 if (!personAdminPage(ctx)) return notFoundPage(ctx);
165163 const form = await readForm(ctx, "admin");
166164 if (form instanceof Response) return form;
167165 const value = field(form, "portal_url");
@@ -173,7 +171,7 @@ export async function billingSetPortal(ctx: Ctx): Promise<Response> {
173171
174172 // POST /settings/billing/links
175173 export async function billingSetLinks(ctx: Ctx): Promise<Response> {
176 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
174 if (!personAdminPage(ctx)) return notFoundPage(ctx);
177175 const form = await readForm(ctx, "admin");
178176 if (form instanceof Response) return form;
179177 const current = readBillingLinks(ctx.app, ctx.auth.user);
@@ -216,7 +214,7 @@ function lapseWords(l: Lapse): string {
216214 // GET /settings/billing
217215 export function billingPage(ctx: Ctx): Response {
218216 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
219 if (!signedInPage(ctx, "billing")) return signInFirst(ctx);
217 if (!signedInPage(ctx)) return signInFirst(ctx);
220218 return billingView(ctx);
221219 }
222220
@@ -313,7 +311,7 @@ function billingView(ctx: Ctx, shown?: Shown, status = 200, refusal?: Refused):
313311
314312 // POST /settings/billing/codes
315313 export async function billingMakeCode(ctx: Ctx): Promise<Response> {
316 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
314 if (!personAdminPage(ctx)) return notFoundPage(ctx);
317315 const form = await readForm(ctx, "admin");
318316 if (form instanceof Response) return form;
319317 const values = { kind: field(form, "kind"), plan: field(form, "plan"), uses: field(form, "uses"), note: field(form, "note"), expires: field(form, "expires") };
@@ -324,7 +322,7 @@ export async function billingMakeCode(ctx: Ctx): Promise<Response> {
324322
325323 // POST /settings/billing/codes/revoke
326324 export async function billingRevokeCode(ctx: Ctx): Promise<Response> {
327 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
325 if (!personAdminPage(ctx)) return notFoundPage(ctx);
328326 const form = await readForm(ctx, "admin");
329327 if (form instanceof Response) return form;
330328 const done = revoke(ctx.app, ctx.auth.user, field(form, "id"));
@@ -362,14 +360,14 @@ function changeView(ctx: Ctx, forge: string, plan: string, refused = false): Res
362360
363361 // GET /settings/billing/change?forge=&plan= — the preview, before the confirm.
364362 export function billingChange(ctx: Ctx): Response {
365 if (!signedInPage(ctx, "billing")) return signInFirst(ctx);
366 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
363 if (!signedInPage(ctx)) return signInFirst(ctx);
364 if (!personAdminPage(ctx)) return notFoundPage(ctx);
367365 return changeView(ctx, ctx.url.searchParams.get("forge") ?? "", ctx.url.searchParams.get("plan") ?? "");
368366 }
369367
370368 // POST /settings/billing/grant — the confirm: it must carry what the preview showed.
371369 export async function billingGrant(ctx: Ctx): Promise<Response> {
372 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
370 if (!personAdminPage(ctx)) return notFoundPage(ctx);
373371 const form = await readForm(ctx, "admin");
374372 if (form instanceof Response) return form;
375373 const forge = field(form, "forge");
@@ -389,7 +387,7 @@ const back = (ctx: Ctx, r: { ok: true; message: string } | { ok: false; error: B
389387
390388 // POST /settings/billing/stripe/connect
391389 export async function stripeConnect(ctx: Ctx): Promise<Response> {
392 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
390 if (!personAdminPage(ctx)) return notFoundPage(ctx);
393391 const form = await readForm(ctx, "admin");
394392 if (form instanceof Response) return form;
395393 const r = await connectStripe(ctx.app, ctx.auth.user, field(form, "key"), field(form, "secret"));
@@ -398,7 +396,7 @@ export async function stripeConnect(ctx: Ctx): Promise<Response> {
398396
399397 // POST /settings/billing/stripe/secret
400398 export async function stripeSecret(ctx: Ctx): Promise<Response> {
401 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
399 if (!personAdminPage(ctx)) return notFoundPage(ctx);
402400 const form = await readForm(ctx, "admin");
403401 if (form instanceof Response) return form;
404402 const r = saveSigningSecret(ctx.app, ctx.auth.user, field(form, "secret"));
@@ -407,7 +405,7 @@ export async function stripeSecret(ctx: Ctx): Promise<Response> {
407405
408406 // POST /settings/billing/stripe/disconnect
409407 export async function stripeDisconnect(ctx: Ctx): Promise<Response> {
410 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
408 if (!personAdminPage(ctx)) return notFoundPage(ctx);
411409 const form = await readForm(ctx, "admin");
412410 if (form instanceof Response) return form;
413411 const r = await disconnectStripe(ctx.app, ctx.auth.user);
@@ -417,7 +415,7 @@ export async function stripeDisconnect(ctx: Ctx): Promise<Response> {
417415 // POST /settings/billing/orders/retry — an admin who is a person retries a paid order whose forge
418416 // was not made.
419417 export async function orderRetry(ctx: Ctx): Promise<Response> {
420 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
418 if (!personAdminPage(ctx)) return notFoundPage(ctx);
421419 const form = await readForm(ctx, "admin");
422420 if (form instanceof Response) return form;
423421 const r = await retryOrder(ctx.app, ctx.auth.user, field(form, "id"));
src/web/pages/board.ts +6 −5
@@ -128,6 +128,7 @@ import { appsRuntime } from "../../apps/runtime_registry.ts";
128128 import { lookUrl } from "../../core/looks.ts";
129129 import { thumbLook } from "./looks.ts";
130130 import { milestoneHref } from "./milestones.ts";
131 import { adminPage, signedInPage } from "../../http/page_may.ts";
131132
132133 // ---- words ----
133134
@@ -241,8 +242,8 @@ export async function boardPage(ctx: Ctx): Promise<Response> {
241242 // The kiosk is the cockpit (#1152): one screen, four keys, no top bar.
242243 if (ctx.url.searchParams.has("kiosk")) return cockpitPage(ctx, true);
243244 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
245 if (!signedInPage(ctx)) return signInFirst(ctx);
244246 const user = ctx.auth.user;
245 if (!user) return signInFirst(ctx);
246247 const db = ctx.app.db;
247248 const rq = ctx.request;
248249 const visible = timePhase(rq, "repos", () => listReposVisibleTo(db, user, { limit: 200 }));
@@ -427,7 +428,7 @@ function moneyStrip(ctx: Ctx): Html | null {
427428 * cloud body is configured. Nobody else pays for the reads.
428429 */
429430 function forgeNotes(ctx: Ctx): { notes: Note[]; ok: boolean; placement: Html | null } | null {
430 if (!ctx.auth.user?.isAdmin) return null;
431 if (!adminPage(ctx)) return null;
431432 const v = forgeVitals(ctx.app);
432433 const fh = forgeHealth();
433434 const verdict = forgeVerdict(fh, Date.now());
@@ -504,8 +505,8 @@ function reviewNotes(ctx: Ctx, scope: BoardScope): Note[] {
504505 * anything has asked.
505506 */
506507 function asksStrip(ctx: Ctx): Html | null {
508 if (!signedInPage(ctx)) return null;
507509 const user = ctx.auth.user;
508 if (!user) return null;
509510 const m = askMeasureWeek(ctx.app.db, user.id);
510511 if (asksMeasureEmpty(m)) return null;
511512 return html`<a class="muted small" id="asks-measure" href="/?waits=me"
@@ -528,8 +529,8 @@ function asksStrip(ctx: Ctx): Html | null {
528529 * viewer holds no owner facts here or nothing ran.
529530 */
530531 function returnsStrip(ctx: Ctx, scope: BoardScope): Html | null {
532 if (!signedInPage(ctx)) return null;
531533 const user = ctx.auth.user;
532 if (!user) return null;
533534 // The crew spends on every repository, app or not: the whole of the
534535 // viewer's own unless `?apps=` narrows the board.
535536 const apps = ctx.url.searchParams.get("apps");
@@ -644,7 +645,7 @@ function figures(parts: readonly FigureWords[]): Html {
644645 * its own.
645646 */
646647 function windowsStrip(ctx: Ctx): Html | null {
647 if (!ctx.auth.user?.isAdmin) return null;
648 if (!adminPage(ctx)) return null;
648649 const db = ctx.app.db;
649650 const pool = listCredentials(db);
650651 if (pool.length === 0) return null;
src/web/pages/boards-index-stream.ts +2 −3
@@ -15,7 +15,7 @@ import type { Ctx } from "../../http/context.ts";
1515 import { background } from "../../perf/jobs.ts";
1616 import { eventStream } from "../../http/sse.ts";
1717 import { notFoundPage } from "../chrome.ts";
18 import { adminPage } from "../../http/page_may.ts";
18 import { personAdminPage } from "../../http/page_may.ts";
1919
2020 /** A burst of events is read once, this long after the first. */
2121 export const SETTLE_MS = 100;
@@ -28,8 +28,7 @@ export function readNumbers(app: App, now = Date.now()): Numbers {
2828 }
2929
3030 export function boardsIndexStream(ctx: Ctx): Response {
31 const u = ctx.auth.user;
32 if (!adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent")) return notFoundPage(ctx);
31 if (!personAdminPage(ctx)) return notFoundPage(ctx);
3332 const { app } = ctx;
3433 return eventStream(app, ctx.request, (emit, _close, ready) => {
3534 let sent = readNumbers(app);
src/web/pages/boards-stream.ts +2 −3
@@ -12,12 +12,11 @@ import { isSlug } from "../../boards/store.ts";
1212 import type { Ctx } from "../../http/context.ts";
1313 import { eventStream } from "../../http/sse.ts";
1414 import { notFoundPage } from "../chrome.ts";
15 import { adminPage } from "../../http/page_may.ts";
15 import { personAdminPage } from "../../http/page_may.ts";
1616
1717 export async function boardStream(ctx: Ctx): Promise<Response> {
18 const u = ctx.auth.user;
1918 const slug = ctx.params.slug ?? "";
20 if (u === undefined || !adminPage(ctx, "boards-stream", u.isAdmin && u.kind !== "agent") || !isSlug(slug)) return notFoundPage(ctx);
19 if (!personAdminPage(ctx) || !isSlug(slug)) return notFoundPage(ctx);
2120 const view = readView(ctx.url.searchParams);
2221 const picture = await boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined);
2322 if (picture === undefined || isFailed(picture) || picture.board === null) return notFoundPage(ctx);
src/web/pages/boards-view.ts +3 −6
@@ -38,7 +38,7 @@ import { boardMarks } from "../../boards/marks.ts";
3838 import { drawnPanel, panelData, runFor, type PanelDrawn } from "../../boards/panel_data.ts";
3939 import { readParams } from "../../boards/params.ts";
4040 import { paramsOf, queryFields } from "./boards.ts";
41 import { adminPage } from "../../http/page_may.ts";
41 import { personAdminPage, signedInPage } from "../../http/page_may.ts";
4242
4343 const sizes = (max: number, word: string, now: number) =>
4444 [1, 2, 3].slice(0, max).map((n) => ({ value: String(n), label: `${String(n)} ${word}`, selected: n === now }));
@@ -90,10 +90,7 @@ function grid(app: App, slug: string, board: Board, panels: readonly PanelDrawn[
9090 </section>`;
9191 }
9292
93 const denied = (ctx: Ctx) => {
94 const u = ctx.auth.user;
95 return !adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent");
96 };
93 const denied = (ctx: Ctx) => !personAdminPage(ctx);
9794
9895 /**
9996 * Start reading `/boards`' picture now and draw the panel once from it, so the
@@ -118,8 +115,8 @@ const liveLine = (paused: boolean): Html =>
118115
119116 export async function boardsList(ctx: Ctx): Promise<Response> {
120117 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
118 if (!signedInPage(ctx)) return signInFirst(ctx);
121119 const user = ctx.auth.user;
122 if (user === undefined) return signInFirst(ctx);
123120 if (denied(ctx)) {
124121 // Not a forge admin: the page is the holds of the repositories they administer, or not found.
125122 const holds = boardsHoldsCard(ctx.app.db, user);
src/web/pages/boards.ts +3 −3
@@ -24,7 +24,7 @@ import { btn, card, chartFrame, empty, field, selectField } from "../ui.ts";
2424 import { count, figure, figures, fold, reading, readingFailed, readingReplaceJs } from "../figure.ts";
2525 import { readForm } from "../form.ts";
2626 import { emptyList } from "../empty_words.ts";
27 import { adminPage } from "../../http/page_may.ts";
27 import { personAdminPage } from "../../http/page_may.ts";
2828
2929 const AGGREGATES = ["count", "sum", "avg", "max"] as const;
3030 const OPS = ["eq", "ne", "lt", "lte", "gt", "gte", "starts"] as const;
@@ -106,16 +106,16 @@ export function paramsOf(q: Record<string, unknown>, chart: Chart = "line"): Par
106106
107107 // GET /boards/data: a `?ask=` sentence is read by the rules only, so no link can spend the model.
108108 export async function boardsPage(ctx: Ctx): Promise<Response> {
109 if (!personAdminPage(ctx)) return notFoundPage(ctx);
109110 const user = ctx.auth.user;
110 if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
111111 return explorer(ctx, user, ctx.url.searchParams.get("ask"), false);
112112 }
113113
114114 // POST /boards/data: the page's own sentence box. Only here may a miss ask the model, which spends the
115115 // asker's budget; `readForm` refuses a form another site sent (`crossOrigin`), as every mutation is.
116116 export async function boardsAsk(ctx: Ctx): Promise<Response> {
117 if (!personAdminPage(ctx)) return notFoundPage(ctx);
117118 const user = ctx.auth.user;
118 if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
119119 const form = await readForm(ctx, "admin");
120120 if (form instanceof Response) return form;
121121 const asked = form.get("ask");
src/web/pages/bottleneck.ts +1 −1
@@ -32,7 +32,7 @@ function opRow(o: Op): Html {
3232
3333 export async function bottleneckPage(ctx: Ctx): Promise<Response> {
3434 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
35 if (!signedInPage(ctx, "bottleneck")) return signInFirst(ctx);
35 if (!signedInPage(ctx)) return signInFirst(ctx);
3636 const reader = telemetryReader(ctx.app, ctx.auth.user);
3737 if (reader?.kind !== "owner") return notFoundPage(ctx);
3838 const rendering = performance.now();
src/web/pages/branches.ts +2 −2
@@ -421,7 +421,7 @@ export async function renderBranches(
421421 export async function branchCreate(ctx: Ctx): Promise<Response> {
422422 const repo = loadRepo(ctx);
423423 if (!repo) return notFoundPage(ctx);
424 if (!signedInPage(ctx, "branches")) return signInFirst(ctx);
424 if (!signedInPage(ctx)) return signInFirst(ctx);
425425 const form = await readForm(ctx, "rw");
426426 if (form instanceof Response) return form;
427427
@@ -447,7 +447,7 @@ export async function branchCreate(ctx: Ctx): Promise<Response> {
447447 export async function branchDelete(ctx: Ctx): Promise<Response> {
448448 const repo = loadRepo(ctx);
449449 if (!repo) return notFoundPage(ctx);
450 if (!signedInPage(ctx, "branches")) return signInFirst(ctx);
450 if (!signedInPage(ctx)) return signInFirst(ctx);
451451 const form = await readForm(ctx, "rw");
452452 if (form instanceof Response) return form;
453453
src/web/pages/builds.ts +4 −4
@@ -77,7 +77,7 @@ export async function buildsPage(ctx: Ctx): Promise<Response> {
7777 export async function deletePinSubmit(ctx: Ctx): Promise<Response> {
7878 const repo = loadRepo(ctx);
7979 if (!repo) return notFoundPage(ctx);
80 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
80 if (!signedInPage(ctx)) return signInFirst(ctx);
8181 const form = await readForm(ctx, "rw");
8282 if (form instanceof Response) return form;
8383 const gone = await deletePin(ctx.app, ctx.auth.user, repo, ctx.params.label ?? "");
@@ -154,7 +154,7 @@ export async function newBuildPage(ctx: Ctx): Promise<Response> {
154154 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
155155 const repo = loadRepo(ctx);
156156 if (!repo) return notFoundPage(ctx);
157 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
157 if (!signedInPage(ctx)) return signInFirst(ctx);
158158 if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx);
159159 const base = repoBase(repo);
160160 const dir = repoDir(ctx.app.reposRoot, repo.ownerName, repo.name);
@@ -223,7 +223,7 @@ const PIN_ERRORS: Record<string, string> = {
223223 export async function pinBuildSubmit(ctx: Ctx): Promise<Response> {
224224 const repo = loadRepo(ctx);
225225 if (!repo) return notFoundPage(ctx);
226 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
226 if (!signedInPage(ctx)) return signInFirst(ctx);
227227 const form = await readForm(ctx, "rw");
228228 if (form instanceof Response) return form;
229229 const base = repoBase(repo);
@@ -258,7 +258,7 @@ const PREVIEW_ERRORS: Record<string, string> = {
258258 export async function previewBuildSubmit(ctx: Ctx): Promise<Response> {
259259 const repo = loadRepo(ctx);
260260 if (!repo) return notFoundPage(ctx);
261 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
261 if (!signedInPage(ctx)) return signInFirst(ctx);
262262 const form = await readForm(ctx, "rw");
263263 if (form instanceof Response) return form;
264264 const preview = await previewBuild(ctx.app, ctx.auth.user, repo, formValue(form, "sha"));
src/web/pages/capacity.ts +2 −2
@@ -27,8 +27,8 @@ import { lentLine } from "../../checks/lent_scope.ts";
2727 import { lentIn } from "../../checks/runner_jobs.ts";
2828
2929 function requireAdmin(ctx: Ctx): Response | undefined {
30 if (!signedInPage(ctx, "capacity")) return signInFirst(ctx);
31 if (!adminPage(ctx, "capacity", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
30 if (!signedInPage(ctx)) return signInFirst(ctx);
31 if (!adminPage(ctx)) return notFoundPage(ctx);
3232 return undefined;
3333 }
3434
src/web/pages/chain.ts +5 −5
@@ -184,7 +184,7 @@ export async function chainPage(ctx: Ctx): Promise<Response> {
184184 export async function severSubmit(ctx: Ctx): Promise<Response> {
185185 const repo = loadRepo(ctx);
186186 if (!repo) return notFoundPage(ctx);
187 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
187 if (!signedInPage(ctx)) return signInFirst(ctx);
188188 const form = await readForm(ctx, "rw");
189189 if (form instanceof Response) return form;
190190 const to = `${repoBase(repo)}/following`;
@@ -203,7 +203,7 @@ export async function severSubmit(ctx: Ctx): Promise<Response> {
203203 export async function checkSubmit(ctx: Ctx): Promise<Response> {
204204 const repo = loadRepo(ctx);
205205 if (!repo) return notFoundPage(ctx);
206 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
206 if (!signedInPage(ctx)) return signInFirst(ctx);
207207 const form = await readForm(ctx, "rw");
208208 if (form instanceof Response) return form;
209209 const to = `${repoBase(repo)}/following`;
@@ -218,7 +218,7 @@ export async function checkSubmit(ctx: Ctx): Promise<Response> {
218218 export async function takeSubmit(ctx: Ctx): Promise<Response> {
219219 const repo = loadRepo(ctx);
220220 if (!repo) return notFoundPage(ctx);
221 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
221 if (!signedInPage(ctx)) return signInFirst(ctx);
222222 const form = await readForm(ctx, "rw");
223223 if (form instanceof Response) return form;
224224 const to = `${repoBase(repo)}/following`;
@@ -238,7 +238,7 @@ export async function takeSubmit(ctx: Ctx): Promise<Response> {
238238 export async function modeSubmit(ctx: Ctx): Promise<Response> {
239239 const repo = loadRepo(ctx);
240240 if (!repo) return notFoundPage(ctx);
241 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
241 if (!signedInPage(ctx)) return signInFirst(ctx);
242242 const form = await readForm(ctx, "rw");
243243 if (form instanceof Response) return form;
244244 const to = `${repoBase(repo)}/following`;
@@ -254,7 +254,7 @@ export async function modeSubmit(ctx: Ctx): Promise<Response> {
254254 export async function proposeParentSubmit(ctx: Ctx): Promise<Response> {
255255 const repo = loadRepo(ctx);
256256 if (!repo) return notFoundPage(ctx);
257 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
257 if (!signedInPage(ctx)) return signInFirst(ctx);
258258 const form = await readForm(ctx, "rw");
259259 if (form instanceof Response) return form;
260260 const to = `${repoBase(repo)}/following`;
src/web/pages/changelog.ts +2 −1
@@ -40,6 +40,7 @@ import { shippedHeld } from "../../release/answer.ts";
4040 import { html, type Html } from "../html.ts";
4141 import { page } from "../layout.ts";
4242 import { badge, row, seg, sha, time, timeAgo } from "../ui.ts";
43 import { signedInPage } from "../../http/page_may.ts";
4344
4445 /** Where the live client looks: a merge lands, or production serves a commit. */
4546 const LIVE = "pull.merged,app.serving";
@@ -463,7 +464,7 @@ function older(more: string | undefined, last: string | undefined, choice: strin
463464 export function cacheHeaders(ctx: Ctx, etag: string): { matched: boolean; response: Response; headers: Headers } | undefined {
464465 if (ctx.request.method !== "GET" && ctx.request.method !== "HEAD") return undefined;
465466 const h = ctx.request.headers;
466 const anonymous = !h.has("cookie") && !h.has("authorization") && !h.has("x-plat-user") && !h.has("x-plat-edge-token") && ctx.auth.user === undefined;
467 const anonymous = !h.has("cookie") && !h.has("authorization") && !h.has("x-plat-user") && !h.has("x-plat-edge-token") && !signedInPage(ctx);
467468 const headers = new Headers({ etag });
468469 if (anonymous) {
469470 headers.set("cache-control", `public, max-age=0, s-maxage=${EDGE_FRESH}, stale-while-revalidate=${EDGE_STALE}`);
src/web/pages/chapters.ts +2 −1
@@ -18,6 +18,7 @@ import { backTo, field, readForm } from "../form.ts";
1818 import { html, type Html } from "../html.ts";
1919 import { flashTo, page } from "../layout.ts";
2020 import { badge, btn, row } from "../ui.ts";
21 import { signedInPage } from "../../http/page_may.ts";
2122
2223 const usd = (n: number): string => `$${n.toFixed(2)}`;
2324 const day = (iso: string | null): string => (iso === null ? "" : iso.slice(0, 10));
@@ -170,8 +171,8 @@ export async function chapterAct(ctx: Ctx): Promise<Response> {
170171 if (form instanceof Response) return form;
171172 const list = `${repoBase(repo)}/chapters`;
172173 const name = ctx.params.chapter;
174 if (!signedInPage(ctx)) return flashTo(ctx, list, { tone: "danger", message: "Sign in first." });
173175 const user = ctx.auth.user;
174 if (user === undefined) return flashTo(ctx, list, { tone: "danger", message: "Sign in first." });
175176 const app = ctx.app;
176177 if (name === undefined) {
177178 const made = draft(app, user, repo, { name: field(form, "name"), means: field(form, "means") });
src/web/pages/client_cloud.ts +6 −6
@@ -50,10 +50,10 @@ export function clientCloudsPage(ctx: Ctx): Response {
5050 }
5151
5252 function clientCloudsBody(ctx: Ctx): Response {
53 if (!signedInPage(ctx)) return signInFirst(ctx);
5354 const user = ctx.auth.user;
54 if (!user) return signInFirst(ctx);
5555 const mine = myClientClouds(ctx.app, user);
56 if (mine.length === 0 && !adminPage(ctx, "client_cloud", user.isAdmin)) return notFoundPage(ctx);
56 if (mine.length === 0 && !adminPage(ctx)) return notFoundPage(ctx);
5757 return sealed(
5858 page({
5959 ctx,
@@ -80,7 +80,7 @@ function clientCloudsBody(ctx: Ctx): Response {
8080
8181 // POST /client-clouds
8282 export async function clientCloudAttach(ctx: Ctx): Promise<Response> {
83 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
83 if (!signedInPage(ctx)) return signInFirst(ctx);
8484 const form = await readForm(ctx, "admin");
8585 if (form instanceof Response) return form;
8686 const r = await attachClientCloud(ctx.app, ctx.auth.user, {
@@ -113,7 +113,7 @@ function seenCard(v: ClientCloudView): Html {
113113
114114 // GET /client-clouds/:id
115115 export async function clientCloudPage(ctx: Ctx): Promise<Response> {
116 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
116 if (!signedInPage(ctx)) return signInFirst(ctx);
117117 const r = await lookAtClientCloud(ctx.app, ctx.auth.user, ctx.params.id ?? "");
118118 if (!r.ok) return notFoundPage(ctx);
119119 const v = r.value;
@@ -143,7 +143,7 @@ export async function clientCloudPage(ctx: Ctx): Promise<Response> {
143143
144144 // POST /client-clouds/:id/grant
145145 export async function clientCloudGrant(ctx: Ctx): Promise<Response> {
146 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
146 if (!signedInPage(ctx)) return signInFirst(ctx);
147147 const form = await readForm(ctx, "admin");
148148 if (form instanceof Response) return form;
149149 const id = ctx.params.id ?? "";
@@ -154,7 +154,7 @@ export async function clientCloudGrant(ctx: Ctx): Promise<Response> {
154154
155155 // POST /client-clouds/:id/end
156156 export async function clientCloudEnd(ctx: Ctx): Promise<Response> {
157 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
157 if (!signedInPage(ctx)) return signInFirst(ctx);
158158 const form = await readForm(ctx, "admin");
159159 if (form instanceof Response) return form;
160160 const id = ctx.params.id ?? "";
src/web/pages/cloud.ts +2 −2
@@ -52,8 +52,8 @@ import { accountSections } from "./origins.ts";
5252 const BACK = "/settings/cloud";
5353
5454 function requireAdmin(ctx: Ctx): Response | undefined {
55 if (!signedInPage(ctx, "cloud")) return signInFirst(ctx);
56 if (!adminPage(ctx, "cloud", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
55 if (!signedInPage(ctx)) return signInFirst(ctx);
56 if (!adminPage(ctx)) return notFoundPage(ctx);
5757 return undefined;
5858 }
5959
src/web/pages/cockpit.ts +2 −1
@@ -17,6 +17,7 @@ import { html, type Html } from "../html.ts";
1717 import { page } from "../layout.ts";
1818 import { meter } from "../ui.ts";
1919 import { cockpitFor, type Cockpit, type CockpitAction, type CockpitCard, type CockpitWave } from "../studio/cockpit.ts";
20 import { signedInPage } from "../../http/page_may.ts";
2021
2122 /** The events that can move a region. */
2223 const LIVE = "run.*,issue.*,pull.*,release.*";
@@ -91,8 +92,8 @@ export function cockpitBody(c: Cockpit, kiosk: boolean): Html {
9192 // GET /cockpit and GET /board?kiosk=1 — signed in.
9293 export function cockpitPage(ctx: Ctx, kioskMode = ctx.url.searchParams.has("kiosk")): Response {
9394 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
95 if (!signedInPage(ctx)) return signInFirst(ctx);
9496 const user = ctx.auth.user;
95 if (!user) return signInFirst(ctx);
9697 const c = timePhase(ctx.request, "cockpit", () => cockpitFor(ctx.app, user, { kiosk: kioskMode }));
9798 return timePhase(ctx.request, "render", () =>
9899 page({
src/web/pages/config.ts +2 −2
@@ -68,7 +68,7 @@ async function commitsDirectly(ctx: Ctx, scope: RepoScope, ref: string): Promise
6868 function configContext(ctx: Ctx, ref: string, path: string): RepoScope | Response {
6969 const repo = loadRepo(ctx);
7070 if (!repo) return notFoundPage(ctx);
71 if (!signedInPage(ctx, "config")) return signInFirst(ctx);
71 if (!signedInPage(ctx)) return signInFirst(ctx);
7272 if (!isSafeRef(ref) || !isSafeTreePath(path) || !isFormConfig(path)) return notFoundPage(ctx);
7373 const scope = localScope(ctx, repo);
7474 // A mirror you cannot push to proposes through its origin: the source editor's card.
@@ -265,7 +265,7 @@ export async function configSubmit(ctx: Ctx): Promise<Response> {
265265 // Who may write is settled before the body is read: a private repository
266266 // answers a stranger 404, as every page about it does.
267267 if (!loadRepo(ctx)) return notFoundPage(ctx);
268 if (!signedInPage(ctx, "config")) return signInFirst(ctx);
268 if (!signedInPage(ctx)) return signInFirst(ctx);
269269 const form = await readForm(ctx, "rw");
270270 if (form instanceof Response) return form;
271271 const ref = formValue(form, "ref");
src/web/pages/confirms.ts +3 −2
@@ -19,6 +19,7 @@ import { html, type Html } from "../html.ts";
1919 import { flashTo, page } from "../layout.ts";
2020 import { btn, icon, messageText, row, time } from "../ui.ts";
2121 import { accountSections } from "./origins.ts";
22 import { signedInPage } from "../../http/page_may.ts";
2223
2324 const BACK = "/settings/confirms";
2425
@@ -61,15 +62,15 @@ function confirmsPage(ctx: Ctx, shown?: Html): Response {
6162
6263 // GET /settings/confirms
6364 export function confirmsList(ctx: Ctx): Response {
64 if (ctx.auth.user === undefined) return signInFirst(ctx);
65 if (!signedInPage(ctx)) return signInFirst(ctx);
6566 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
6667 return timePhase(ctx.request, "render", () => confirmsPage(ctx));
6768 }
6869
6970 // POST /settings/confirms/:id — the person's yes.
7071 export async function confirmYes(ctx: Ctx): Promise<Response> {
72 if (!signedInPage(ctx)) return signInFirst(ctx);
7173 const user = ctx.auth.user;
72 if (user === undefined) return signInFirst(ctx);
7374 // A browser's own session, as the API's door: never a token or a password.
7475 if (ctx.auth.via !== "session") return forbiddenPage(ctx, "Answer this from your own signed-in browser.");
7576 const form = await readForm(ctx);
src/web/pages/conflicts.ts +2 −1
@@ -36,6 +36,7 @@ import { flashTo, page } from "../layout.ts";
3636 import { renderMarkdown } from "../markdown.ts";
3737 import { btn } from "../ui.ts";
3838 import { changeHead, changeTabs, pullContext } from "../studio/change.ts";
39 import { signedInPage } from "../../http/page_may.ts";
3940
4041 /** More blocks or longer words than this are not a hand's work. */
4142 export const MAX_BLOCKS = 500;
@@ -280,7 +281,7 @@ export async function conflictsFinish(ctx: Ctx): Promise<Response> {
280281 const found = pullContext(ctx);
281282 if (found instanceof Response) return found;
282283 const { repo, pull } = found;
283 if (!ctx.auth.user || !canWrite(ctx.app.db, repo, ctx.auth.user))
284 if (!signedInPage(ctx) || !canWrite(ctx.app.db, repo, ctx.auth.user))
284285 return forbiddenPage(ctx, "Only someone who can write to this repository can do this.");
285286 const form = await readForm(ctx, "rw");
286287 if (form instanceof Response) return form;
src/web/pages/connections.ts +6 −6
@@ -34,7 +34,7 @@ import { field, readForm } from "../form.ts";
3434 import { html, type Html } from "../html.ts";
3535 import { flashTo } from "../layout.ts";
3636 import { badge, btn, confirmAction, field as formField, row, rowList, selectField } from "../ui.ts";
37 import { adminPage } from "../../http/page_may.ts";
37 import { adminPage, signedInPage } from "../../http/page_may.ts";
3838
3939 const BACK = "/settings/model";
4040
@@ -138,8 +138,8 @@ function addForm(user: User): Html {
138138
139139 // POST /settings/model/connections
140140 export async function connectionAdd(ctx: Ctx): Promise<Response> {
141 if (!signedInPage(ctx)) return notFoundPage(ctx);
141142 const user = ctx.auth.user;
142 if (user === undefined) return notFoundPage(ctx);
143143 const form = await readForm(ctx, "admin");
144144 if (form instanceof Response) return form;
145145 const preset = CONNECTION_PRESETS.find((p) => p.id === field(form, "preset"));
@@ -171,8 +171,8 @@ export async function connectionAdd(ctx: Ctx): Promise<Response> {
171171
172172 // POST /settings/model/connections/:id
173173 export async function connectionEdit(ctx: Ctx): Promise<Response> {
174 if (!signedInPage(ctx)) return notFoundPage(ctx);
174175 const user = ctx.auth.user;
175 if (user === undefined) return notFoundPage(ctx);
176176 const form = await readForm(ctx, "admin");
177177 if (form instanceof Response) return form;
178178 // A field the form did not send keeps what it is; the empty one it did send is the person's.
@@ -208,12 +208,12 @@ export async function connectionEdit(ctx: Ctx): Promise<Response> {
208208
209209 // POST /settings/model/connections/:id/test
210210 export async function connectionRetest(ctx: Ctx): Promise<Response> {
211 if (!signedInPage(ctx)) return notFoundPage(ctx);
211212 const user = ctx.auth.user;
212 if (user === undefined) return notFoundPage(ctx);
213213 const form = await readForm(ctx, "admin");
214214 if (form instanceof Response) return form;
215215 const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? "");
216 if (c === undefined || (c.scope === "forge" && !adminPage(ctx, "connections", user.isAdmin)))
216 if (c === undefined || (c.scope === "forge" && !adminPage(ctx)))
217217 return notFoundPage(ctx);
218218 const test = await retestConnection(ctx.app, user, c.id);
219219 if (test === "busy") return flashTo(ctx, BACK, { tone: "danger", message: CONNECTION_REFUSED["busy"]! });
@@ -231,8 +231,8 @@ export async function connectionRetest(ctx: Ctx): Promise<Response> {
231231
232232 // POST /settings/model/connections/:id/remove (from the confirm page, with its name typed)
233233 export async function connectionRemove(ctx: Ctx): Promise<Response> {
234 if (!signedInPage(ctx)) return notFoundPage(ctx);
234235 const user = ctx.auth.user;
235 if (user === undefined) return notFoundPage(ctx);
236236 const form = await readForm(ctx, "admin");
237237 if (form instanceof Response) return form;
238238 const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? "");
src/web/pages/crew-settings.ts +1 −1
@@ -30,7 +30,7 @@ export async function crewSubscriptionsSave(ctx: Ctx): Promise<Response> {
3030 const gate = await adminForm(ctx);
3131 if (gate instanceof Response) return gate;
3232 const { repo, form } = gate;
33 if (!adminPage(ctx, "crew-settings", ctx.auth.user?.isAdmin === true)) return repoNotFound(ctx);
33 if (!adminPage(ctx)) return repoNotFound(ctx);
3434 const crew = listCrew(ctx.app, ctx.auth.user, repo);
3535 saveGrants(ctx, form, repo.id, crew.ok ? crew.value : []);
3636 return flashTo(ctx, `${repoBase(repo)}/settings#crew`, {
src/web/pages/crew.ts +2 −2
@@ -97,8 +97,8 @@ import { forgeCeiling } from "../../flow/ceiling.ts";
9797
9898 /** The admin, or the response that turns everyone else away. */
9999 function requireAdmin(ctx: Ctx): Response | undefined {
100 if (!signedInPage(ctx, "crew")) return signInFirst(ctx);
101 if (!adminPage(ctx, "crew", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
100 if (!signedInPage(ctx)) return signInFirst(ctx);
101 if (!adminPage(ctx)) return notFoundPage(ctx);
102102 return undefined;
103103 }
104104
src/web/pages/data.ts +5 −5
@@ -21,7 +21,7 @@ import { page } from "../layout.ts";
2121 import { btn } from "../ui.ts";
2222 import { localScope } from "../scope.ts";
2323 import { dataBody, type DataView } from "./data_view.ts";
24 import { adminPage } from "../../http/page_may.ts";
24 import { adminPage, signedInPage } from "../../http/page_may.ts";
2525
2626 const PURPOSE = "Every SQLite file you may read; secrets are masked.";
2727
@@ -48,8 +48,8 @@ function refuse(ctx: Ctx): Response {
4848 // GET /data[?source=<id>[&table=<name>…][&sql=…]]
4949 export async function dataPage(ctx: Ctx): Promise<Response> {
5050 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
51 if (!signedInPage(ctx)) return signInFirst(ctx);
5152 const viewer = ctx.auth.user;
52 if (!viewer) return signInFirst(ctx);
5353 const { db, config } = ctx.app;
5454 if (!maySeeData(db, viewer)) return refuse(ctx);
5555 const sources = listSources(db, config.dataDir, viewer);
@@ -60,9 +60,9 @@ export async function dataPage(ctx: Ctx): Promise<Response> {
6060 // GET /admin/data — the forge's own database (the admin gate has already refused non-admins).
6161 export async function adminDataPage(ctx: Ctx): Promise<Response> {
6262 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
63 if (!signedInPage(ctx)) return signInFirst(ctx);
6364 const viewer = ctx.auth.user;
64 if (!viewer) return signInFirst(ctx);
65 if (!adminPage(ctx, "data", viewer.isAdmin)) return refuse(ctx);
65 if (!adminPage(ctx)) return refuse(ctx);
6666 const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.kind === "forge");
6767 return draw(ctx, { path: "/admin/data", sources, sqlWait: () => sqlWindow(ctx.app, viewer.id) }, "Forge data", pageHead("Forge data", { sub: "Secrets are masked; queries are read-only." }));
6868 }
@@ -72,7 +72,7 @@ export async function appDataPage(ctx: Ctx): Promise<Response> {
7272 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
7373 const repo = loadRepo(ctx);
7474 const record = repo && getAppByRepo(ctx.app.db, repo.id);
75 if (!repo || !record || !ctx.auth.user || !canWrite(ctx.app.db, repo, ctx.auth.user)) return refuse(ctx);
75 if (!repo || !record || !signedInPage(ctx) || !canWrite(ctx.app.db, repo, ctx.auth.user)) return refuse(ctx);
7676 const viewer = ctx.auth.user;
7777 const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.id.startsWith(`app:${record.id}:`));
7878 const scope = localScope(ctx, repo);
src/web/pages/dataset.ts +2 −2
@@ -24,8 +24,8 @@ const usd = (n: number): string => `$${n.toFixed(2)}`;
2424 export function datasetPage(ctx: Ctx): Response {
2525 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2626 const rendering = performance.now();
27 if (!signedInPage(ctx, "dataset")) return signInFirst(ctx);
28 if (!adminPage(ctx, "dataset", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
27 if (!signedInPage(ctx)) return signInFirst(ctx);
28 if (!adminPage(ctx)) return notFoundPage(ctx);
2929 const stats = datasetStats(ctx.app.db);
3030 const last = lastExport(ctx.app);
3131 const a = answers(ctx.app.db);
src/web/pages/displays.ts +2 −1
@@ -13,6 +13,7 @@ import { pageHead, repoBase, signInFirst } from "../chrome.ts";
1313 import { html } from "../html.ts";
1414 import { page } from "../layout.ts";
1515 import { emptyList } from "../empty_words.ts";
16 import { signedInPage } from "../../http/page_may.ts";
1617
1718 const LAYOUT_WORD = { shelf: "Shelf", grid: "Grid", graph: "Graph" } as const;
1819
@@ -21,7 +22,7 @@ export { LIST_WAIT_MS, listWait };
2122 // GET /displays — every display the viewer may read; a stranger signs in first.
2223 export async function displaysPage(ctx: Ctx): Promise<Response> {
2324 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
24 if (ctx.auth.user === undefined) return signInFirst(ctx);
25 if (!signedInPage(ctx)) return signInFirst(ctx);
2526 const { rows, complete } = await timePhaseAsync(ctx.request, "displays", () => listedDisplaysWithin(ctx.app, ctx.auth.user, listWait.ms));
2627 return timePhase(ctx.request, "render", () =>
2728 page({
src/web/pages/economics.ts +3 −3
@@ -13,7 +13,7 @@
1313 * Anyone else gets the not-found page.
1414 */
1515
16 import { adminPage, signedInPage } from "../../http/page_may.ts";
16 import { signedInPage, personAdminPage } from "../../http/page_may.ts";
1717 import { sshOn } from "../../settings/ssh.ts";
1818 import { emptyNote } from "../empty_words.ts";
1919 import { ECONOMICS_WORDS, changeEconomics, readEconomics } from "../../actions/economics.ts";
@@ -33,7 +33,7 @@ const PATH = "/settings/economics";
3333 // GET /settings/economics
3434 export function economicsPage(ctx: Ctx): Response {
3535 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
36 if (!signedInPage(ctx, "economics")) return signInFirst(ctx);
36 if (!signedInPage(ctx)) return signInFirst(ctx);
3737 const read = timePhase(ctx.request, "economics", () => readEconomics(ctx.app, ctx.auth.user));
3838 if (!read.ok) return notFoundPage(ctx);
3939 const rendering = performance.now();
@@ -176,7 +176,7 @@ export function economicsPage(ctx: Ctx): Response {
176176 // POST /settings/economics
177177 export async function economicsSet(ctx: Ctx): Promise<Response> {
178178 // Checked before the body is read: a non-admin learns nothing of the door.
179 if (!adminPage(ctx, "economics", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
179 if (!personAdminPage(ctx)) return notFoundPage(ctx);
180180 const form = await readForm(ctx, "admin");
181181 if (form instanceof Response) return form;
182182 // A field the posted form does not carry is left undefined: kept as it stands.
src/web/pages/edit.ts +4 −4
@@ -652,7 +652,7 @@ const isMarkdownPath = (path: string): boolean =>
652652 function editContext(ctx: Ctx): { scope: RepoScope; ref: string } | Response {
653653 const repo = loadRepo(ctx);
654654 if (!repo) return notFoundPage(ctx);
655 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
655 if (!signedInPage(ctx)) return signInFirst(ctx);
656656 const scope = localScope(ctx, repo);
657657 // A reader may not change it; a fork is how they propose. Someone who cannot read never got here.
658658 if (!scope.caps.write) return cannotChangePage(ctx, scope, repo);
@@ -964,7 +964,7 @@ export async function runContribute(
964964 export async function contributeSubmit(ctx: Ctx): Promise<Response> {
965965 const repo = loadRepo(ctx);
966966 if (!repo) return notFoundPage(ctx);
967 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
967 if (!signedInPage(ctx)) return signInFirst(ctx);
968968 const form = await readForm(ctx, "rw");
969969 if (form instanceof Response) return form;
970970 const scope = localScope(ctx, repo);
@@ -1106,7 +1106,7 @@ async function dxfSubmit(ctx: Ctx, scope: RepoScope, repo: Repo, form: Form): Pr
11061106 export async function editSubmit(ctx: Ctx): Promise<Response> {
11071107 const repo = loadRepo(ctx);
11081108 if (!repo) return notFoundPage(ctx);
1109 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
1109 if (!signedInPage(ctx)) return signInFirst(ctx);
11101110 const form = await readForm(ctx, "rw");
11111111 if (form instanceof Response) return form;
11121112 const scope = localScope(ctx, repo);
@@ -1297,7 +1297,7 @@ export async function deleteFilePage(ctx: Ctx): Promise<Response> {
12971297 export async function deleteFileSubmit(ctx: Ctx): Promise<Response> {
12981298 const repo = loadRepo(ctx);
12991299 if (!repo) return notFoundPage(ctx);
1300 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
1300 if (!signedInPage(ctx)) return signInFirst(ctx);
13011301 const form = await readForm(ctx, "rw");
13021302 if (form instanceof Response) return form;
13031303 const scope = localScope(ctx, repo);
src/web/pages/everyday.ts +12 −12
@@ -40,7 +40,7 @@ import { signOutHere } from "../../actions/signins.ts";
4040 import { sessionCookie } from "./site.ts";
4141 import { safeNext, withReturn } from "../return_to.ts";
4242 import { EMAIL_TAKEN_MESSAGE, EMAIL_WANTED, USERNAME_TAKEN } from "../../actions/signup_words.ts";
43 import { adminPage } from "../../http/page_may.ts";
43 import { adminPage, signedInPage } from "../../http/page_may.ts";
4444
4545 const USERNAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/;
4646
@@ -53,10 +53,10 @@ function suggestedName(ctx: Ctx, admin: User): string {
5353 // GET /settings/everyday — the step on its own page: why, a username, one passkey button, and "Keep
5454 // using admin".
5555 export function everydayPage(ctx: Ctx): Response {
56 if (!signedInPage(ctx)) return signInFirst(ctx);
5657 const user = ctx.auth.user;
57 if (!user) return signInFirst(ctx);
5858 // Nothing to ask: not an admin, has one already, or is one.
59 if (!adminPage(ctx, "everyday", user.isAdmin) || user.kind !== "user" || everydayOf(ctx.app.db, user) !== undefined || adminOf(ctx.app.db, user) !== undefined) return redirect("/settings");
59 if (!adminPage(ctx) || user.kind !== "user" || everydayOf(ctx.app.db, user) !== undefined || adminOf(ctx.app.db, user) !== undefined) return redirect("/settings");
6060 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
6161 return timePhase(ctx.request, "render", () => page({
6262 ctx,
@@ -164,10 +164,10 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> {
164164 const refuse = (status: number, message: string) =>
165165 json({ error: "refused", message }, status);
166166 if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE);
167 if (!signedInPage(ctx)) return refuse(401, "Sign in first.");
167168 const admin = ctx.auth.user;
168 if (!admin) return refuse(401, "Sign in first.");
169169 if (ctx.auth.via !== "session") return refuse(403, "Passkeys are made from a signed-in browser.");
170 if (!adminPage(ctx, "everyday", admin.isAdmin)) return refuse(403, NOT_ADMIN_HERE);
170 if (!adminPage(ctx)) return refuse(403, NOT_ADMIN_HERE);
171171 if (everydayOf(ctx.app.db, admin) !== undefined)
172172 return refuse(409, "You already have an everyday account.");
173173 const data = await boundedBody(ctx.request, STRANGER_MAX);
@@ -181,11 +181,11 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> {
181181
182182 // POST /settings/everyday — make the everyday account, link it, sign in as it.
183183 export async function everydayCreate(ctx: Ctx): Promise<Response> {
184 if (!signedInPage(ctx)) return signInFirst(ctx);
184185 const admin = ctx.auth.user;
185 if (!admin) return signInFirst(ctx);
186186 const form = await readForm(ctx, "admin");
187187 if (form instanceof Response) return form;
188 if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
188 if (!adminPage(ctx)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
189189 const existing = everydayOf(ctx.app.db, admin);
190190 if (existing !== undefined)
191191 return flashTo(ctx, "/settings", {
@@ -249,11 +249,11 @@ export async function everydayCreate(ctx: Ctx): Promise<Response> {
249249
250250 // POST /settings/everyday/keep — the admin keeps working as admin, on purpose.
251251 export async function everydayKeep(ctx: Ctx): Promise<Response> {
252 if (!signedInPage(ctx)) return signInFirst(ctx);
252253 const admin = ctx.auth.user;
253 if (!admin) return signInFirst(ctx);
254254 const form = await readForm(ctx, "admin");
255255 if (form instanceof Response) return form;
256 if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
256 if (!adminPage(ctx)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
257257 keepAdmin(ctx.app.db, admin);
258258 return flashTo(ctx, "/", {
259259 message:
@@ -264,8 +264,8 @@ export async function everydayKeep(ctx: Ctx): Promise<Response> {
264264 // POST /settings/everyday/switch — leave the admin account for the everyday
265265 // one: this session ends, and sign-in says as whom to come back.
266266 export async function everydaySwitch(ctx: Ctx): Promise<Response> {
267 if (!signedInPage(ctx)) return signInFirst(ctx);
267268 const admin = ctx.auth.user;
268 if (!admin) return signInFirst(ctx);
269269 const form = await readForm(ctx, "admin");
270270 if (form instanceof Response) return form;
271271 const daily = admin.isAdmin ? everydayOf(ctx.app.db, admin) : undefined;
@@ -287,8 +287,8 @@ export async function everydaySwitch(ctx: Ctx): Promise<Response> {
287287 * is the other choice, staying as the everyday account.
288288 */
289289 export function everydayRefusedPage(ctx: Ctx, admin: User): Response {
290 if (!signedInPage(ctx)) return signInFirst(ctx);
290291 const daily = ctx.auth.user;
291 if (daily === undefined) return signInFirst(ctx);
292292 const [who, way] = everydayRefusal(daily, admin);
293293 const back = ctx.request.method === "GET" ? safeNext(ctx.url.pathname + ctx.url.search) : undefined;
294294 return page(
@@ -314,8 +314,8 @@ export function everydayRefusedPage(ctx: Ctx, admin: User): Response {
314314 // POST /settings/everyday/to-admin — leave the everyday account for its
315315 // admin: this session ends, and sign-in says as whom to come back.
316316 export async function everydayToAdmin(ctx: Ctx): Promise<Response> {
317 if (!signedInPage(ctx)) return signInFirst(ctx);
317318 const daily = ctx.auth.user;
318 if (!daily) return signInFirst(ctx);
319319 const form = await readForm(ctx);
320320 if (form instanceof Response) return form;
321321 const admin = adminOf(ctx.app.db, daily);
src/web/pages/features.ts +3 −3
@@ -6,7 +6,7 @@
66 * Anyone else is told the forge's 404, as every admin page does.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
9 import { signedInPage, personAdminPage } from "../../http/page_may.ts";
1010 import { sshOn } from "../../settings/ssh.ts";
1111 import { upstreamBlob } from "../../core/upstream.ts";
1212 import {
@@ -40,8 +40,8 @@ import { badge, btn, empty, row, time } from "../ui.ts";
4040 import { accountSections } from "./origins.ts";
4141
4242 function requireAdmin(ctx: Ctx): Response | undefined {
43 if (!signedInPage(ctx, "features")) return signInFirst(ctx);
44 if (!adminPage(ctx, "features", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
43 if (!signedInPage(ctx)) return signInFirst(ctx);
44 if (!personAdminPage(ctx)) return notFoundPage(ctx);
4545 return undefined;
4646 }
4747
src/web/pages/first.ts +1 −1
@@ -9,7 +9,7 @@ import { flashOrJson } from "../layout.ts";
99 export async function firstSubmit(ctx: Ctx): Promise<Response> {
1010 const repo = loadRepo(ctx);
1111 if (!repo) return notFoundPage(ctx);
12 if (!signedInPage(ctx, "first")) return signInFirst(ctx);
12 if (!signedInPage(ctx)) return signInFirst(ctx);
1313 const form = await readForm(ctx, "rw");
1414 if (form instanceof Response) return form;
1515 const dest = backTo(form, `${repoBase(repo)}/map`);
src/web/pages/flags.ts +2 −1
@@ -19,12 +19,13 @@ import { html } from "../html.ts";
1919 import { flashTo, page } from "../layout.ts";
2020 import { btn, empty, icon, row } from "../ui.ts";
2121 import { accountSections } from "./origins.ts";
22 import { signedInPage } from "../../http/page_may.ts";
2223
2324 export { useFlagRegistry };
2425
2526 function denied(ctx: Ctx): Response | undefined {
27 if (!signedInPage(ctx)) return signInFirst(ctx);
2628 const user = ctx.auth.user;
27 if (!user) return signInFirst(ctx);
2829 if (mayManageFlags(user)) return undefined;
2930 return page(
3031 {
src/web/pages/fleet-graph.ts +4 −3
@@ -25,6 +25,7 @@ import {
2525 import { html } from "../html.ts";
2626 import { fragment, page } from "../layout.ts";
2727 import { btn, field } from "../ui.ts";
28 import { signedInPage } from "../../http/page_may.ts";
2829
2930 /** The selection from the URL, or the refusal's words. */
3031 function selection(ctx: Ctx) {
@@ -34,8 +35,8 @@ function selection(ctx: Ctx) {
3435 /** GET /fleet/graph */
3536 export function fleetGraphPage(ctx: Ctx): Response {
3637 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
38 if (!signedInPage(ctx)) return signInFirst(ctx);
3739 const user = ctx.auth.user;
38 if (!user) return signInFirst(ctx);
3940 const asked = selection(ctx);
4041 const graph = asked.ok
4142 ? timePhase(ctx.request, "graph", () =>
@@ -101,8 +102,8 @@ export function fleetGraphPage(ctx: Ctx): Response {
101102
102103 /** GET /fleet/graph/live — the section alone, for the redraw. */
103104 export function fleetGraphLive(ctx: Ctx): Response {
105 if (!signedInPage(ctx)) return fragment(html``, { status: 404 });
104106 const user = ctx.auth.user;
105 if (!user) return fragment(html``, { status: 404 });
106107 const asked = selection(ctx);
107108 if (!asked.ok) return fragment(html``, { status: 422 });
108109 return fragment(fleetGraphSection(readFleetGraph(ctx.app, user, asked.value)), {
@@ -138,8 +139,8 @@ export function fleetGraphCsvText(graph: FleetGraph): string {
138139
139140 /** GET /fleet/graph.csv */
140141 export function fleetGraphCsv(ctx: Ctx): Response {
142 if (!signedInPage(ctx)) return signInFirst(ctx);
141143 const user = ctx.auth.user;
142 if (!user) return signInFirst(ctx);
143144 const asked = selection(ctx);
144145 if (!asked.ok)
145146 return new Response(`${asked.error}\n`, {
src/web/pages/fleet-ops.ts +3 −3
@@ -26,7 +26,7 @@ import { canAct, renderFleet } from "./fleet.ts";
2626
2727 /** POST /fleet */
2828 export async function fleetAct(ctx: Ctx): Promise<Response> {
29 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
29 if (!signedInPage(ctx)) return signInFirst(ctx);
3030 if (!canAct(ctx)) return notFoundPage(ctx);
3131 const form = await readForm(ctx, "rw");
3232 if (form instanceof Response) return form;
@@ -91,7 +91,7 @@ function refusal(
9191
9292 /** GET /fleet/ops/:id */
9393 export function fleetReceipt(ctx: Ctx): Response {
94 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
94 if (!signedInPage(ctx)) return signInFirst(ctx);
9595 const found = getFleetOp(ctx.app, ctx.auth.user, ctx.params.id ?? "");
9696 if (!found.ok) return notFoundPage(ctx);
9797 const op = found.value;
@@ -108,7 +108,7 @@ export function fleetReceipt(ctx: Ctx): Response {
108108
109109 /** POST /fleet/ops/:id/undo */
110110 export async function fleetUndo(ctx: Ctx): Promise<Response> {
111 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
111 if (!signedInPage(ctx)) return signInFirst(ctx);
112112 if (!canAct(ctx)) return notFoundPage(ctx);
113113 const form = await readForm(ctx, "rw");
114114 if (form instanceof Response) return form;
src/web/pages/flow.ts +6 −6
@@ -14,7 +14,7 @@
1414 * `tui/screens/valves.ts`, on the same `readPipes` and the same actions.
1515 */
1616
17 import { adminPage, signedInPage } from "../../http/page_may.ts";
17 import { signedInPage, personAdminPage } from "../../http/page_may.ts";
1818 import { retryBackup } from "../../actions/backup_retry.ts";
1919 import { alarmBackup, type BackupAlarm } from "../../flow/alarm_backup.ts";
2020 import { acceptSuggestion, turnValveFor, type ValveError } from "../../actions/valves.ts";
@@ -159,9 +159,9 @@ export async function flowPage(ctx: Ctx): Promise<Response> {
159159 const waiting = ctx.url.search === "?wait=1";
160160 if (ctx.url.search !== "" && !waiting) return new Response(null, { status: 301, headers: { location: `/boards${ctx.url.search}` } });
161161 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
162 if (!signedInPage(ctx)) return signInFirst(ctx);
162163 const user = ctx.auth.user;
163 if (user === undefined) return signInFirst(ctx);
164 if (!adminPage(ctx, "flow", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
164 if (!personAdminPage(ctx)) return notFoundPage(ctx);
165165 // What a "Reading…" page asks: it answers when the worker has the picture, and draws nothing.
166166 if (waiting) {
167167 return waitAnswer(await flowPicture(ctx.app, user.id, LONG_WAIT_MS));
@@ -242,7 +242,7 @@ function done(ctx: Ctx, result: ReturnType<typeof turnValveFor>): Response {
242242
243243 // POST /flow/valve
244244 export async function valveSet(ctx: Ctx): Promise<Response> {
245 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
245 if (!signedInPage(ctx)) return signInFirst(ctx);
246246 const form = await readForm(ctx, "admin");
247247 if (form instanceof Response) return form;
248248 return done(ctx, turnValveFor(ctx.app, ctx.auth.user, field(form, "repo"), field(form, "level")));
@@ -250,7 +250,7 @@ export async function valveSet(ctx: Ctx): Promise<Response> {
250250
251251 // POST /flow/suggestion
252252 export async function suggestionTake(ctx: Ctx): Promise<Response> {
253 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
253 if (!signedInPage(ctx)) return signInFirst(ctx);
254254 const form = await readForm(ctx, "admin");
255255 if (form instanceof Response) return form;
256256 return done(ctx, acceptSuggestion(ctx.app, ctx.auth.user, field(form, "repo")));
@@ -258,7 +258,7 @@ export async function suggestionTake(ctx: Ctx): Promise<Response> {
258258
259259 // POST /flow/backup/retry: one snapshot now, through the service's own queue, so two never run at once.
260260 export async function backupRetry(ctx: Ctx): Promise<Response> {
261 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
261 if (!signedInPage(ctx)) return signInFirst(ctx);
262262 const form = await readForm(ctx, "admin");
263263 if (form instanceof Response) return form;
264264 const retried = await retryBackup(ctx.app, ctx.auth.user);
src/web/pages/flows-all.ts +2 −3
@@ -15,7 +15,7 @@ import { html } from "../html.ts";
1515 import { page } from "../layout.ts";
1616 import { accountSections } from "./origins.ts";
1717 import { badge, btn, listCard, row, time, type Tone } from "../ui.ts";
18 import { adminPage } from "../../http/page_may.ts";
18 import { personAdminPage } from "../../http/page_may.ts";
1919
2020 /** Lines drawn at once; the count above says how many matched. */
2121 const SHOWN = 500;
@@ -25,8 +25,7 @@ const TONE: Record<Health, Tone> = { ok: "default", behind: "attn", diverged: "d
2525 // GET /admin/flows?kind=&stale=1
2626 export function allFlowsPage(ctx: Ctx): Response {
2727 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
28 const user = ctx.auth.user;
29 if (!adminPage(ctx, "flows", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx);
28 if (!personAdminPage(ctx)) return notFoundPage(ctx);
3029 const q = new URL(ctx.request.url).searchParams;
3130 const kind = parseKind(q.get("kind"));
3231 const stale = q.get("stale") === "1";
src/web/pages/following.ts +1 −1
@@ -603,7 +603,7 @@ export function followingCard(
603603 export async function followingSubmit(ctx: Ctx): Promise<Response> {
604604 const repo = loadRepo(ctx);
605605 if (!repo) return notFoundPage(ctx);
606 if (!signedInPage(ctx, "following")) return signInFirst(ctx);
606 if (!signedInPage(ctx)) return signInFirst(ctx);
607607 const form = await readForm(ctx, "rw");
608608 if (form instanceof Response) return form;
609609 const base = repoBase(repo);
src/web/pages/forge-it.ts +2 −1
@@ -11,13 +11,14 @@ import { forgeIt } from "../../spawn/forge_it.ts";
1111 import { loadRepo, notFoundPage, signInFirst } from "../chrome.ts";
1212 import { readForm } from "../form.ts";
1313 import { flashTo, redirect } from "../layout.ts";
14 import { signedInPage } from "../../http/page_may.ts";
1415
1516 // POST /:owner/:name/forge
1617 export async function forgeItSubmit(ctx: Ctx): Promise<Response> {
1718 const repo = loadRepo(ctx);
1819 if (!repo) return notFoundPage(ctx);
20 if (!signedInPage(ctx)) return signInFirst(ctx);
1921 const user = ctx.auth.user;
20 if (!user) return signInFirst(ctx);
2122 const form = await readForm(ctx, "admin");
2223 if (form instanceof Response) return form;
2324 const back = `/${repo.ownerName}/${repo.name}`;
src/web/pages/forge-template-setting.ts +2 −2
@@ -14,11 +14,11 @@ import { html, type Html } from "../html.ts";
1414 import { flashTo } from "../layout.ts";
1515 import { repoBase } from "../chrome.ts";
1616 import { btn, card, field as inputField } from "../ui.ts";
17 import { adminPage } from "../../http/page_may.ts";
1718
1819 /** The control, or nothing for anyone but a site admin. */
1920 export function forgeTemplateSetting(ctx: Ctx, repo: Repo): Html | null {
20 const user = ctx.auth.user;
21 if (user === undefined || !user.isAdmin || user.kind !== "user") return null;
21 if (!adminPage(ctx) || ctx.auth.user.kind !== "user") return null;
2222 const note = offeredNotes(ctx.app.db).get(`${repo.ownerName}/${repo.name}`);
2323 return card(
2424 html`<form method="post" action="${repoBase(repo)}/settings/app/forge-template">
src/web/pages/forge_machine.ts +2 −3
@@ -29,8 +29,7 @@ const choose = (name: string, machines: readonly string[], recover: boolean) =>
2929 </form>`;
3030
3131 export async function forgeMachineForm(ctx: Ctx): Promise<Response> {
32 const user = ctx.auth.user;
33 if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx);
32 if (!adminPage(ctx)) return notFoundPage(ctx);
3433 const name = ctx.params["name"] ?? "";
3534 const to = ctx.url.searchParams.get("to") ?? "";
3635 const recover = ctx.url.searchParams.get("recover") === "1";
@@ -57,8 +56,8 @@ export async function forgeMachineForm(ctx: Ctx): Promise<Response> {
5756 }
5857
5958 export async function forgeMachineSubmit(ctx: Ctx): Promise<Response> {
59 if (!adminPage(ctx)) return notFoundPage(ctx);
6060 const user = ctx.auth.user;
61 if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx);
6261 const form = await readForm(ctx, "admin");
6362 if (form instanceof Response) return form;
6463 const name = ctx.params["name"] ?? "";
src/web/pages/forge_move_in.ts +3 −3
@@ -16,7 +16,7 @@ import { html, type Html } from "../html.ts";
1616 import { page } from "../layout.ts";
1717 import { btn, field } from "../ui.ts";
1818 import { statusRow } from "./security.ts";
19 import { adminPage } from "../../http/page_may.ts";
19 import { personAdminPage } from "../../http/page_may.ts";
2020
2121 const wrap = (title: string, body: Html) =>
2222 html`<div class="narrow-wide" data-forges>${pageHead(title)}<section class="settings-block">${body}<p class="mt">${btn("Back to your forges", { href: "/forges", size: "sm" })}</p></section></div>`;
@@ -28,7 +28,7 @@ const done = (response: Response): Response => {
2828
2929 export function forgeMoveInForm(ctx: Ctx): Response {
3030 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
31 if (!adminPage(ctx, "forge_move_in", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
31 if (!personAdminPage(ctx)) return notFoundPage(ctx);
3232 const rendering = performance.now();
3333 const cost = moveInCost();
3434 const body = html`<dl class="status-rows" data-preview>${cost.rows.map(([label, value]) => statusRow(label, html`${value}`))}</dl>
@@ -46,7 +46,7 @@ export function forgeMoveInForm(ctx: Ctx): Response {
4646
4747 export async function forgeMoveInSubmit(ctx: Ctx): Promise<Response> {
4848 const user = ctx.auth.user;
49 if (!adminPage(ctx, "forge_move_in", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx);
49 if (!personAdminPage(ctx)) return notFoundPage(ctx);
5050 const form = await readForm(ctx, "admin", BODY_CAPS.moveIn.bytes);
5151 if (form instanceof Response) return form;
5252 const name = String(form.get("name") ?? "").trim().toLowerCase();
src/web/pages/forge_upgrade.ts +2 −2
@@ -24,7 +24,7 @@ const wrap = (name: string, body: Html) =>
2424
2525 export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> {
2626 const user = ctx.auth.user;
27 if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx);
27 if (!adminPage(ctx)) return notFoundPage(ctx);
2828 const name = ctx.params["name"] ?? "";
2929 const plan = ctx.url.searchParams.get("plan") ?? "";
3030 const to = ctx.url.searchParams.get("to") ?? "";
@@ -53,7 +53,7 @@ export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> {
5353
5454 export async function forgeUpgradeSubmit(ctx: Ctx): Promise<Response> {
5555 const user = ctx.auth.user;
56 if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx);
56 if (!adminPage(ctx)) return notFoundPage(ctx);
5757 const form = await readForm(ctx, "admin");
5858 if (form instanceof Response) return form;
5959 const name = ctx.params["name"] ?? "";
src/web/pages/forges.ts +17 −22
@@ -49,7 +49,7 @@ import { claimedWords, isForgeSort, keepWords, SORT_WORDS, sortForges, type Forg
4949 import { CHILD_NAME } from "../../spawn/placement.ts";
5050 import { forgesMemory, memoryOverLine } from "../../spawn/memory_fit.ts";
5151 import { NO_KEY_HELD } from "../../crew/no_key.ts";
52 import { adminPage } from "../../http/page_may.ts";
52 import { adminPage, signedInPage } from "../../http/page_may.ts";
5353
5454
5555 /** "3 apps running", or which one is not and why. */
@@ -262,7 +262,7 @@ function refusedLink(ctx: Ctx): Html | null {
262262 // GET /forges/export.csv — the client list as a download, behind the page's own gate (a missing
263263 // page to anyone else).
264264 export async function forgesCsv(ctx: Ctx): Promise<Response> {
265 if (!adminPage(ctx, "forges", ctx.auth.user?.isAdmin === true)) return notFoundPage(ctx);
265 if (!adminPage(ctx)) return notFoundPage(ctx);
266266 const rows = sortForges(await servedRows(ctx.app), "attention");
267267 return new Response(clientsCsv(rows), {
268268 headers: {
@@ -276,8 +276,8 @@ export async function forgesCsv(ctx: Ctx): Promise<Response> {
276276
277277 // GET /forges — an admin's only.
278278 export async function forgesPage(ctx: Ctx): Promise<Response> {
279 if (!adminPage(ctx)) return notFoundPage(ctx);
279280 const user = ctx.auth.user;
280 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
281281 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
282282 const asked = ctx.url.searchParams.get("sort");
283283 const sort: ForgeSort = isForgeSort(asked) ? asked : "attention";
@@ -362,8 +362,8 @@ export async function forgesPage(ctx: Ctx): Promise<Response> {
362362 // has no /forges list (#12105). Nothing is minted until it is pressed; whether this
363363 // account may is the door's answer, not this page's.
364364 export async function forgeLinkForm(ctx: Ctx): Promise<Response> {
365 if (!signedInPage(ctx)) return notFoundPage(ctx);
365366 const user = ctx.auth.user;
366 if (user === undefined) return notFoundPage(ctx);
367367 const name = ctx.params["name"] ?? "";
368368 const seen = await previewDoor(ctx, user, name);
369369 const says = String(seen.body["says"] ?? seen.body["message"]);
@@ -390,8 +390,7 @@ export async function forgeLinkForm(ctx: Ctx): Promise<Response> {
390390 // GET /forges/:name/revoke-link — what ending the link does in one line and the one button that
391391 // does it; nothing changes until it is pressed (#14518).
392392 export async function forgeRevokeConfirm(ctx: Ctx): Promise<Response> {
393 const user = ctx.auth.user;
394 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
393 if (!adminPage(ctx)) return notFoundPage(ctx);
395394 const name = ctx.params["name"] ?? "";
396395 if (!CHILD_NAME.test(name)) return notFoundPage(ctx);
397396 const response = page({
@@ -443,8 +442,7 @@ async function namedForges(ctx: Ctx, wanted: readonly string[]): Promise<string[
443442 // GET /forges/archive?name=a&name=b — what archiving does, for one or several, and the one button
444443 // that does it.
445444 export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> {
446 const user = ctx.auth.user;
447 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
445 if (!adminPage(ctx)) return notFoundPage(ctx);
448446 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
449447 const names = await namedForges(ctx, ctx.url.searchParams.getAll("name"));
450448 const rows = (await servedRows(ctx.app)).filter((r) => names.includes(r.name));
@@ -477,8 +475,8 @@ export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> {
477475
478476 // POST /forges/archive — archive each named forge, one after another; the receipt says each result.
479477 export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> {
478 if (!adminPage(ctx)) return notFoundPage(ctx);
480479 const user = ctx.auth.user;
481 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
482480 const form = await readForm(ctx, "admin");
483481 if (form instanceof Response) return form;
484482 const names = await namedForges(ctx, form.getAll("name").filter((v): v is string => typeof v === "string"));
@@ -489,8 +487,8 @@ export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> {
489487
490488 // POST /forges/:name/restore — bring an archived forge back under its name.
491489 export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> {
490 if (!adminPage(ctx)) return notFoundPage(ctx);
492491 const user = ctx.auth.user;
493 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
494492 const form = await readForm(ctx, "admin");
495493 if (form instanceof Response) return form;
496494 const done = await restoreForge(ctx.app, ctx.params["name"] ?? "", { actorId: user.id });
@@ -501,8 +499,8 @@ export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> {
501499 // old one stops working. Shown once, in this answer only. The account that sent the
502500 // forge may ask, as an admin may (#12105): `reissueClaim` says which.
503501 export async function forgeLinkSubmit(ctx: Ctx): Promise<Response> {
502 if (!signedInPage(ctx)) return notFoundPage(ctx);
504503 const user = ctx.auth.user;
505 if (user === undefined) return notFoundPage(ctx);
506504 const form = await readForm(ctx, "rw");
507505 if (form instanceof Response) return form;
508506 const name = ctx.params["name"] ?? "";
@@ -554,8 +552,8 @@ function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null {
554552 // minute; then the row, with a receipt.
555553 function linkChange(act: "revoke" | "undo") {
556554 return async (ctx: Ctx): Promise<Response> => {
555 if (!adminPage(ctx)) return notFoundPage(ctx);
557556 const user = ctx.auth.user;
558 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
559557 const form = await readForm(ctx, "admin");
560558 if (form instanceof Response) return form;
561559 const name = ctx.params["name"] ?? "";
@@ -571,8 +569,7 @@ export const forgeLinkUndo = linkChange("undo");
571569 // POST /forges/:name/stop and /remove — the owner's hands on a hosted forge.
572570 function manageSubmit(act: (app: Ctx["app"], name: string) => Promise<Managed>, title: string) {
573571 return async (ctx: Ctx): Promise<Response> => {
574 const user = ctx.auth.user;
575 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
572 if (!adminPage(ctx)) return notFoundPage(ctx);
576573 const form = await readForm(ctx, "admin");
577574 if (form instanceof Response) return form;
578575 const done = await act(ctx.app, ctx.params["name"] ?? "");
@@ -599,8 +596,8 @@ export const forgeStopSubmit = manageSubmit(stopForge, "Forge stopped");
599596 // POST /forges/:name/sandbox — move a forge out of this forge's own process into a sandbox of its
600597 // own (`spawn/move_cell.ts`).
601598 export async function forgeSandboxSubmit(ctx: Ctx): Promise<Response> {
599 if (!adminPage(ctx)) return notFoundPage(ctx);
602600 const user = ctx.auth.user;
603 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
604601 const form = await readForm(ctx, "admin");
605602 if (form instanceof Response) return form;
606603 const name = ctx.params["name"] ?? "";
@@ -627,8 +624,7 @@ export const forgeRemoveSubmit = manageSubmit(removeForge, "Forge removed");
627624
628625 // GET /forges/:name/remove — what removing would delete, and the one button that does it.
629626 export async function forgeRemoveConfirm(ctx: Ctx): Promise<Response> {
630 const user = ctx.auth.user;
631 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
627 if (!adminPage(ctx)) return notFoundPage(ctx);
632628 const name = ctx.params["name"] ?? "";
633629 const child = (await listChildren(ctx.app)).find((c) => c.name === name);
634630 if (child === undefined) return notFoundPage(ctx);
@@ -702,8 +698,7 @@ async function ownCodeSection(ctx: Ctx): Promise<Html | null> {
702698 // POST /forges/:name/own-code — the owner's switch: `on` is "on" or "off"; then back to the list,
703699 // with a receipt.
704700 export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> {
705 const user = ctx.auth.user;
706 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
701 if (!adminPage(ctx)) return notFoundPage(ctx);
707702 const form = await readForm(ctx, "admin");
708703 if (form instanceof Response) return form;
709704 const want = form.get("on");
@@ -716,8 +711,8 @@ export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> {
716711
717712 // POST /forges/:name/size — raise a forge to a larger size (xlarge); a receipt on the list.
718713 export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> {
714 if (!adminPage(ctx)) return notFoundPage(ctx);
719715 const user = ctx.auth.user;
720 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
721716 const form = await readForm(ctx, "admin");
722717 if (form instanceof Response) return form;
723718 const name = ctx.params["name"] ?? "";
@@ -731,8 +726,8 @@ export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> {
731726 once. Who may is the action's answer (`actions/forge_recovery.ts`). */
732727 // GET — the preview; nothing is minted.
733728 export async function forgeRecoveryForm(ctx: Ctx): Promise<Response> {
729 if (!signedInPage(ctx)) return notFoundPage(ctx);
734730 const user = ctx.auth.user;
735 if (user === undefined) return notFoundPage(ctx);
736731 const name = ctx.params["name"] ?? "";
737732 const seen = await previewRecoveryDoor(ctx, user, name);
738733 const says = String(seen.body["says"] ?? seen.body["message"]);
@@ -758,8 +753,8 @@ export async function forgeRecoveryForm(ctx: Ctx): Promise<Response> {
758753
759754 // POST — mint it; the link is in this answer only.
760755 export async function forgeRecoverySubmit(ctx: Ctx): Promise<Response> {
756 if (!signedInPage(ctx)) return notFoundPage(ctx);
761757 const user = ctx.auth.user;
762 if (user === undefined) return notFoundPage(ctx);
763758 const form = await readForm(ctx, "rw");
764759 if (form instanceof Response) return form;
765760 const name = ctx.params["name"] ?? "";
src/web/pages/fork-flows.ts +2 −1
@@ -9,11 +9,12 @@ import { emptyList } from "../empty_words.ts";
99 import { html } from "../html.ts";
1010 import { page } from "../layout.ts";
1111 import { listCard, row, time } from "../ui.ts";
12 import { signedInPage } from "../../http/page_may.ts";
1213
1314 export function forkFlowsPage(ctx: Ctx): Response {
1415 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
16 if (!signedInPage(ctx)) return signInFirst(ctx);
1517 const user = ctx.auth.user;
16 if (user === undefined) return signInFirst(ctx);
1718 const reading = performance.now();
1819 const f = forkFlows(ctx.app, user);
1920 const empty = f.follows.length + f.sent.length + f.offered.length === 0;
src/web/pages/games.ts +4 −4
@@ -168,7 +168,7 @@ export async function gameServersSubmit(ctx: Ctx): Promise<Response> {
168168 }
169169
170170 export function boxOf(ctx: Ctx, need: Role, service = ""): { box: GameBox; role: Role } | Response {
171 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
171 if (!signedInPage(ctx)) return signInFirst(ctx);
172172 const box = boxNamed(ctx.app.db, ctx.params.box ?? "");
173173 if (box === undefined) return notFoundPage(ctx);
174174 // Seeing the box's page needs a grant on any of it; acting on it, the role there.
@@ -189,7 +189,7 @@ const startBox = (): Html => html`<form method="post" action="/talk" class="mt">
189189 // GET /games
190190 export function gamesPage(ctx: Ctx): Response {
191191 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
192 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
192 if (!signedInPage(ctx)) return signInFirst(ctx);
193193 const user = ctx.auth.user;
194194 const boxes = listBoxes(ctx.app.db).filter((b) => seesBox(ctx.app.db, user, b.id));
195195 return timePhase(ctx.request, "render", () => page({
@@ -217,7 +217,7 @@ export function gamesPage(ctx: Ctx): Response {
217217 // POST /settings/minecraft/code: a one-time code (ten minutes) the person types in game as !forge
218218 // link <code>.
219219 export async function gameLinkCode(ctx: Ctx): Promise<Response> {
220 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
220 if (!signedInPage(ctx)) return signInFirst(ctx);
221221 const form = await readForm(ctx, "rw");
222222 if (form instanceof Response) return form;
223223 const code = newLinkCode(ctx.app, ctx.auth.user);
@@ -227,7 +227,7 @@ export async function gameLinkCode(ctx: Ctx): Promise<Response> {
227227
228228 // POST /settings/minecraft/unlink: forget one of the person's linked names.
229229 export async function gameLinkRemove(ctx: Ctx): Promise<Response> {
230 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
230 if (!signedInPage(ctx)) return signInFirst(ctx);
231231 const form = await readForm(ctx, "rw");
232232 if (form instanceof Response) return form;
233233 unlink(ctx.app, ctx.auth.user.id, field(form, "box"), field(form, "player"));
src/web/pages/games_client_pack.ts +2 −1
@@ -15,6 +15,7 @@ import { pageHead } from "../chrome.ts";
1515 import { flashTo, page } from "../layout.ts";
1616 import { btn } from "../ui.ts";
1717 import { boxOf } from "./games.ts";
18 import { signedInPage } from "../../http/page_may.ts";
1819
1920 // POST /games/:box/:service/pack/link: a link for the service's pack, 30 days, shown once.
2021 export async function gamePackLink(ctx: Ctx): Promise<Response> {
@@ -70,7 +71,7 @@ export async function gamePackLinked(ctx: Ctx): Promise<Response> {
7071 const box = link === undefined ? undefined : boxById(ctx.app.db, link.boxId);
7172 if (link === undefined || box === undefined) return new Response("not found", { status: 404 });
7273 const headers = new Headers({ location: rawOf(ctx), "cache-control": "private, no-store" });
73 if (ctx.auth.user === undefined) {
74 if (!signedInPage(ctx)) {
7475 const client = clientBucket(ctx.request);
7576 const admitted = admitVisitor(ctx.app.db, () => loadKey(ctx.app.config.dataDir), {
7677 headers: ctx.request.headers,
src/web/pages/gate.ts +2 −2
@@ -72,7 +72,7 @@ export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null {
7272 export async function liftHoldSubmit(ctx: Ctx): Promise<Response> {
7373 const found = threadContext(ctx, "issue");
7474 if (found instanceof Response) return found;
75 if (!signedInPage(ctx, "gate")) return signInFirst(ctx);
75 if (!signedInPage(ctx)) return signInFirst(ctx);
7676 const form = await readForm(ctx, "rw");
7777 if (form instanceof Response) return form;
7878 const repo = loadRepo(ctx) ?? found.repo;
@@ -223,7 +223,7 @@ export function heldPage(ctx: Ctx): Response {
223223 export async function heldApply(ctx: Ctx): Promise<Response> {
224224 const repo = loadRepo(ctx);
225225 if (!repo) return notFoundPage(ctx);
226 if (!signedInPage(ctx, "gate")) return signInFirst(ctx);
226 if (!signedInPage(ctx)) return signInFirst(ctx);
227227 const form = await readForm(ctx, "rw");
228228 if (form instanceof Response) return form;
229229 const dest = `${repoBase(repo)}/held`;
src/web/pages/gifts.ts +1 −1
@@ -52,7 +52,7 @@ export function giftsBlock(ctx: Ctx, shown?: Shown, refusal?: string): Html | nu
5252
5353 // POST /settings/gifts
5454 export async function giftMake(ctx: Ctx): Promise<Response> {
55 if (!signedInPage(ctx, "gifts")) return signInFirst(ctx);
55 if (!signedInPage(ctx)) return signInFirst(ctx);
5656 const form = await readForm(ctx);
5757 if (form instanceof Response) return form;
5858 const made = giveGift(ctx.app, ctx.auth.user, publicOrigin(ctx.app.config.url, ctx.url.origin));
src/web/pages/global-map.ts +2 −1
@@ -45,6 +45,7 @@ import {
4545 type Marks,
4646 type Word,
4747 } from "./map.ts";
48 import { signedInPage } from "../../http/page_may.ts";
4849
4950 export interface Lane {
5051 readonly repo: Repo;
@@ -298,8 +299,8 @@ export function nextThings(lanes: readonly Lane[], n = NEXT_COUNT): Html {
298299
299300 /** GET /map — every app the viewer can see, one lane each. */
300301 export function globalMapPage(ctx: Ctx): Response {
302 if (!signedInPage(ctx)) return signInFirst(ctx);
301303 const viewer = ctx.auth.user;
302 if (!viewer) return signInFirst(ctx);
303304 const { request } = ctx;
304305 notePhase(request, "session", takeSessionTime(request));
305306 const spent: Spent = { layoutMs: 0 };
src/web/pages/grants.ts +2 −2
@@ -76,7 +76,7 @@ function grantsView(grants: readonly OAuthGrant[], reused: readonly ReusedGrant[
7676
7777 // GET /settings/grants
7878 export function grantsPage(ctx: Ctx): Response {
79 if (!signedInPage(ctx, "grants")) return signInFirst(ctx);
79 if (!signedInPage(ctx)) return signInFirst(ctx);
8080 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
8181 const grants = timePhase(ctx.request, "grants", () => myOAuthGrants(ctx.app, ctx.auth.user));
8282 const reused = myReusedGrants(ctx.app, ctx.auth.user);
@@ -87,7 +87,7 @@ export function grantsPage(ctx: Ctx): Response {
8787
8888 // POST /settings/grants/:id/revoke
8989 export async function grantRevoke(ctx: Ctx): Promise<Response> {
90 if (!signedInPage(ctx, "grants")) return signInFirst(ctx);
90 if (!signedInPage(ctx)) return signInFirst(ctx);
9191 const form = await readForm(ctx, "admin");
9292 if (form instanceof Response) return form;
9393 const revoked = revokeOAuthGrant(ctx.app, ctx.auth.user, ctx.params.id ?? "");
src/web/pages/home_flow.ts +6 −5
@@ -81,6 +81,7 @@ import { parkedSection } from "../parked_lines.ts";
8181 import { parkedFor } from "../../flow/parked_read.ts";
8282 import { firstWeekBlock } from "../first_week.ts";
8383 import { idleFor, type IdleReason } from "../../crew/idle_reason.ts";
84 import { adminPage, signedInPage } from "../../http/page_may.ts";
8485
8586 /**
8687 * The events that can move work between lanes, per lane. A burst of them is one fetch of the lane.
@@ -438,8 +439,8 @@ function viewSwitch(view: "lanes" | "table", only: string | null): Html {
438439 // redirects here.
439440 export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited<ReturnType<typeof spawnedForge>> }): Promise<Response> {
440441 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
442 if (!signedInPage(ctx)) return signInFirst(ctx);
441443 const user = ctx.auth.user;
442 if (user === undefined) return signInFirst(ctx);
443444 const { view, asked } = viewOf(ctx);
444445 const only = filterOf(ctx.url);
445446 const mine = waitsOf(ctx.url);
@@ -454,7 +455,7 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited
454455 // A spawned forge's owner is a client: the forge-wide figures are not theirs to see, whole home
455456 // or lean.
456457 const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app));
457 const wide = user.isAdmin && spawned === undefined;
458 const wide = adminPage(ctx) && spawned === undefined;
458459 const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now);
459460 const need = needLine(brokenOf(picture, wide, ctx.app.config.dataDir, now), new Set(asksToAnswer(ctx.app, user).map((a) => a.username)).size);
460461 // What the old home also carried and is not a lane: the box that tells the crew (with Notes and
@@ -597,15 +598,15 @@ export async function liveLaneFragment(ctx: Ctx): Promise<Response> {
597598 // GET /live/strip — an admin's figures, alone; no one else has a strip.
598599 export async function liveStripFragment(ctx: Ctx): Promise<Response> {
599600 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
600 const user = ctx.auth.user;
601 if (user === undefined) {
601 if (!signedInPage(ctx)) {
602602 notePhase(ctx.request, "render", 0);
603603 return fragment(html``, { status: 404 });
604604 }
605 const user = ctx.auth.user;
605606 const now = Date.now();
606607 const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now));
607608 const rendering = performance.now();
608 const wide = user.isAdmin && (await spawnedForge(ctx.app)) === undefined;
609 const wide = adminPage(ctx) && (await spawnedForge(ctx.app)) === undefined;
609610 const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) });
610611 notePhase(ctx.request, "render", performance.now() - rendering);
611612 return res;
src/web/pages/hosted-forges.ts +2 −2
@@ -120,8 +120,8 @@ export function forgeReachRows(
120120 }
121121
122122 function requireAdmin(ctx: Ctx): Response | undefined {
123 if (!signedInPage(ctx, "hosted-forges")) return signInFirst(ctx);
124 if (!adminPage(ctx, "hosted-forges", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
123 if (!signedInPage(ctx)) return signInFirst(ctx);
124 if (!adminPage(ctx)) return notFoundPage(ctx);
125125 return undefined;
126126 }
127127
src/web/pages/identities.ts +2 −2
@@ -67,7 +67,7 @@ const card = (c: Connection): Html => {
6767 // GET /settings/identities
6868 export function identitiesPage(ctx: Ctx): Response {
6969 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
70 if (!signedInPage(ctx, "identities")) return signInFirst(ctx);
70 if (!signedInPage(ctx)) return signInFirst(ctx);
7171 const list = connectionsOf(ctx.app, ctx.auth.user);
7272 const body = html`<section class="settings-block">
7373 <h2>Proven identities</h2>
@@ -100,7 +100,7 @@ const said = (ctx: Ctx, message: string, ok: boolean): Response =>
100100
101101 /** Read the form as the signed-in account, same-origin; the acts below share it. */
102102 async function acting(ctx: Ctx): Promise<{ form: import("../form.ts").Form } | Response> {
103 if (!signedInPage(ctx, "identities")) return signInFirst(ctx);
103 if (!signedInPage(ctx)) return signInFirst(ctx);
104104 const form = await readForm(ctx, "admin");
105105 return form instanceof Response ? form : { form };
106106 }
src/web/pages/inventory.ts +1 −1
@@ -63,7 +63,7 @@ function tally(items: readonly InventoryItem[]): string {
6363 }
6464
6565 export async function inventoryPage(ctx: Ctx): Promise<Response> {
66 if (!signedInPage(ctx, "inventory")) return signInFirst(ctx);
66 if (!signedInPage(ctx)) return signInFirst(ctx);
6767 const user = ctx.auth.user;
6868 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
6969 const origins = listUserOrigins(ctx.app, user);
src/web/pages/issues.ts +7 −7
@@ -149,7 +149,7 @@ export function newIssuePage(ctx: Ctx): Response {
149149 if (!repo) return timePhase(request, "render", () => notFoundPage(ctx));
150150 // `?sealed=1`: the repository page's "report it sealed" link.
151151 const sealed = ctx.url.searchParams.get("sealed") === "1";
152 if (!ctx.auth.user) {
152 if (!signedInPage(ctx)) {
153153 const open = timePhase(request, "access", () => canRead(ctx.app.db, repo, undefined));
154154 return timePhase(request, "render", () =>
155155 open ? accountOrReport(ctx, repo, sealed) : signInFirst(ctx),
@@ -215,8 +215,8 @@ function accountOrReport(ctx: Ctx, repo: Repo, sealed: boolean): Response {
215215 * repositories the viewer may write. Each carries `from` along.
216216 */
217217 export function newIssueAnywhere(ctx: Ctx): Response {
218 if (!signedInPage(ctx)) return signInFirst(ctx);
218219 const user = ctx.auth.user;
219 if (user === undefined) return signInFirst(ctx);
220220 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
221221 const from = cleanFrom(ctx.url.searchParams.get("from"));
222222 const query = from === undefined ? "" : `?from=${encodeURIComponent(from)}`;
@@ -250,7 +250,7 @@ export function newIssueAnywhere(ctx: Ctx): Response {
250250 export async function newIssueSubmit(ctx: Ctx): Promise<Response> {
251251 const repo = loadRepo(ctx);
252252 if (!repo) return notFoundPage(ctx);
253 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
253 if (!signedInPage(ctx)) return signInFirst(ctx);
254254 const form = await readForm(ctx, "rw");
255255 if (form instanceof Response) return form;
256256
@@ -298,7 +298,7 @@ export function issueThreadFragment(ctx: Ctx): Response {
298298 export async function issueSealSubmit(ctx: Ctx): Promise<Response> {
299299 const found = threadContext(ctx, "issue");
300300 if (found instanceof Response) return found;
301 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
301 if (!signedInPage(ctx)) return signInFirst(ctx);
302302 const form = await readForm(ctx, "rw");
303303 if (form instanceof Response) return form;
304304 const sealed = field(form, "sealed") === "1";
@@ -323,7 +323,7 @@ export async function issueSealSubmit(ctx: Ctx): Promise<Response> {
323323 export async function issuePrivateSubmit(ctx: Ctx): Promise<Response> {
324324 const found = threadContext(ctx, "issue");
325325 if (found instanceof Response) return found;
326 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
326 if (!signedInPage(ctx)) return signInFirst(ctx);
327327 const form = await readForm(ctx, "rw");
328328 if (form instanceof Response) return form;
329329 const made = await privateRepoForSealed(ctx.app, ctx.auth.user, found.repo, found.issue);
@@ -357,7 +357,7 @@ const BACK = new Map<string, { to: string; said: (n: number) => string }>([
357357 export async function issueCommentSubmit(ctx: Ctx): Promise<Response> {
358358 const found = threadContext(ctx, "issue");
359359 if (found instanceof Response) return found;
360 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
360 if (!signedInPage(ctx)) return signInFirst(ctx);
361361 const form = await readForm(ctx, "rw");
362362 if (form instanceof Response) return form;
363363
@@ -414,7 +414,7 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> {
414414 export async function issueQuestionSubmit(ctx: Ctx): Promise<Response> {
415415 const found = threadContext(ctx, "issue");
416416 if (found instanceof Response) return found;
417 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
417 if (!signedInPage(ctx)) return signInFirst(ctx);
418418 const form = await readForm(ctx, "rw");
419419 if (form instanceof Response) return form;
420420 const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`;
src/web/pages/iterations.ts +1 −1
@@ -584,7 +584,7 @@ const NOTE_ERRORS: Record<string, string> = {
584584 export async function noteSubmit(ctx: Ctx): Promise<Response> {
585585 const repo = loadRepo(ctx);
586586 if (!repo) return notFoundPage(ctx);
587 if (!signedInPage(ctx, "iterations")) return signInFirst(ctx);
587 if (!signedInPage(ctx)) return signInFirst(ctx);
588588 const form = await readForm(ctx, "rw");
589589 if (form instanceof Response) return form;
590590 const to = backTo(form, `${repoBase(repo)}/iterations`);
src/web/pages/knobs.ts +2 −2
@@ -51,8 +51,8 @@ export function knobsCard(ctx: Ctx): Html {
5151
5252 // POST /settings/crew/knobs
5353 export async function knobSet(ctx: Ctx): Promise<Response> {
54 if (!signedInPage(ctx, "knobs")) return signInFirst(ctx);
55 if (!adminPage(ctx, "knobs", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
54 if (!signedInPage(ctx)) return signInFirst(ctx);
55 if (!adminPage(ctx)) return notFoundPage(ctx);
5656 const form = await readForm(ctx, "admin");
5757 if (form instanceof Response) return form;
5858 const knob = field(form, "knob");
src/web/pages/limb.ts +3 −3
@@ -153,7 +153,7 @@ export function limbPreviewPage(ctx: Ctx): Response {
153153 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
154154 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
155155 if (!repo) return notFoundPage(ctx);
156 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
156 if (!signedInPage(ctx)) return signInFirst(ctx);
157157 const number = Number(ctx.params.number);
158158 const action = ctx.url.searchParams.get("action");
159159 if (action === "replan") return replanPreviewPage(ctx, repo, number);
@@ -350,7 +350,7 @@ export function limbPreviewPage(ctx: Ctx): Response {
350350 export async function limbSubmit(ctx: Ctx): Promise<Response> {
351351 const repo = loadRepo(ctx);
352352 if (!repo) return notFoundPage(ctx);
353 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
353 if (!signedInPage(ctx)) return signInFirst(ctx);
354354 const form = await readForm(ctx, "admin");
355355 if (form instanceof Response) return form;
356356 const number = Number(ctx.params.number);
@@ -440,7 +440,7 @@ export function limbReceiptPage(ctx: Ctx): Response {
440440 export async function limbUndo(ctx: Ctx): Promise<Response> {
441441 const repo = loadRepo(ctx);
442442 if (!repo) return notFoundPage(ctx);
443 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
443 if (!signedInPage(ctx)) return signInFirst(ctx);
444444 const form = await readForm(ctx, "admin");
445445 if (form instanceof Response) return form;
446446 const number = Number(ctx.params.number);
src/web/pages/maintenance.ts +8 −8
@@ -4,7 +4,7 @@
44 * once the forge is back, when and what was verified.
55 */
66
7 import { adminPage, signedInPage } from "../../http/page_may.ts";
7 import { adminPage, signedInPage, personAdminPage } from "../../http/page_may.ts";
88 import { json } from "../../http/respond.ts";
99 import { emptyNote } from "../empty_words.ts";
1010 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
@@ -42,8 +42,8 @@ import { diskLine } from "../../maintenance/disk_line.ts";
4242 import { readDisk } from "../../kernel/disk_reading.ts";
4343
4444 function admin(ctx: Ctx): Response | undefined {
45 if (!signedInPage(ctx, "maintenance")) return signInFirst(ctx);
46 if (!adminPage(ctx, "maintenance", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
45 if (!signedInPage(ctx)) return signInFirst(ctx);
46 if (!adminPage(ctx)) return notFoundPage(ctx);
4747 return undefined;
4848 }
4949
@@ -342,9 +342,9 @@ function quietedRows(withActions: boolean, rows: readonly Quieted[]): Html {
342342
343343 /** Who may press: a forge admin who is a person, the gate the finding cards' buttons have. */
344344 function mayQuiet(ctx: Ctx): Response | undefined {
345 if (!signedInPage(ctx)) return signInFirst(ctx);
345346 const user = ctx.auth.user;
346 if (user === undefined) return signInFirst(ctx);
347 if (!adminPage(ctx, "maintenance", user.isAdmin)) return notFoundPage(ctx);
347 if (!adminPage(ctx)) return notFoundPage(ctx);
348348 if (user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a person may quiet a finding." });
349349 return undefined;
350350 }
@@ -410,7 +410,7 @@ export function stalePullsSection(ctx: Ctx, withActions: boolean): Html {
410410 */
411411 export async function staleAction(ctx: Ctx): Promise<Response> {
412412 const user = ctx.auth.user;
413 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
413 if (!personAdminPage(ctx))
414414 return flashTo(ctx, "/maintenance", { tone: "danger", message: STALE_WORDS.forbidden });
415415 const form = await readForm(ctx, "admin");
416416 if (form instanceof Response) return form;
@@ -442,7 +442,7 @@ function mergedRows(withActions: boolean, found: readonly MergedBranch[]): Html
442442 */
443443 export async function mergedAction(ctx: Ctx): Promise<Response> {
444444 const user = ctx.auth.user;
445 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
445 if (!personAdminPage(ctx))
446446 return flashTo(ctx, "/maintenance", { tone: "danger", message: MERGED_WORDS.forbidden });
447447 const form = await readForm(ctx, "admin");
448448 if (form instanceof Response) return form;
@@ -475,7 +475,7 @@ function previewRows(withActions: boolean, found: readonly PreviewDir[]): Html {
475475 */
476476 export async function previewAction(ctx: Ctx): Promise<Response> {
477477 const user = ctx.auth.user;
478 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
478 if (!personAdminPage(ctx))
479479 return flashTo(ctx, "/maintenance", { tone: "danger", message: PREVIEW_WORDS.forbidden });
480480 const form = await readForm(ctx, "admin");
481481 if (form instanceof Response) return form;
src/web/pages/maintenance_budgets.ts +2 −1
@@ -13,6 +13,7 @@ import { field as formField, readForm } from "../form.ts";
1313 import { html, type Html } from "../html.ts";
1414 import { flashTo } from "../layout.ts";
1515 import { btn, field as formControl } from "../ui.ts";
16 import { personAdminPage } from "../../http/page_may.ts";
1617
1718 /** Every duty's budget row, in `names` order: two reads for all of them, not three a duty. */
1819 export function budgetRows(app: App, names: readonly string[], now = new Date()): Html[] {
@@ -40,8 +41,8 @@ function budgetOfRow(d: Duty, b: Budget, u: { runs: number; dollars: number }):
4041
4142 /** POST /maintenance/budget: an admin moves one duty's budgets; a blank value goes back to the duty's own. */
4243 export async function maintenanceBudget(ctx: Ctx): Promise<Response> {
44 if (!personAdminPage(ctx)) return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a forge admin who is a person sets a budget." });
4345 const user = ctx.auth.user;
44 if (user === undefined || !user.isAdmin || user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a forge admin who is a person sets a budget." });
4546 const form = await readForm(ctx, "admin");
4647 if (form instanceof Response) return form;
4748 const duty = duties().find((d) => d.name === formField(form, "duty"));
src/web/pages/migrate.ts +3 −3
@@ -710,7 +710,7 @@ async function show(
710710 // GET /migrate
711711 export async function migratePage(ctx: Ctx): Promise<Response> {
712712 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
713 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
713 if (!signedInPage(ctx)) return signInFirst(ctx);
714714 const q = ctx.url.searchParams;
715715 const origins = await timePhaseAsync(ctx.request, "origins", () =>
716716 originChoices(ctx),
@@ -759,7 +759,7 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
759759
760760 // POST /migrate
761761 export async function migrateSubmit(ctx: Ctx): Promise<Response> {
762 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
762 if (!signedInPage(ctx)) return signInFirst(ctx);
763763 const form = await readForm(ctx, "rw");
764764 if (form instanceof Response) return form;
765765 const values: MigrateValues = {
@@ -944,7 +944,7 @@ const migrateJobJs = /* js */ `
944944
945945 export function migrationJobPage(ctx: Ctx): Response {
946946 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
947 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
947 if (!signedInPage(ctx)) return signInFirst(ctx);
948948 const user = ctx.auth.user;
949949 const found = timePhase(ctx.request, "job", () =>
950950 migrationJobFor(user, ctx.params.job ?? ""),
src/web/pages/milestones.ts +1 −1
@@ -697,7 +697,7 @@ export async function milestonePage(
697697 export async function milestoneWatch(ctx: Ctx): Promise<Response> {
698698 const repo = loadRepo(ctx);
699699 if (!repo) return notFoundPage(ctx);
700 if (!signedInPage(ctx, "milestones")) return signInFirst(ctx);
700 if (!signedInPage(ctx)) return signInFirst(ctx);
701701 const form = await readForm(ctx, "rw");
702702 if (form instanceof Response) return form;
703703 const number = Number(ctx.params.number);
src/web/pages/model.ts +4 −4
@@ -153,8 +153,8 @@ export function grantCard(ctx: Ctx, user: User, at: string): Html {
153153
154154 // POST /settings/accounts/:username/model
155155 export async function grantAct(ctx: Ctx): Promise<Response> {
156 if (!signedInPage(ctx, "model")) return signInFirst(ctx);
157 if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
156 if (!signedInPage(ctx)) return signInFirst(ctx);
157 if (!adminPage(ctx)) return notFoundPage(ctx);
158158 const form = await readForm(ctx, "admin");
159159 if (form instanceof Response) return form;
160160 const username = ctx.params.username ?? "";
@@ -182,8 +182,8 @@ export async function grantAct(ctx: Ctx): Promise<Response> {
182182
183183 // POST /settings/accounts/:username/ceiling
184184 export async function ceilingAct(ctx: Ctx): Promise<Response> {
185 if (!signedInPage(ctx, "model")) return signInFirst(ctx);
186 if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
185 if (!signedInPage(ctx)) return signInFirst(ctx);
186 if (!adminPage(ctx)) return notFoundPage(ctx);
187187 const form = await readForm(ctx, "admin");
188188 if (form instanceof Response) return form;
189189 const username = ctx.params.username ?? "";
src/web/pages/my-repos.ts +2 −1
@@ -11,12 +11,13 @@ import { html } from "../html.ts";
1111 import { page } from "../layout.ts";
1212 import { emptyList } from "../empty_words.ts";
1313 import { btn, listCard, row } from "../ui.ts";
14 import { signedInPage } from "../../http/page_may.ts";
1415
1516 // GET /repos
1617 export function myReposPage(ctx: Ctx): Response {
1718 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
19 if (!signedInPage(ctx)) return signInFirst(ctx);
1820 const user = ctx.auth.user;
19 if (user === undefined) return signInFirst(ctx);
2021 const reading = performance.now();
2122 const repos = listReposWritableTo(ctx.app.db, user, { limit: 200, withoutArchived: true });
2223 const body =
src/web/pages/new-forge.ts +2 −1
@@ -59,6 +59,7 @@ import { cloudsOffered, NO_CHARGE, otherPlaces, placeWords, roomWords, whereFiel
5959 import { catalogPlan } from "../../spawn/cloud_placement.ts";
6060 import { TAB_FORGE_OFFER, TAB_FORGE_PAGE } from "../tabforge/words.ts";
6161 import { CEILING_PAGE } from "../../cloud/ceiling.ts";
62 import { adminPage } from "../../http/page_may.ts";
6263
6364 interface Values {
6465 readonly name: string;
@@ -666,7 +667,7 @@ export async function newForgePage(ctx: Ctx): Promise<Response> {
666667 if (user && user.kind !== "user") return notFoundPage(ctx);
667668 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
668669 // Only an admin is offered clouds, so only an admin's visit reads the providers.
669 if (user?.isAdmin === true) await refreshForPage(ctx.app);
670 if (adminPage(ctx)) await refreshForPage(ctx.app);
670671 const reads = await readsFor(ctx, user);
671672 const rendering = performance.now();
672673 // A code in the address moves to a cookie and out of the address (the log and history never hold
src/web/pages/next.ts +2 −2
@@ -221,7 +221,7 @@ function cutMark(fit: number, top: boolean, byPace: boolean): Html {
221221 /** One row, for an admin, to the page that sets the cap, while under a fifth is left (#13529). */
222222 function walletRow(ctx: Ctx, repo: Repo, base: string): Html | null {
223223 const cap = monthCap(ctx.app.db, repo.id);
224 if (cap === undefined || !ctx.auth.user || !canAdmin(ctx.app.db, repo, ctx.auth.user)) return null;
224 if (cap === undefined || !signedInPage(ctx) || !canAdmin(ctx.app.db, repo, ctx.auth.user)) return null;
225225 if (lowWallet(ctx.app.db, repo.id, new Date(), cap) === undefined) return null;
226226 return listCard([row({ id: "wallet-row", href: `${base}/wallet`, title: html`Raise the monthly cap`, nav: true })]);
227227 }
@@ -377,7 +377,7 @@ export function nextPage(ctx: Ctx): Response {
377377 export async function nextSubmit(ctx: Ctx): Promise<Response> {
378378 const repo: Repo | undefined = loadRepo(ctx);
379379 if (!repo) return notFoundPage(ctx);
380 if (!signedInPage(ctx, "next")) return signInFirst(ctx);
380 if (!signedInPage(ctx)) return signInFirst(ctx);
381381 const form = await readForm(ctx, "rw");
382382 if (form instanceof Response) return form;
383383 const dest = backTo(form, `${repoBase(repo)}/next`);
src/web/pages/next_all.ts +2 −1
@@ -11,11 +11,12 @@ import { pageHead, repoBase, signInFirst } from "../chrome.ts";
1111 import { html } from "../html.ts";
1212 import { page } from "../layout.ts";
1313 import { listCard, row } from "../ui.ts";
14 import { signedInPage } from "../../http/page_may.ts";
1415
1516 export function nextAllPage(ctx: Ctx): Response {
1617 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
18 if (!signedInPage(ctx)) return signInFirst(ctx);
1719 const user = ctx.auth.user;
18 if (user === undefined) return signInFirst(ctx);
1920 const asked = ctx.url.searchParams.getAll("repo");
2021 const narrowed = onlyNames(asked).length > 0;
2122 const groups = timePhase(ctx.request, "ranking", () => nextAll(ctx.app, user, asked));
src/web/pages/next_batch.ts +1 −1
@@ -56,7 +56,7 @@ export function batchButtons(live: readonly number[]): Html {
5656 export async function nextBatch(ctx: Ctx): Promise<Response> {
5757 const repo = loadRepo(ctx);
5858 if (!repo) return notFoundPage(ctx);
59 if (!signedInPage(ctx, "next_batch")) return signInFirst(ctx);
59 if (!signedInPage(ctx)) return signInFirst(ctx);
6060 const form = await readForm(ctx, "rw");
6161 if (form instanceof Response) return form;
6262 const dest = backTo(form, `${repoBase(repo)}/next`);
src/web/pages/notes.ts +4 −3
@@ -23,6 +23,7 @@ import { flashTo, page } from "../layout.ts";
2323 import { btn, listCard, row, time } from "../ui.ts";
2424 import { cut } from "../../actions/ask_state_words.ts";
2525 import { emptyLine } from "../empty_words.ts";
26 import { signedInPage } from "../../http/page_may.ts";
2627
2728 const HERE = "/notes";
2829 const SHOWN = 100;
@@ -53,8 +54,8 @@ export const NOTES_CSS = /* css */ `
5354 // GET /notes
5455 export async function notesView(ctx: Ctx): Promise<Response> {
5556 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
57 if (!signedInPage(ctx)) return signInFirst(ctx);
5658 const user = ctx.auth.user;
57 if (user === undefined) return signInFirst(ctx);
5859 const notes = timePhase(ctx.request, "notes", () => thoughtStream(ctx.app.db, user, { limit: SHOWN }));
5960 // The release that carried a pull is known only for the forge's own repository.
6061 const own = publicForgeRepo(ctx.app);
@@ -96,8 +97,8 @@ export async function notesView(ctx: Ctx): Promise<Response> {
9697
9798 // POST /notes
9899 export async function notesSave(ctx: Ctx): Promise<Response> {
100 if (!signedInPage(ctx)) return signInFirst(ctx);
99101 const user = ctx.auth.user;
100 if (user === undefined) return signInFirst(ctx);
101102 const form = await readForm(ctx, "rw");
102103 if (form instanceof Response) return form;
103104 const text = form.get("text");
@@ -113,8 +114,8 @@ const OVERRULED = { accepted: "Built after all.", declined: "Declined." } as con
113114
114115 // POST /notes/:id/overrule
115116 export async function notesOverrule(ctx: Ctx): Promise<Response> {
117 if (!signedInPage(ctx)) return signInFirst(ctx);
116118 const user = ctx.auth.user;
117 if (user === undefined) return signInFirst(ctx);
118119 const form = await readForm(ctx, "rw");
119120 if (form instanceof Response) return form;
120121 const done = overruleNote(ctx.app, user, ctx.params["id"] ?? "", form.get("do"));
src/web/pages/now.ts +2 −1
@@ -12,12 +12,13 @@ import { notFoundPage, signInFirst } from "../chrome.ts";
1212 import { html } from "../html.ts";
1313 import { page } from "../layout.ts";
1414 import { row, time } from "../ui.ts";
15 import { signedInPage } from "../../http/page_may.ts";
1516
1617 // GET /now/:stage
1718 export function nowPage(ctx: Ctx): Response {
1819 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
20 if (!signedInPage(ctx)) return signInFirst(ctx);
1921 const user = ctx.auth.user;
20 if (user === undefined) return signInFirst(ctx);
2122 const stage = NOW_STAGES.find((s) => s === ctx.params["stage"]);
2223 if (stage === undefined || !mayReadNow(user)) return notFoundPage(ctx);
2324 const reading = performance.now();
src/web/pages/oauth.ts +3 −2
@@ -22,6 +22,7 @@ import { field, readForm } from "../form.ts";
2222 import { html, type Html } from "../html.ts";
2323 import { page, redirect } from "../layout.ts";
2424 import { btn, field as formField } from "../ui.ts";
25 import { signedInPage } from "../../http/page_may.ts";
2526
2627 const PARAMS = [
2728 "client_id",
@@ -182,7 +183,7 @@ const fromQuery = (ctx: Ctx): Params =>
182183 ) as Params;
183184
184185 export function authorizePage(ctx: Ctx): Response {
185 if (ctx.auth.user === undefined || ctx.auth.via === "token")
186 if (!signedInPage(ctx) || ctx.auth.via === "token")
186187 return guard(
187188 redirect(
188189 `/signin?next=${encodeURIComponent(ctx.url.pathname + ctx.url.search)}`,
@@ -206,7 +207,7 @@ export function authorizePage(ctx: Ctx): Response {
206207 export async function authorizeSubmit(ctx: Ctx): Promise<Response> {
207208 const form = await readForm(ctx);
208209 if (form instanceof Response) return form;
209 if (ctx.auth.user === undefined || ctx.auth.via === "token")
210 if (!signedInPage(ctx) || ctx.auth.via === "token")
210211 return forbiddenPage(ctx, SIGN_IN_TO_DO);
211212 const request = parseAuthRequest(ctx.app.db, (n) => field(form, n));
212213 if (!request.ok) return refused(ctx, request.error);
src/web/pages/offer-receipt.ts +1 −1
@@ -12,7 +12,7 @@ import { html } from "../html.ts";
1212 import { page } from "../layout.ts";
1313
1414 export function offerReceiptPage(ctx: Ctx): Response {
15 if (!signedInPage(ctx, "offer-receipt")) return signInFirst(ctx);
15 if (!signedInPage(ctx)) return signInFirst(ctx);
1616 const r = readForkOffer(ctx.app.db, ctx.auth.user, ctx.params.id ?? "");
1717 if (r === undefined) return notFoundPage(ctx);
1818 const [owner = "", name = ""] = r.upstream.split("/");
src/web/pages/offer-upstream.ts +5 −5
@@ -52,7 +52,7 @@ export function offerCommitButton(
5252 repo: Repo,
5353 oid: string,
5454 ): Html | null {
55 if (repo.forkParentId === null || ctx.auth.user === undefined) return null;
55 if (repo.forkParentId === null || !signedInPage(ctx)) return null;
5656 if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return null;
5757 return html`<form method="post" action="${repoBase(repo)}/commit/${oid}/offer" class="mt">
5858 ${btn("Offer upstream", { size: "sm", icon: "merge" })}
@@ -63,7 +63,7 @@ export function offerCommitButton(
6363 export async function offerCommitPost(ctx: Ctx): Promise<Response> {
6464 const repo = loadRepo(ctx);
6565 if (!repo) return notFoundPage(ctx);
66 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
66 if (!signedInPage(ctx)) return signInFirst(ctx);
6767 const form = await readForm(ctx, "rw");
6868 if (form instanceof Response) return form;
6969 const rev = ctx.params.oid ?? "";
@@ -88,7 +88,7 @@ export async function offerCommitPost(ctx: Ctx): Promise<Response> {
8888 export async function offerWithdrawPost(ctx: Ctx): Promise<Response> {
8989 const fork = loadRepo(ctx);
9090 if (!fork) return notFoundPage(ctx);
91 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
91 if (!signedInPage(ctx)) return signInFirst(ctx);
9292 const form = await readForm(ctx, "rw");
9393 if (form instanceof Response) return form;
9494 const number = Number(ctx.params.number);
@@ -107,7 +107,7 @@ export async function offerWithdrawPost(ctx: Ctx): Promise<Response> {
107107 * offer applies.
108108 */
109109 export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null {
110 if (repo.forkParentId === null || ctx.auth.user === undefined) return null;
110 if (repo.forkParentId === null || !signedInPage(ctx)) return null;
111111 const preview = previewOfferPull(ctx.app, ctx.auth.user, repo, pull.number);
112112 if (!preview.ok) return null;
113113 const p = preview.value;
@@ -128,7 +128,7 @@ export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null {
128128 export async function offerPullPost(ctx: Ctx): Promise<Response> {
129129 const repo = loadRepo(ctx);
130130 if (!repo) return notFoundPage(ctx);
131 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
131 if (!signedInPage(ctx)) return signInFirst(ctx);
132132 const form = await readForm(ctx, "rw");
133133 if (form instanceof Response) return form;
134134 const number = Number(ctx.params.number);
src/web/pages/og.ts +2 −1
@@ -51,6 +51,7 @@ import { templateIdOfRef, templateRow } from "../../spawn/template_list.ts";
5151 import { marksFor } from "./map.ts";
5252 import { Busy, pngCache, type PngCache } from "../og/png-cache.ts";
5353 import { drawer } from "../og/raster.ts";
54 import { signedInPage } from "../../http/page_may.ts";
5455
5556 /** What an anonymous reader may see of a repository, or nothing. */
5657 function publicRepo(ctx: Ctx, repo: Repo | undefined): Repo | undefined {
@@ -351,7 +352,7 @@ function repoCard(ctx: Ctx, ref: string): CardInput | undefined {
351352
352353 /** Whether this response is for the signed-in viewer alone, not for a shared cache. */
353354 function personal(ctx: Ctx, kind: OgKind, ref: string): boolean {
354 if (kind !== "repo" || ctx.auth.user === undefined) return false;
355 if (kind !== "repo" || !signedInPage(ctx)) return false;
355356 const [owner, name] = ref.split("~");
356357 if (!owner || !name || !isSafeName(owner) || !isSafeName(name)) return false;
357358 const repo = getRepo(ctx.app.db, owner, name);
src/web/pages/org.ts +2 −2
@@ -497,7 +497,7 @@ function orgSecrets(ctx: Ctx, name: string): Html | null {
497497 // POST /:owner/-/subscriptions
498498 export async function orgSubscriptionsSave(ctx: Ctx): Promise<Response> {
499499 const org = requireOrgAdmin(ctx);
500 if (!org || ctx.auth.user === undefined || !adminPage(ctx, "org", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
500 if (!org || !adminPage(ctx)) return notFoundPage(ctx);
501501 const form = await readForm(ctx, "admin");
502502 if (form instanceof Response) return form;
503503 saveGrants(ctx, form, org.id, agentsOnForge(ctx));
@@ -552,7 +552,7 @@ export function newOrgPage(ctx: Ctx): Response {
552552
553553 // POST /organizations/new
554554 export async function newOrgSubmit(ctx: Ctx): Promise<Response> {
555 if (!signedInPage(ctx, "org")) return signInFirst(ctx);
555 if (!signedInPage(ctx)) return signInFirst(ctx);
556556 const form = await readForm(ctx, "rw");
557557 if (form instanceof Response) return form;
558558 const name = field(form, "name");
src/web/pages/origin-reach.ts +3 −3
@@ -113,8 +113,8 @@ function askRow(a: HostAsk): Html {
113113 * person has neither.
114114 */
115115 export function reachBlock(ctx: Ctx, blocked?: Blocked): Html | null {
116 if (!signedInPage(ctx)) return null;
116117 const user = ctx.auth.user;
117 if (user === undefined) return null;
118118 const asks = asksOfUser(ctx.app.db, user.id);
119119 const open = asks.filter((a) => a.state !== "offered");
120120 const named = blocked?.ask?.body["host"];
@@ -183,7 +183,7 @@ export const reachJs = /* js */ `
183183
184184 // POST /settings/origins/reach — the button: ask the host to allow `host`.
185185 export async function originReachAsk(ctx: Ctx): Promise<Response> {
186 if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx);
186 if (!signedInPage(ctx)) return signInFirst(ctx);
187187 const form = await readForm(ctx, "rw");
188188 if (form instanceof Response) return form;
189189 const host = field(form, "host").trim();
@@ -209,7 +209,7 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> {
209209
210210 // POST /settings/origins/reach/dismiss — take one's own answered ask off the page.
211211 export async function originReachDismiss(ctx: Ctx): Promise<Response> {
212 if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx);
212 if (!signedInPage(ctx)) return signInFirst(ctx);
213213 const form = await readForm(ctx, "rw");
214214 if (form instanceof Response) return form;
215215 dismissAsk(ctx.app, ctx.auth.user, field(form, "host"));
src/web/pages/origins.ts +1 −1
@@ -248,7 +248,7 @@ export const callbackUri = (ctx: Ctx): string =>
248248 * enumerate whose GitHub is connected, let alone spend it.
249249 */
250250 export function accountOnly(ctx: Ctx): Response | undefined {
251 if (!signedInPage(ctx, "origins")) return signInFirst(ctx);
251 if (!signedInPage(ctx)) return signInFirst(ctx);
252252 if (ctx.auth.via === "session" || ctx.auth.via === "password")
253253 return undefined;
254254 if (ctx.auth.scope === "admin") return undefined;
src/web/pages/packs-settings.ts +3 −3
@@ -6,7 +6,7 @@
66 * the change is on /packs at once.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
9 import { signedInPage, personAdminPage } from "../../http/page_may.ts";
1010 import { sshOn } from "../../settings/ssh.ts";
1111 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1212 import { refreshCatalogQuietly } from "../../packs/catalog.ts";
@@ -21,8 +21,8 @@ import { btn, field as uiField, row } from "../ui.ts";
2121 import { accountSections } from "./origins.ts";
2222
2323 function requireAdmin(ctx: Ctx): Response | undefined {
24 if (!signedInPage(ctx, "packs-settings")) return signInFirst(ctx);
25 if (!adminPage(ctx, "packs-settings", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
24 if (!signedInPage(ctx)) return signInFirst(ctx);
25 if (!personAdminPage(ctx)) return notFoundPage(ctx);
2626 return undefined;
2727 }
2828
src/web/pages/packs.ts +2 −2
@@ -20,7 +20,7 @@ import { btn, copyField, field as uiField, row, timeAgo } from "../ui.ts";
2020 import { listReposVisibleTo } from "../../core/repos.ts";
2121 import { changeRepos, editPack, getPack, history, listPacks, mayCurate, resolveRepos, slugOf, type CuratedPack, type PackRepo } from "../../packs/curated.ts";
2222 import { field, readForm } from "../form.ts";
23 import { adminPage } from "../../http/page_may.ts";
23 import { personAdminPage } from "../../http/page_may.ts";
2424
2525 const plural = (n: number, one: string): string => `${n} ${one}${n === 1 ? "" : "s"}`;
2626
@@ -226,7 +226,7 @@ export async function packPage(ctx: Ctx): Promise<Response> {
226226
227227 // POST /packs/mirror (admin)
228228 export async function packsMirror(ctx: Ctx): Promise<Response> {
229 if (!adminPage(ctx, "packs", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
229 if (!personAdminPage(ctx)) return notFoundPage(ctx);
230230 const form = await readForm(ctx, "admin");
231231 if (form instanceof Response) return form;
232232 const done = await mirrorPacks(ctx.app, ctx.auth.user);
src/web/pages/passkeys.ts +3 −3
@@ -63,7 +63,7 @@ const refuse = (status: number, message: string) =>
6363 /** A signed-in browser, on a same-origin request; else the refusal to send. */
6464 function sessionOnly(ctx: Ctx): Response | undefined {
6565 if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE);
66 if (!signedInPage(ctx, "passkeys")) return refuse(401, "Sign in first.");
66 if (!signedInPage(ctx)) return refuse(401, "Sign in first.");
6767 // A browser the platform edge signed in is a signed-in browser too: adding a
6868 // passkey there is how an account comes to sign in without the edge (#9432).
6969 if (ctx.auth.via !== "session" && ctx.auth.via !== "edge")
@@ -74,7 +74,7 @@ function sessionOnly(ctx: Ctx): Response | undefined {
7474 // GET /settings/passkeys
7575 export function passkeysPage(ctx: Ctx): Response {
7676 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
77 if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx);
77 if (!signedInPage(ctx)) return signInFirst(ctx);
7878 const user = ctx.auth.user;
7979 const keys = timePhase(ctx.request, "passkeys", () => listPasskeys(ctx.app.db, user.id));
8080 const rendering = performance.now();
@@ -165,7 +165,7 @@ export async function passkeyAdd(ctx: Ctx): Promise<Response> {
165165
166166 // POST /settings/passkeys/:id/delete
167167 export async function passkeyDelete(ctx: Ctx): Promise<Response> {
168 if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx);
168 if (!signedInPage(ctx)) return signInFirst(ctx);
169169 const form = await readForm(ctx, "admin");
170170 if (form instanceof Response) return form;
171171 const gone = removeOwnPasskey(ctx.app, ctx.auth.user, ctx.params.id ?? "");
src/web/pages/payments.ts +3 −2
@@ -15,6 +15,7 @@ import { toCsv } from "../../text/csv_write.ts";
1515 import { securityFloor } from "../../http/respond.ts";
1616 import { EXPORT_PATH, EXPORT_WORDS } from "../../core/account_export.ts";
1717 import { paymentsFor, PAYMENTS_CAP, type PaymentLine } from "../../actions/forge_bill.ts";
18 import { signedInPage } from "../../http/page_may.ts";
1819
1920 const STATUS_WORDS = { paid: "Paid", refunded: "Refunded", failed: "Failed" } as const;
2021
@@ -75,8 +76,8 @@ export function paymentsCsvText(app: App, user: User | undefined, cap = PAYMENTS
7576 // GET /settings/payments.csv: the page's rows, same order, up to `cap`; one build per person per
7677 // CSV_GAP_MS.
7778 export function paymentsCsv(ctx: Ctx, cap = PAYMENTS_CSV_CAP): Response {
79 if (!signedInPage(ctx)) return signInFirst(ctx);
7880 const user = ctx.auth.user;
79 if (user === undefined) return signInFirst(ctx);
8081 const now = Date.now();
8182 const lastCsv = lastCsvOf(ctx.app);
8283 if (now - (lastCsv.get(user.id) ?? 0) < CSV_GAP_MS) {
@@ -107,7 +108,7 @@ export const exportRow = (): Html =>
107108
108109 // GET /settings/payments
109110 export function paymentsPage(ctx: Ctx): Response {
110 if (ctx.auth.user === undefined) return signInFirst(ctx);
111 if (!signedInPage(ctx)) return signInFirst(ctx);
111112 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
112113 const rendering = performance.now();
113114 const { rows, more } = paymentsFor(ctx.app, ctx.auth.user);
src/web/pages/people.ts +4 −4
@@ -46,8 +46,8 @@ export function appsMade(ctx: Ctx): Map<string, string[]> {
4646
4747 // GET /settings/people
4848 export function peoplePage(ctx: Ctx): Response {
49 if (!signedInPage(ctx, "people")) return signInFirst(ctx);
50 if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
49 if (!signedInPage(ctx)) return signInFirst(ctx);
50 if (!adminPage(ctx)) return notFoundPage(ctx);
5151 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
5252 const only = wordFilter(ctx.url.searchParams.get("role"));
5353 const rows = timePhase(ctx.request, "people", () => peopleByActivity(ctx.app.db, only));
@@ -126,8 +126,8 @@ export function peoplePage(ctx: Ctx): Response {
126126
127127 // POST /settings/people/:username/role
128128 export async function roleAct(ctx: Ctx): Promise<Response> {
129 if (!signedInPage(ctx, "people")) return signInFirst(ctx);
130 if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
129 if (!signedInPage(ctx)) return signInFirst(ctx);
130 if (!adminPage(ctx)) return notFoundPage(ctx);
131131 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
132132 const form = await readForm(ctx, "admin");
133133 if (form instanceof Response) return form;
src/web/pages/proven_identities.ts +1 −1
@@ -56,7 +56,7 @@ export function identitiesBlock(ctx: Ctx): Html {
5656 // again. Only from the confirm page (`/-/confirm`), with the address typed back: the terminal asks
5757 // first too.
5858 export async function emailRemove(ctx: Ctx): Promise<Response> {
59 if (!signedInPage(ctx, "proven_identities")) return signInFirst(ctx);
59 if (!signedInPage(ctx)) return signInFirst(ctx);
6060 const form = await readForm(ctx, "rw");
6161 if (form instanceof Response) return form;
6262 if (field(form, "confirm") !== ctx.auth.user.email)
src/web/pages/pull-guest.ts +1 −1
@@ -74,7 +74,7 @@ export async function guestWalls(ctx: Ctx, repo: Repo, pull: Pull, baseOid: stri
7474 export async function pullApproveGuestSubmit(ctx: Ctx): Promise<Response> {
7575 const found = pullContext(ctx);
7676 if (found instanceof Response) return found;
77 if (!signedInPage(ctx, "pull-guest")) return signInFirst(ctx);
77 if (!signedInPage(ctx)) return signInFirst(ctx);
7878 const form = await readForm(ctx, "rw");
7979 if (form instanceof Response) return form;
8080 const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`;

45 more files not shown.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs