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

Access 3, web pages: every page that gates on isAdmin or sign-in also asks may(), counted beside the old check #18400

opened this

Merged 2h 35m ago, live in production

scout/forge:scout/18395-access-3-web-pages-every-page-that-gates → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/18395-access-3-web-pages-every-page-that-gates was merged into main as 8f27ed4.

Review

Sign in to review this change.
111 files changed +589 −296
docs/features/may.md +8
@@ -44,3 +44,11 @@ the evidence that moving the door changed nobody's access.
4444 something asks `forge.write` with the credential you send, so an `ro` token is told it may only read
4545 (`src/http/mcp/tool_may.ts`). The old scope floor is worked out beside it, and where the two part the count's door is
4646 `mcp <tool>`. The terminal's "What I can do" lists `forge.write` with the rest.
47
48 **The web pages ask it.** A page only the admin sees asks `forge.administer`, and a page that needs you signed in asks
49 by what the request does: `forge.read` to open it (GET), `forge.write` to change something (POST), both with the
50 credential you send (`src/http/page_may.ts`). An `ro` token that opens its own page is no parting; one that posts is.
51 An anonymous visit to a signed-in page parts on `forge.read`, which is open to all: that row says the page needs more
52 than reading. The page's old check (`isAdmin`, an account
53 behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is
54 `web <page>`, the page's module. Nothing you can open on the web changes while the count is read.
src/core/access_disagreement.ts +8 −2
@@ -5,12 +5,16 @@
55 * principal and what `may` said. No account, token or repository is written, so the table can be
66 * read by anyone who keeps the forge without learning who asked.
77 *
8 * The count is telemetry, written `quietly`: it records how the forge is asked, not anything a
9 * page shows, so it must not move the write clock and turn a cached page's validator (#18395).
10 *
811 * Read it with `SELECT * FROM access_disagreement ORDER BY seen DESC` (docs/ROLES.md).
912 */
1013
1114 import type { Database } from "bun:sqlite";
1215 import type { Action } from "./may.ts";
1316 import type { PrincipalKind } from "./principal.ts";
17 import { quietly } from "./write_clock.ts";
1418
1519 /** Count one disagreement: `may` said `said`, the old check said the opposite. */
1620 export function noteDisagreement(
@@ -20,9 +24,11 @@ export function noteDisagreement(
2024 principal: PrincipalKind,
2125 said: boolean,
2226 ): void {
23 db.query(
27 quietly(db, () =>
28 db.query(
2429 `INSERT INTO access_disagreement (door, action, principal, may, seen, last_at)
2530 VALUES (?1, ?2, ?3, ?4, 1, ?5)
2631 ON CONFLICT (door, action, principal, may) DO UPDATE SET seen = seen + 1, last_at = excluded.last_at`,
27 ).run(door, action, principal, said ? 1 : 0, new Date().toISOString());
32 ).run(door, action, principal, said ? 1 : 0, new Date().toISOString()),
33 );
2834 }
src/http/may_beside.ts added +18
@@ -0,0 +1,18 @@
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 { noteDisagreement } from "../core/access_disagreement.ts";
9 import { type Action, holds } 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 const asking = principalOf(ctx.auth);
15 const said = holds(ctx.app.db, asking, action);
16 if (said !== old) noteDisagreement(ctx.app.db, door, action, asking.kind, said);
17 return said;
18 }
src/http/mcp/tool_may.ts +3 −6
@@ -14,20 +14,17 @@
1414 */
1515
1616 import type { Database } from "bun:sqlite";
17 import { noteDisagreement } from "../../core/access_disagreement.ts";
1817 import { holds } from "../../core/may.ts";
19 import { principalOf, principalOfUser } from "../../core/principal.ts";
18 import { principalOfUser } from "../../core/principal.ts";
2019 import { scopeAllows } from "../../core/tokens.ts";
2120 import type { User } from "../../core/users.ts";
2221 import type { Ctx } from "../context.ts";
22 import { mayBeside } from "../may_beside.ts";
2323
2424 /** Is this account the forge's admin? What `adminOnly` and `listedTo: "admin"` ask. */
2525 export const adminAccount = (db: Database, user: User): boolean => holds(db, principalOfUser(user), "forge.administer");
2626
2727 /** May this call change something? What a tool's `writes` asks; `door` names it in the count. */
2828 export function mayToolWrite(ctx: Ctx, door: string): boolean {
29 const asking = principalOf(ctx.auth);
30 const said = holds(ctx.app.db, asking, "forge.write");
31 if (said !== scopeAllows(ctx.auth.scope ?? "ro", "rw")) noteDisagreement(ctx.app.db, `mcp ${door}`, "forge.write", asking.kind, said);
32 return said;
29 return mayBeside(ctx, `mcp ${door}`, "forge.write", scopeAllows(ctx.auth.scope ?? "ro", "rw"));
3330 }
src/http/page_may.ts added +38
@@ -0,0 +1,38 @@
1 /**
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.
7 *
8 * - `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.
14 */
15
16 import type { Action } from "../core/may.ts";
17 import type { User } from "../core/users.ts";
18 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);
29
30 /** A request with an account behind it. */
31 export type SignedIn = Ctx & { auth: Ctx["auth"] & { user: User } };
outdated

Medium: this asks forge.write for every sign-in gate, GET pages included. A read-only token may legitimately read them, so each such view records a false disagreement. Take the action as a parameter (forge.read for GET, forge.write for writes) so the count stays meaningful.

32
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");
35
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);
src/web/pages/access.ts +2 −1
@@ -5,6 +5,7 @@
55 * never an address — stands for the caller.
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { sshOn } from "../../settings/ssh.ts";
910 import { listAccess } from "../../actions/access_log.ts";
1011 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
@@ -18,7 +19,7 @@ import { accountSections } from "./origins.ts";
1819 // GET /settings/access
1920 export function accessPage(ctx: Ctx): Response {
2021 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
21 if (!ctx.auth.user) return signInFirst(ctx);
22 if (!signedInPage(ctx, "access")) return signInFirst(ctx);
2223 const user = ctx.auth.user;
2324 const ua = ctx.url.searchParams.get("ua")?.slice(0, 100) ?? "";
2425 const path = ctx.url.searchParams.get("path")?.slice(0, 200) ?? "";
src/web/pages/account.ts +25 −24
@@ -9,6 +9,7 @@
99 * has been read once.
1010 */
1111
12 import { signedInPage } from "../../http/page_may.ts";
1213 import { UPSTREAM_REPO } from "../../core/upstream.ts";
1314 import { emptyNote } from "../empty_words.ts";
1415 import { resendVerification } from "../../actions/verify.ts";
@@ -255,7 +256,7 @@ function dotfilesView(ctx: Ctx, error?: string): Html {
255256
256257 // POST /settings/dotfiles
257258 export async function dotfilesUpdate(ctx: Ctx): Promise<Response> {
258 if (!ctx.auth.user) return signInFirst(ctx);
259 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
259260 const form = await readForm(ctx, "admin");
260261 if (form instanceof Response) return form;
261262 const saved = setDotfilesRepo(ctx.app.db, ctx.auth.user, field(form, "repo"));
@@ -315,7 +316,7 @@ function parentLinkView(ctx: Ctx): Html {
315316
316317 // POST /settings/parent/unlink
317318 export async function parentUnlink(ctx: Ctx): Promise<Response> {
318 if (!ctx.auth.user) return signInFirst(ctx);
319 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
319320 const form = await readForm(ctx, "admin");
320321 if (form instanceof Response) return form;
321322 const issuer = parentIssuerOf(ctx.app.config);
@@ -328,7 +329,7 @@ export async function parentUnlink(ctx: Ctx): Promise<Response> {
328329
329330 // POST /settings/edge/link
330331 export async function edgeLink(ctx: Ctx): Promise<Response> {
331 if (!ctx.auth.user) return signInFirst(ctx);
332 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
332333 const form = await readForm(ctx, "admin");
333334 if (form instanceof Response) return form;
334335 const login = edgeIdentity(ctx.request, activeEdgeToken(ctx.app));
@@ -352,7 +353,7 @@ export async function edgeLink(ctx: Ctx): Promise<Response> {
352353
353354 // POST /settings/edge/unlink
354355 export async function edgeUnlink(ctx: Ctx): Promise<Response> {
355 if (!ctx.auth.user) return signInFirst(ctx);
356 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
356357 const form = await readForm(ctx, "admin");
357358 if (form instanceof Response) return form;
358359 if (unlinkEdgeLogin(ctx.app.db, ctx.auth.user.id))
@@ -383,7 +384,7 @@ function unverifiedNotice(ctx: Ctx): Html {
383384
384385 // POST /settings/email/verify
385386 export async function resendVerifyLink(ctx: Ctx): Promise<Response> {
386 if (!ctx.auth.user) return signInFirst(ctx);
387 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
387388 const form = await readForm(ctx);
388389 if (form instanceof Response) return form;
389390 const sent = await resendVerification(ctx.app, ctx.auth.user);
@@ -595,7 +596,7 @@ export function appearancePage(ctx: Ctx): Response {
595596
596597 // GET /settings/shells
597598 export function shellsPage(ctx: Ctx): Response {
598 if (!ctx.auth.user) return signInFirst(ctx);
599 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
599600 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
600601 const body = html`${dotfilesView(ctx)}${shellsView(ctx, ctx.auth.user)}`;
601602 return timePhase(ctx.request, "render", () => accountShell(ctx, "shells", "Shells", body));
@@ -603,7 +604,7 @@ export function shellsPage(ctx: Ctx): Response {
603604
604605 // POST /settings/shells/:id/stop
605606 export async function shellStop(ctx: Ctx): Promise<Response> {
606 if (!ctx.auth.user) return signInFirst(ctx);
607 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
607608 const form = await readForm(ctx, "admin");
608609 if (form instanceof Response) return form;
609610 const id = ctx.params.id ?? "";
@@ -613,7 +614,7 @@ export async function shellStop(ctx: Ctx): Promise<Response> {
613614
614615 // POST /settings/shells/stop-idle
615616 export async function shellsStopIdle(ctx: Ctx): Promise<Response> {
616 if (!ctx.auth.user) return signInFirst(ctx);
617 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
617618 const form = await readForm(ctx, "admin");
618619 if (form instanceof Response) return form;
619620 return flashTo(ctx, "/settings/shells", { message: stoppedIdleSays(stopIdleShells(ctx.app, ctx.auth.user.id)) });
@@ -632,7 +633,7 @@ function hostedBackupRow(dataDir: string): Html | null {
632633
633634 // GET /settings
634635 export function accountPage(ctx: Ctx): Response {
635 if (!ctx.auth.user) return signInFirst(ctx);
636 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
636637 const user = ctx.auth.user;
637638 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
638639 // Read in the order the page lays them out; each phase is named for what it reads.
@@ -664,7 +665,7 @@ export function accountPage(ctx: Ctx): Response {
664665
665666 // POST /settings/notify
666667 export async function notifyUpdate(ctx: Ctx): Promise<Response> {
667 if (!ctx.auth.user) return signInFirst(ctx);
668 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
668669 const form = await readForm(ctx, "admin");
669670 if (form instanceof Response) return form;
670671 const saved = setNotifyUrl(ctx.app.db, ctx.auth.user.id, field(form, "url"));
@@ -689,7 +690,7 @@ export async function notifyUpdate(ctx: Ctx): Promise<Response> {
689690
690691 // POST /settings/focus
691692 export async function focusUpdate(ctx: Ctx): Promise<Response> {
692 if (!ctx.auth.user) return signInFirst(ctx);
693 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
693694 if (ctx.auth.user.kind !== "user") return forbiddenPage(ctx, "A focus is a person's, not an agent's.");
694695 const form = await readForm(ctx, "admin");
695696 if (form instanceof Response) return form;
@@ -704,7 +705,7 @@ export async function focusUpdate(ctx: Ctx): Promise<Response> {
704705
705706 // POST /settings
706707 export async function accountUpdate(ctx: Ctx): Promise<Response> {
707 if (!ctx.auth.user) return signInFirst(ctx);
708 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
708709 const form = await readForm(ctx, "admin");
709710 if (form instanceof Response) return form;
710711 const displayName = field(form, "displayName").trim();
@@ -785,7 +786,7 @@ function passwordView(error?: {
785786
786787 // GET /settings/password
787788 export function passwordPage(ctx: Ctx): Response {
788 if (!ctx.auth.user) return signInFirst(ctx);
789 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
789790 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
790791 const standing = closeStanding(ctx.app.db, ctx.auth.user.id);
791792 const body = html`${passwordView()}${closeView(ctx, standing)}`;
@@ -795,7 +796,7 @@ export function passwordPage(ctx: Ctx): Response {
795796
796797 // POST /settings/password
797798 export async function passwordUpdate(ctx: Ctx): Promise<Response> {
798 if (!ctx.auth.user) return signInFirst(ctx);
799 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
799800 const form = await readForm(ctx, "admin");
800801 if (form instanceof Response) return form;
801802 const current = field(form, "current");
@@ -978,7 +979,7 @@ function tokensView(ctx: Ctx): Html {
978979
979980 // GET /settings/tokens
980981 export function tokensPage(ctx: Ctx): Response {
981 if (!ctx.auth.user) return signInFirst(ctx);
982 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
982983 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
983984 const body = tokensView(ctx);
984985 return timePhase(ctx.request, "render", () => accountShell(ctx, "tokens", "Access codes", body));
@@ -986,7 +987,7 @@ export function tokensPage(ctx: Ctx): Response {
986987
987988 // POST /settings/tokens
988989 export async function tokenCreate(ctx: Ctx): Promise<Response> {
989 if (!ctx.auth.user) return signInFirst(ctx);
990 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
990991 // Minting a token must come from the account itself — a browser session,
991992 // the platform edge's sign-in, or the password — never from another token
992993 // (no privilege bootstrapping). readForm below refuses a cross-site post.
@@ -1023,7 +1024,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> {
10231024
10241025 // POST /settings/tokens/:id/delete
10251026 export async function tokenDelete(ctx: Ctx): Promise<Response> {
1026 if (!ctx.auth.user) return signInFirst(ctx);
1027 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
10271028 const form = await readForm(ctx, "admin");
10281029 if (form instanceof Response) return form;
10291030 const revoked = deleteToken(ctx.app, ctx.auth.user, ctx.params.id ?? "");
@@ -1036,7 +1037,7 @@ export async function tokenDelete(ctx: Ctx): Promise<Response> {
10361037
10371038 // POST /settings/sessions/:id/delete
10381039 export async function sessionDelete(ctx: Ctx): Promise<Response> {
1039 if (!ctx.auth.user) return signInFirst(ctx);
1040 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
10401041 const form = await readForm(ctx, "admin");
10411042 if (form instanceof Response) return form;
10421043 const user = ctx.auth.user;
@@ -1055,7 +1056,7 @@ export async function sessionDelete(ctx: Ctx): Promise<Response> {
10551056
10561057 // POST /settings/sessions/end-others
10571058 export async function sessionsOthersDelete(ctx: Ctx): Promise<Response> {
1058 if (!ctx.auth.user) return signInFirst(ctx);
1059 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
10591060 const form = await readForm(ctx, "admin");
10601061 if (form instanceof Response) return form;
10611062 const done = signOutElsewhere(ctx.app, ctx.auth.user, cookieValue(ctx.request, "forge_session"));
@@ -1141,7 +1142,7 @@ function keysOff(ctx: Ctx): Response {
11411142
11421143 // GET /settings/keys
11431144 export function keysPage(ctx: Ctx): Response {
1144 if (!ctx.auth.user) return signInFirst(ctx);
1145 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
11451146 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11461147 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
11471148 const body = keysView(ctx, { name: "", key: "" });
@@ -1150,7 +1151,7 @@ export function keysPage(ctx: Ctx): Response {
11501151
11511152 // POST /settings/keys
11521153 export async function keyCreate(ctx: Ctx): Promise<Response> {
1153 if (!ctx.auth.user) return signInFirst(ctx);
1154 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
11541155 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11551156 // A key outlives the token and opens the terminal, so an rw token is
11561157 // refused here as over the API and MCP (#14762); a session is admin.
@@ -1183,7 +1184,7 @@ export async function keyCreate(ctx: Ctx): Promise<Response> {
11831184
11841185 // POST /settings/keys/:id/delete
11851186 export async function keyDelete(ctx: Ctx): Promise<Response> {
1186 if (!ctx.auth.user) return signInFirst(ctx);
1187 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
11871188 if (!sshOn(ctx.app.db)) return keysOff(ctx);
11881189 // A key outlives the token and opens the terminal, so an rw token is
11891190 // refused here as over the API and MCP (#14762); a session is admin.
@@ -1277,7 +1278,7 @@ function closeRefused(ctx: Ctx, said: CloseSaid): Response {
12771278
12781279 // POST /settings/account/close
12791280 export async function accountClose(ctx: Ctx): Promise<Response> {
1280 if (!ctx.auth.user) return signInFirst(ctx);
1281 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
12811282 if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF);
12821283 const user = ctx.auth.user;
12831284 const form = await readForm(ctx, "admin");
@@ -1303,7 +1304,7 @@ const CLOSE_ITSELF = "Closing an account, or keeping it, is asked from the accou
13031304
13041305 // POST /settings/account/keep
13051306 export async function accountKeep(ctx: Ctx): Promise<Response> {
1306 if (!ctx.auth.user) return signInFirst(ctx);
1307 if (!signedInPage(ctx, "account")) return signInFirst(ctx);
13071308 if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF);
13081309 const form = await readForm(ctx, "admin");
13091310 if (form instanceof Response) return form;
src/web/pages/accounts.ts +16 −15
@@ -5,6 +5,7 @@
55 * only; anyone else gets the forge's one 404.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
89 import { sshOn } from "../../settings/ssh.ts";
910 import { emptyNote } from "../empty_words.ts";
1011 import {
@@ -140,8 +141,8 @@ function wayBackForms(ctx: Ctx): Html | null {
140141
141142 // POST /settings/accounts/:username/way-back — the link, shown once on the page.
142143 export async function wayBackAct(ctx: Ctx): Promise<Response> {
143 if (!ctx.auth.user) return signInFirst(ctx);
144 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
144 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
145 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
145146 const form = await readForm(ctx, "admin");
146147 if (form instanceof Response) return form;
147148 const username = ctx.params.username ?? "";
@@ -178,7 +179,7 @@ export function accountsPage(ctx: Ctx): Response {
178179
179180 /** The page, with what an act needs said first (`notice`) when it did not finish. */
180181 function accountsView(ctx: Ctx, notice?: Html, status = 200): Response {
181 if (!ctx.auth.user) return signInFirst(ctx);
182 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
182183 const user = ctx.auth.user;
183184 const listed = timePhase(ctx.request, "accounts", () =>
184185 listAccounts(ctx.app, user),
@@ -339,8 +340,8 @@ function isOtherAdmin(ctx: Ctx, username: string): boolean {
339340
340341 // GET /settings/accounts/:username — one person, on one screen, with what an admin may do
341342 export function personSignInsPage(ctx: Ctx): Response {
342 if (!ctx.auth.user) return signInFirst(ctx);
343 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
343 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
344 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
344345 const username = ctx.params.username ?? "";
345346 const named = getUserByName(ctx.app.db, username);
346347 // An organization has no sign-ins: its page is its model grant and spend ceilings.
@@ -440,8 +441,8 @@ export function personSignInsPage(ctx: Ctx): Response {
440441 // POST /settings/accounts/:username/(reset|end-sessions)
441442 export function accessAct(act: "reset" | "end-sessions") {
442443 return async (ctx: Ctx): Promise<Response> => {
443 if (!ctx.auth.user) return signInFirst(ctx);
444 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
444 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
445 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
445446 const form = await readForm(ctx, "admin");
446447 if (form instanceof Response) return form;
447448 const username = ctx.params.username ?? "";
@@ -467,8 +468,8 @@ export function accessAct(act: "reset" | "end-sessions") {
467468 // POST /settings/accounts/:username/(tokens|sessions)/:id/delete
468469 export function signInAct(what: "token" | "session") {
469470 return async (ctx: Ctx): Promise<Response> => {
470 if (!ctx.auth.user) return signInFirst(ctx);
471 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
471 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
472 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
472473 const form = await readForm(ctx, "admin");
473474 if (form instanceof Response) return form;
474475 const username = ctx.params.username ?? "";
@@ -502,8 +503,8 @@ const DONE: Readonly<Record<Act, string>> = {
502503 // POST /settings/accounts/:username/(suspend|unsuspend|remove)
503504 export function accountAct(act: Act) {
504505 return async (ctx: Ctx): Promise<Response> => {
505 if (!ctx.auth.user) return signInFirst(ctx);
506 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
506 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
507 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
507508 const form = await readForm(ctx, "admin");
508509 if (form instanceof Response) return form;
509510 const username = ctx.params.username ?? "";
@@ -547,8 +548,8 @@ export function accountAct(act: Act) {
547548
548549 // GET /settings/accounts/:username/retire — everything removal would take; removes nothing
549550 export function retirePage(ctx: Ctx): Response {
550 if (!ctx.auth.user) return signInFirst(ctx);
551 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
551 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
552 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
552553 const username = ctx.params.username ?? "";
553554 const plan = retirementPlan(ctx.app, ctx.auth.user, username);
554555 if (!plan.ok)
@@ -605,8 +606,8 @@ export function retirePage(ctx: Ctx): Response {
605606
606607 // POST /settings/accounts/:username/retire
607608 export async function retireAct(ctx: Ctx): Promise<Response> {
608 if (!ctx.auth.user) return signInFirst(ctx);
609 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
609 if (!signedInPage(ctx, "accounts")) return signInFirst(ctx);
610 if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
610611 const form = await readForm(ctx, "admin");
611612 if (form instanceof Response) return form;
612613 const username = ctx.params.username ?? "";
src/web/pages/admin-limits.ts +8 −7
@@ -29,6 +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";
3233
3334 // GET /admin/limits
3435 export function limitsPage(ctx: Ctx): Response {
@@ -257,7 +258,7 @@ export function limitsPage(ctx: Ctx): Response {
257258 // POST /admin/limits
258259 export async function limitsSet(ctx: Ctx): Promise<Response> {
259260 // Checked before the body is read: a non-admin learns nothing of the door.
260 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent")
261 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
261262 return notFoundPage(ctx);
262263 const form = await readForm(ctx, "admin");
263264 if (form instanceof Response) return form;
@@ -293,7 +294,7 @@ export async function limitsSet(ctx: Ctx): Promise<Response> {
293294
294295 // POST /admin/quotas
295296 export async function quotasSet(ctx: Ctx): Promise<Response> {
296 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent")
297 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
297298 return notFoundPage(ctx);
298299 const form = await readForm(ctx, "admin");
299300 if (form instanceof Response) return form;
@@ -314,7 +315,7 @@ export async function quotasSet(ctx: Ctx): Promise<Response> {
314315
315316 // POST /admin/signup
316317 export async function signupSet(ctx: Ctx): Promise<Response> {
317 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent")
318 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
318319 return notFoundPage(ctx);
319320 const form = await readForm(ctx, "admin");
320321 if (form instanceof Response) return form;
@@ -331,7 +332,7 @@ export async function signupSet(ctx: Ctx): Promise<Response> {
331332
332333 // POST /admin/agent-start
333334 export async function agentStartSet(ctx: Ctx): Promise<Response> {
334 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
335 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
335336 const form = await readForm(ctx, "admin");
336337 if (form instanceof Response) return form;
337338 const changed = changeAgentStart(ctx.app, ctx.auth.user, field(form, "agent_start"));
@@ -347,7 +348,7 @@ export async function agentStartSet(ctx: Ctx): Promise<Response> {
347348
348349 // POST /admin/billing-links
349350 export async function billingLinksSet(ctx: Ctx): Promise<Response> {
350 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
351 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
351352 const form = await readForm(ctx, "admin");
352353 if (form instanceof Response) return form;
353354 const changed = changeBillingLinks(
@@ -367,7 +368,7 @@ export async function billingLinksSet(ctx: Ctx): Promise<Response> {
367368
368369 // POST /admin/invites
369370 export async function inviteMint(ctx: Ctx): Promise<Response> {
370 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent")
371 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
371372 return notFoundPage(ctx);
372373 const form = await readForm(ctx, "admin");
373374 if (form instanceof Response) return form;
@@ -389,7 +390,7 @@ export async function inviteMint(ctx: Ctx): Promise<Response> {
389390
390391 // POST /admin/invites/:id/revoke
391392 export async function inviteRevoke(ctx: Ctx): Promise<Response> {
392 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent")
393 if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent"))
393394 return notFoundPage(ctx);
394395 const form = await readForm(ctx, "admin");
395396 if (form instanceof Response) return form;
src/web/pages/advisories.ts +2 −1
@@ -14,9 +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";
1718
1819 const gate = (ctx: Ctx): Response | undefined =>
19 !ctx.auth.user ? signInFirst(ctx) : ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx);
20 !ctx.auth.user ? signInFirst(ctx) : adminPage(ctx, "advisories", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx);
2021
2122 const line = (a: Seen) =>
2223 row({
src/web/pages/app_templates.ts +2 −1
@@ -15,11 +15,12 @@ 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";
1819
1920 function denied(ctx: Ctx): Response | undefined {
2021 const user = ctx.auth.user;
2122 if (!user) return signInFirst(ctx);
22 if (user.isAdmin && user.kind === "user") return undefined;
23 if (adminPage(ctx, "app_templates", user.isAdmin && user.kind === "user")) return undefined;
2324 return page(
2425 {
2526 ctx,
src/web/pages/app_variants.ts +2 −1
@@ -5,6 +5,7 @@
55 * values, retire it, make it main (docs/features/variants.md).
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import {
910 makeMain,
1011 registerVariant,
@@ -98,7 +99,7 @@ type Verb = (ctx: Ctx, repo: NonNullable<ReturnType<typeof loadRepo>>, form: For
9899 async function mutate(ctx: Ctx, verb: Verb): Promise<Response> {
99100 const repo = loadRepo(ctx);
100101 if (!repo) return notFoundPage(ctx);
101 if (!ctx.auth.user) return signInFirst(ctx);
102 if (!signedInPage(ctx, "app_variants")) return signInFirst(ctx);
102103 const form = await readForm(ctx, "rw");
103104 if (form instanceof Response) return form;
104105 return verb(ctx, repo, form);
src/web/pages/apps.ts +5 −4
@@ -12,6 +12,7 @@
1212 * 404 for everyone.
1313 */
1414
15 import { signedInPage } from "../../http/page_may.ts";
1516 import { appsStanding } from "../studio/standing.ts";
1617 import { keyOf } from "../keymap.ts";
1718 import { stepsOf } from "../../core/review_steps.ts";
@@ -437,7 +438,7 @@ function newAppForm(
437438
438439 // GET /apps/new
439440 export async function newAppPage(ctx: Ctx): Promise<Response> {
440 if (!ctx.auth.user) return signInFirst(ctx);
441 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
441442 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
442443 const picks = plannerOffered(ctx);
443444 const offered = await timePhaseAsync(ctx.request, "templates", () => templateChoices(ctx.app, ctx.auth.user));
@@ -461,7 +462,7 @@ export async function newAppPage(ctx: Ctx): Promise<Response> {
461462
462463 // POST /apps/new
463464 export async function newAppSubmit(ctx: Ctx): Promise<Response> {
464 if (!ctx.auth.user) return signInFirst(ctx);
465 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
465466 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
466467 const form = await readForm(ctx, "rw");
467468 if (form instanceof Response) return form;
@@ -813,7 +814,7 @@ function appsOpenResponse(ctx: Ctx): Response {
813814 // up: a private app and a name nobody holds answer alike (#13678).
814815 const target = resolveAppHostname(ctx.app, runtime.options.domain, host);
815816 if (target === undefined) return notFoundPage(ctx);
816 if (!ctx.auth.user) return signInFirst(ctx);
817 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
817818 if (target === "unknown") return notFoundPage(ctx);
818819 const repo = getRepoById(ctx.app.db, target.app.repoId);
819820 if (!repo) return notFoundPage(ctx);
@@ -864,7 +865,7 @@ async function envForm(
864865 ): Promise<{ repo: Repo; env: string; user: User } | Response> {
865866 const repo = loadRepo(ctx);
866867 if (!repo) return notFoundPage(ctx);
867 if (!ctx.auth.user) return signInFirst(ctx);
868 if (!signedInPage(ctx, "apps")) return signInFirst(ctx);
868869 const form = await readForm(ctx, "rw");
869870 if (form instanceof Response) return form;
870871 return { repo, env: ctx.params.env ?? "", user: ctx.auth.user };
src/web/pages/audit.ts +2 −1
@@ -13,6 +13,7 @@
1313 * which are as public as the file in the repository.
1414 */
1515
16 import { signedInPage } from "../../http/page_may.ts";
1617 import { appsRuntime } from "../../apps/runtime_registry.ts";
1718 import { appsForRepos, getAppByRepo } from "../../core/apps.ts";
1819 import { canWrite, listReposVisibleTo, type Repo } from "../../core/repos.ts";
@@ -384,7 +385,7 @@ export async function auditCsv(ctx: Ctx): Promise<Response> {
384385 export async function auditProbeSubmit(ctx: Ctx): Promise<Response> {
385386 const repo = loadRepo(ctx);
386387 if (!repo) return notFoundPage(ctx);
387 if (!ctx.auth.user) return signInFirst(ctx);
388 if (!signedInPage(ctx, "audit")) return signInFirst(ctx);
388389 const form = await readForm(ctx, "rw");
389390 if (form instanceof Response) return form;
390391 if (!canWrite(ctx.app.db, repo, ctx.auth.user))
src/web/pages/backups.ts +6 −5
@@ -13,6 +13,7 @@
1313 * was /settings/resilience, which now sends here.
1414 */
1515
16 import { adminPage, signedInPage } from "../../http/page_may.ts";
1617 import { sshOn } from "../../settings/ssh.ts";
1718 import {
1819 forgetDestination,
@@ -56,8 +57,8 @@ import { badge, btn, fileSize, icon, row, time } from "../ui.ts";
5657 import { accountSections } from "./origins.ts";
5758
5859 function requireAdmin(ctx: Ctx): Response | undefined {
59 if (!ctx.auth.user) return signInFirst(ctx);
60 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
60 if (!signedInPage(ctx, "backups")) return signInFirst(ctx);
61 if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
6162 return undefined;
6263 }
6364
@@ -290,7 +291,7 @@ export async function backupsPage(ctx: Ctx): Promise<Response> {
290291
291292 /** GET /settings/backups/live — the moving part alone, which the page refetches on an event. */
292293 export async function backupsLive(ctx: Ctx): Promise<Response> {
293 if (!ctx.auth.user?.isAdmin) return fragment(html``, { status: 404 });
294 if (!adminPage(ctx, "backups", ctx.auth.user?.isAdmin === true)) return fragment(html``, { status: 404 });
294295 const svc = snapshotsOf(ctx.app);
295296 if (svc === undefined || svc.store === undefined) return fragment(html``, { status: 404 });
296297 return fragment(await movingPart(ctx, svc, svc.store), { request: ctx.request });
@@ -656,8 +657,8 @@ export function lanesCard(ctx: Ctx): Html | "" {
656657
657658 /** POST /settings/backups/drill — restore the newest snapshot, keep what came of it. */
658659 export async function backupsDrill(ctx: Ctx): Promise<Response> {
659 if (!ctx.auth.user) return signInFirst(ctx);
660 if (!ctx.auth.user.isAdmin)
660 if (!signedInPage(ctx, "backups")) return signInFirst(ctx);
661 if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin))
661662 return new Response("Forbidden", {
662663 status: 403,
663664 headers: { "content-type": "text/plain; charset=utf-8" },
src/web/pages/billing.ts +13 −12
@@ -5,6 +5,7 @@
55 * Anyone else gets the not-found page.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
89 import { sshOn } from "../../settings/ssh.ts";
910 import { emptyNote } from "../empty_words.ts";
1011 import { ledBlock } from "./visitors.ts";
@@ -160,7 +161,7 @@ function portalSection(ctx: Ctx, r: Refused | undefined): Html | null {
160161
161162 // POST /settings/billing/portal
162163 export async function billingSetPortal(ctx: Ctx): Promise<Response> {
163 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
164 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
164165 const form = await readForm(ctx, "admin");
165166 if (form instanceof Response) return form;
166167 const value = field(form, "portal_url");
@@ -172,7 +173,7 @@ export async function billingSetPortal(ctx: Ctx): Promise<Response> {
172173
173174 // POST /settings/billing/links
174175 export async function billingSetLinks(ctx: Ctx): Promise<Response> {
175 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
176 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
176177 const form = await readForm(ctx, "admin");
177178 if (form instanceof Response) return form;
178179 const current = readBillingLinks(ctx.app, ctx.auth.user);
@@ -215,7 +216,7 @@ function lapseWords(l: Lapse): string {
215216 // GET /settings/billing
216217 export function billingPage(ctx: Ctx): Response {
217218 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
218 if (!ctx.auth.user) return signInFirst(ctx);
219 if (!signedInPage(ctx, "billing")) return signInFirst(ctx);
219220 return billingView(ctx);
220221 }
221222
@@ -312,7 +313,7 @@ function billingView(ctx: Ctx, shown?: Shown, status = 200, refusal?: Refused):
312313
313314 // POST /settings/billing/codes
314315 export async function billingMakeCode(ctx: Ctx): Promise<Response> {
315 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
316 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
316317 const form = await readForm(ctx, "admin");
317318 if (form instanceof Response) return form;
318319 const values = { kind: field(form, "kind"), plan: field(form, "plan"), uses: field(form, "uses"), note: field(form, "note"), expires: field(form, "expires") };
@@ -323,7 +324,7 @@ export async function billingMakeCode(ctx: Ctx): Promise<Response> {
323324
324325 // POST /settings/billing/codes/revoke
325326 export async function billingRevokeCode(ctx: Ctx): Promise<Response> {
326 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
327 if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
327328 const form = await readForm(ctx, "admin");
328329 if (form instanceof Response) return form;
329330 const done = revoke(ctx.app, ctx.auth.user, field(form, "id"));
@@ -361,14 +362,14 @@ function changeView(ctx: Ctx, forge: string, plan: string, refused = false): Res
361362
362363 // GET /settings/billing/change?forge=&plan= — the preview, before the confirm.
363364 export function billingChange(ctx: Ctx): Response {
364 if (!ctx.auth.user) return signInFirst(ctx);
365 if (!isPerson(ctx)) return notFoundPage(ctx);
365 if (!signedInPage(ctx, "billing")) return signInFirst(ctx);
366 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
366367 return changeView(ctx, ctx.url.searchParams.get("forge") ?? "", ctx.url.searchParams.get("plan") ?? "");
367368 }
368369
369370 // POST /settings/billing/grant — the confirm: it must carry what the preview showed.
370371 export async function billingGrant(ctx: Ctx): Promise<Response> {
371 if (!isPerson(ctx)) return notFoundPage(ctx);
372 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
372373 const form = await readForm(ctx, "admin");
373374 if (form instanceof Response) return form;
374375 const forge = field(form, "forge");
@@ -388,7 +389,7 @@ const back = (ctx: Ctx, r: { ok: true; message: string } | { ok: false; error: B
388389
389390 // POST /settings/billing/stripe/connect
390391 export async function stripeConnect(ctx: Ctx): Promise<Response> {
391 if (!isPerson(ctx)) return notFoundPage(ctx);
392 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
392393 const form = await readForm(ctx, "admin");
393394 if (form instanceof Response) return form;
394395 const r = await connectStripe(ctx.app, ctx.auth.user, field(form, "key"), field(form, "secret"));
@@ -397,7 +398,7 @@ export async function stripeConnect(ctx: Ctx): Promise<Response> {
397398
398399 // POST /settings/billing/stripe/secret
399400 export async function stripeSecret(ctx: Ctx): Promise<Response> {
400 if (!isPerson(ctx)) return notFoundPage(ctx);
401 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
401402 const form = await readForm(ctx, "admin");
402403 if (form instanceof Response) return form;
403404 const r = saveSigningSecret(ctx.app, ctx.auth.user, field(form, "secret"));
@@ -406,7 +407,7 @@ export async function stripeSecret(ctx: Ctx): Promise<Response> {
406407
407408 // POST /settings/billing/stripe/disconnect
408409 export async function stripeDisconnect(ctx: Ctx): Promise<Response> {
409 if (!isPerson(ctx)) return notFoundPage(ctx);
410 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
410411 const form = await readForm(ctx, "admin");
411412 if (form instanceof Response) return form;
412413 const r = await disconnectStripe(ctx.app, ctx.auth.user);
@@ -416,7 +417,7 @@ export async function stripeDisconnect(ctx: Ctx): Promise<Response> {
416417 // POST /settings/billing/orders/retry — an admin who is a person retries a paid order whose forge
417418 // was not made.
418419 export async function orderRetry(ctx: Ctx): Promise<Response> {
419 if (!isPerson(ctx)) return notFoundPage(ctx);
420 if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx);
420421 const form = await readForm(ctx, "admin");
421422 if (form instanceof Response) return form;
422423 const r = await retryOrder(ctx.app, ctx.auth.user, field(form, "id"));
src/web/pages/boards-index-stream.ts +2 −1
@@ -15,6 +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";
1819
1920 /** A burst of events is read once, this long after the first. */
2021 export const SETTLE_MS = 100;
@@ -28,7 +29,7 @@ export function readNumbers(app: App, now = Date.now()): Numbers {
2829
2930 export function boardsIndexStream(ctx: Ctx): Response {
3031 const u = ctx.auth.user;
31 if (u?.isAdmin !== true || u.kind === "agent") return notFoundPage(ctx);
32 if (!adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent")) return notFoundPage(ctx);
3233 const { app } = ctx;
3334 return eventStream(app, ctx.request, (emit, _close, ready) => {
3435 let sent = readNumbers(app);
src/web/pages/boards-stream.ts +2 −1
@@ -12,11 +12,12 @@ 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";
1516
1617 export async function boardStream(ctx: Ctx): Promise<Response> {
1718 const u = ctx.auth.user;
1819 const slug = ctx.params.slug ?? "";
19 if (u?.isAdmin !== true || u.kind === "agent" || !isSlug(slug)) return notFoundPage(ctx);
20 if (u === undefined || !adminPage(ctx, "boards-stream", u.isAdmin && u.kind !== "agent") || !isSlug(slug)) return notFoundPage(ctx);
2021 const view = readView(ctx.url.searchParams);
2122 const picture = await boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined);
2223 if (picture === undefined || isFailed(picture) || picture.board === null) return notFoundPage(ctx);
src/web/pages/boards-view.ts +2 −1
@@ -38,6 +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";
4142
4243 const sizes = (max: number, word: string, now: number) =>
4344 [1, 2, 3].slice(0, max).map((n) => ({ value: String(n), label: `${String(n)} ${word}`, selected: n === now }));
@@ -91,7 +92,7 @@ function grid(app: App, slug: string, board: Board, panels: readonly PanelDrawn[
9192
9293 const denied = (ctx: Ctx) => {
9394 const u = ctx.auth.user;
94 return u?.isAdmin !== true || u.kind === "agent";
95 return !adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent");
9596 };
9697
9798 /**
src/web/pages/boards.ts +3 −2
@@ -24,6 +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";
2728
2829 const AGGREGATES = ["count", "sum", "avg", "max"] as const;
2930 const OPS = ["eq", "ne", "lt", "lte", "gt", "gte", "starts"] as const;
@@ -106,7 +107,7 @@ export function paramsOf(q: Record<string, unknown>, chart: Chart = "line"): Par
106107 // GET /boards/data: a `?ask=` sentence is read by the rules only, so no link can spend the model.
107108 export async function boardsPage(ctx: Ctx): Promise<Response> {
108109 const user = ctx.auth.user;
109 if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx);
110 if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
110111 return explorer(ctx, user, ctx.url.searchParams.get("ask"), false);
111112 }
112113
@@ -114,7 +115,7 @@ export async function boardsPage(ctx: Ctx): Promise<Response> {
114115 // asker's budget; `readForm` refuses a form another site sent (`crossOrigin`), as every mutation is.
115116 export async function boardsAsk(ctx: Ctx): Promise<Response> {
116117 const user = ctx.auth.user;
117 if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx);
118 if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
118119 const form = await readForm(ctx, "admin");
119120 if (form instanceof Response) return form;
120121 const asked = form.get("ask");
src/web/pages/bottleneck.ts +2 −1
@@ -4,6 +4,7 @@
44 * beside it. Numbers are `system/bottleneck.ts`'s, the same the MCP `system` tool
55 * (`kind: bottleneck`) reads. First paint is server-rendered; nothing polls.
66 */
7 import { signedInPage } from "../../http/page_may.ts";
78 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
89 import { telemetryReader } from "../../actions/telemetry.ts";
910 import type { Ctx } from "../../http/context.ts";
@@ -31,7 +32,7 @@ function opRow(o: Op): Html {
3132
3233 export async function bottleneckPage(ctx: Ctx): Promise<Response> {
3334 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
34 if (!ctx.auth.user) return signInFirst(ctx);
35 if (!signedInPage(ctx, "bottleneck")) return signInFirst(ctx);
3536 const reader = telemetryReader(ctx.app, ctx.auth.user);
3637 if (reader?.kind !== "owner") return notFoundPage(ctx);
3738 const rendering = performance.now();
src/web/pages/branches.ts +3 −2
@@ -15,6 +15,7 @@
1515 * are readable and nothing more, which is the whole rule of a live browse.
1616 */
1717
18 import { signedInPage } from "../../http/page_may.ts";
1819 import { emptyList } from "../empty_words.ts";
1920 import { createBranchSaying, deleteBranch } from "../../actions/branches.ts";
2021 import type { Repo } from "../../core/repos.ts";
@@ -420,7 +421,7 @@ export async function renderBranches(
420421 export async function branchCreate(ctx: Ctx): Promise<Response> {
421422 const repo = loadRepo(ctx);
422423 if (!repo) return notFoundPage(ctx);
423 if (!ctx.auth.user) return signInFirst(ctx);
424 if (!signedInPage(ctx, "branches")) return signInFirst(ctx);
424425 const form = await readForm(ctx, "rw");
425426 if (form instanceof Response) return form;
426427
@@ -446,7 +447,7 @@ export async function branchCreate(ctx: Ctx): Promise<Response> {
446447 export async function branchDelete(ctx: Ctx): Promise<Response> {
447448 const repo = loadRepo(ctx);
448449 if (!repo) return notFoundPage(ctx);
449 if (!ctx.auth.user) return signInFirst(ctx);
450 if (!signedInPage(ctx, "branches")) return signInFirst(ctx);
450451 const form = await readForm(ctx, "rw");
451452 if (form instanceof Response) return form;
452453
src/web/pages/builds.ts +5 −4
@@ -6,6 +6,7 @@
66 * first pins hang from its parent repository's, which its objects share.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import { deletePin, pinBuild } from "../../actions/builds.ts";
1011 import { previewBuild } from "../../actions/build_preview.ts";
1112 import { getAppByRepo } from "../../core/apps.ts";
@@ -76,7 +77,7 @@ export async function buildsPage(ctx: Ctx): Promise<Response> {
7677 export async function deletePinSubmit(ctx: Ctx): Promise<Response> {
7778 const repo = loadRepo(ctx);
7879 if (!repo) return notFoundPage(ctx);
79 if (!ctx.auth.user) return signInFirst(ctx);
80 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
8081 const form = await readForm(ctx, "rw");
8182 if (form instanceof Response) return form;
8283 const gone = await deletePin(ctx.app, ctx.auth.user, repo, ctx.params.label ?? "");
@@ -153,7 +154,7 @@ export async function newBuildPage(ctx: Ctx): Promise<Response> {
153154 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
154155 const repo = loadRepo(ctx);
155156 if (!repo) return notFoundPage(ctx);
156 if (!ctx.auth.user) return signInFirst(ctx);
157 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
157158 if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx);
158159 const base = repoBase(repo);
159160 const dir = repoDir(ctx.app.reposRoot, repo.ownerName, repo.name);
@@ -222,7 +223,7 @@ const PIN_ERRORS: Record<string, string> = {
222223 export async function pinBuildSubmit(ctx: Ctx): Promise<Response> {
223224 const repo = loadRepo(ctx);
224225 if (!repo) return notFoundPage(ctx);
225 if (!ctx.auth.user) return signInFirst(ctx);
226 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
226227 const form = await readForm(ctx, "rw");
227228 if (form instanceof Response) return form;
228229 const base = repoBase(repo);
@@ -257,7 +258,7 @@ const PREVIEW_ERRORS: Record<string, string> = {
257258 export async function previewBuildSubmit(ctx: Ctx): Promise<Response> {
258259 const repo = loadRepo(ctx);
259260 if (!repo) return notFoundPage(ctx);
260 if (!ctx.auth.user) return signInFirst(ctx);
261 if (!signedInPage(ctx, "builds")) return signInFirst(ctx);
261262 const form = await readForm(ctx, "rw");
262263 if (form instanceof Response) return form;
263264 const preview = await previewBuild(ctx.app, ctx.auth.user, repo, formValue(form, "sha"));
src/web/pages/capacity.ts +3 −2
@@ -6,6 +6,7 @@
66 * and each one is listed below the settings: who, when, from what to what.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { CAPACITY_GROUPS, DERIVED_WORDS, REASON_WORDS, changeCapacity, checkCapacity, edgeOffDryRun, listCapacity, type CapacityRow } from "../../actions/capacity.ts";
1011 import { CAPACITY, REASON_MAX, belowCeiling, bootDefault, needsReason, type CapacityKey } from "../../core/capacity.ts";
1112 import { effectOf, loadLine } from "../../actions/capacity_effects.ts";
@@ -26,8 +27,8 @@ import { lentLine } from "../../checks/lent_scope.ts";
2627 import { lentIn } from "../../checks/runner_jobs.ts";
2728
2829 function requireAdmin(ctx: Ctx): Response | undefined {
29 if (!ctx.auth.user) return signInFirst(ctx);
30 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
30 if (!signedInPage(ctx, "capacity")) return signInFirst(ctx);
31 if (!adminPage(ctx, "capacity", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
3132 return undefined;
3233 }
3334
src/web/pages/chain.ts +6 −5
@@ -5,6 +5,7 @@
55 * sever. A severed forge says so with the date and nothing is deleted.
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { FAMILY_WORDS } from "../../actions/family_words.ts";
910 import { emptyNote } from "../empty_words.ts";
1011 import { FOLLOW_MODE_REFUSALS, followModeSaid, setFollowMode, severForge, takeForgeCode, takeForgeWords } from "../../actions/follow.ts";
@@ -183,7 +184,7 @@ export async function chainPage(ctx: Ctx): Promise<Response> {
183184 export async function severSubmit(ctx: Ctx): Promise<Response> {
184185 const repo = loadRepo(ctx);
185186 if (!repo) return notFoundPage(ctx);
186 if (!ctx.auth.user) return signInFirst(ctx);
187 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
187188 const form = await readForm(ctx, "rw");
188189 if (form instanceof Response) return form;
189190 const to = `${repoBase(repo)}/following`;
@@ -202,7 +203,7 @@ export async function severSubmit(ctx: Ctx): Promise<Response> {
202203 export async function checkSubmit(ctx: Ctx): Promise<Response> {
203204 const repo = loadRepo(ctx);
204205 if (!repo) return notFoundPage(ctx);
205 if (!ctx.auth.user) return signInFirst(ctx);
206 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
206207 const form = await readForm(ctx, "rw");
207208 if (form instanceof Response) return form;
208209 const to = `${repoBase(repo)}/following`;
@@ -217,7 +218,7 @@ export async function checkSubmit(ctx: Ctx): Promise<Response> {
217218 export async function takeSubmit(ctx: Ctx): Promise<Response> {
218219 const repo = loadRepo(ctx);
219220 if (!repo) return notFoundPage(ctx);
220 if (!ctx.auth.user) return signInFirst(ctx);
221 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
221222 const form = await readForm(ctx, "rw");
222223 if (form instanceof Response) return form;
223224 const to = `${repoBase(repo)}/following`;
@@ -237,7 +238,7 @@ export async function takeSubmit(ctx: Ctx): Promise<Response> {
237238 export async function modeSubmit(ctx: Ctx): Promise<Response> {
238239 const repo = loadRepo(ctx);
239240 if (!repo) return notFoundPage(ctx);
240 if (!ctx.auth.user) return signInFirst(ctx);
241 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
241242 const form = await readForm(ctx, "rw");
242243 if (form instanceof Response) return form;
243244 const to = `${repoBase(repo)}/following`;
@@ -253,7 +254,7 @@ export async function modeSubmit(ctx: Ctx): Promise<Response> {
253254 export async function proposeParentSubmit(ctx: Ctx): Promise<Response> {
254255 const repo = loadRepo(ctx);
255256 if (!repo) return notFoundPage(ctx);
256 if (!ctx.auth.user) return signInFirst(ctx);
257 if (!signedInPage(ctx, "chain")) return signInFirst(ctx);
257258 const form = await readForm(ctx, "rw");
258259 if (form instanceof Response) return form;
259260 const to = `${repoBase(repo)}/following`;
src/web/pages/client_cloud.ts +6 −5
@@ -6,6 +6,7 @@
66 * finds no such page. Nothing here is cached, indexed or linked from a public page.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { OFF_SWITCH, attachClientCloud, endClientCloudKey, grantClientCloud, lookAtClientCloud, myClientClouds, type ClientCloudView } from "../../actions/client_cloud.ts";
1011 import { CLIENT_PROVIDERS } from "../../cloud/client_read.ts";
1112 import { KEEP_DAYS, LABEL_MAX } from "../../core/client_cloud.ts";
@@ -52,7 +53,7 @@ function clientCloudsBody(ctx: Ctx): Response {
5253 const user = ctx.auth.user;
5354 if (!user) return signInFirst(ctx);
5455 const mine = myClientClouds(ctx.app, user);
55 if (mine.length === 0 && !user.isAdmin) return notFoundPage(ctx);
56 if (mine.length === 0 && !adminPage(ctx, "client_cloud", user.isAdmin)) return notFoundPage(ctx);
5657 return sealed(
5758 page({
5859 ctx,
@@ -79,7 +80,7 @@ function clientCloudsBody(ctx: Ctx): Response {
7980
8081 // POST /client-clouds
8182 export async function clientCloudAttach(ctx: Ctx): Promise<Response> {
82 if (!ctx.auth.user) return signInFirst(ctx);
83 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
8384 const form = await readForm(ctx, "admin");
8485 if (form instanceof Response) return form;
8586 const r = await attachClientCloud(ctx.app, ctx.auth.user, {
@@ -112,7 +113,7 @@ function seenCard(v: ClientCloudView): Html {
112113
113114 // GET /client-clouds/:id
114115 export async function clientCloudPage(ctx: Ctx): Promise<Response> {
115 if (!ctx.auth.user) return signInFirst(ctx);
116 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
116117 const r = await lookAtClientCloud(ctx.app, ctx.auth.user, ctx.params.id ?? "");
117118 if (!r.ok) return notFoundPage(ctx);
118119 const v = r.value;
@@ -142,7 +143,7 @@ export async function clientCloudPage(ctx: Ctx): Promise<Response> {
142143
143144 // POST /client-clouds/:id/grant
144145 export async function clientCloudGrant(ctx: Ctx): Promise<Response> {
145 if (!ctx.auth.user) return signInFirst(ctx);
146 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
146147 const form = await readForm(ctx, "admin");
147148 if (form instanceof Response) return form;
148149 const id = ctx.params.id ?? "";
@@ -153,7 +154,7 @@ export async function clientCloudGrant(ctx: Ctx): Promise<Response> {
153154
154155 // POST /client-clouds/:id/end
155156 export async function clientCloudEnd(ctx: Ctx): Promise<Response> {
156 if (!ctx.auth.user) return signInFirst(ctx);
157 if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx);
157158 const form = await readForm(ctx, "admin");
158159 if (form instanceof Response) return form;
159160 const id = ctx.params.id ?? "";
src/web/pages/cloud.ts +3 −2
@@ -6,6 +6,7 @@
66 * event. "Write allowed" is off until someone turns it on here.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import type { Database } from "bun:sqlite";
1011 import { sshOn } from "../../settings/ssh.ts";
1112 import {
@@ -51,8 +52,8 @@ import { accountSections } from "./origins.ts";
5152 const BACK = "/settings/cloud";
5253
5354 function requireAdmin(ctx: Ctx): Response | undefined {
54 if (!ctx.auth.user) return signInFirst(ctx);
55 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
55 if (!signedInPage(ctx, "cloud")) return signInFirst(ctx);
56 if (!adminPage(ctx, "cloud", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
5657 return undefined;
5758 }
5859
src/web/pages/config.ts +3 −2
@@ -20,6 +20,7 @@
2020 * its line.
2121 */
2222
23 import { signedInPage } from "../../http/page_may.ts";
2324 import type { Flash } from "../flash.ts";
2425 import { blockedFlash } from "../blocked.ts";
2526 import { FORK_NEEDS_MEMBER, notMemberBlocked } from "../../actions/blocked_words.ts";
@@ -67,7 +68,7 @@ async function commitsDirectly(ctx: Ctx, scope: RepoScope, ref: string): Promise
6768 function configContext(ctx: Ctx, ref: string, path: string): RepoScope | Response {
6869 const repo = loadRepo(ctx);
6970 if (!repo) return notFoundPage(ctx);
70 if (!ctx.auth.user) return signInFirst(ctx);
71 if (!signedInPage(ctx, "config")) return signInFirst(ctx);
7172 if (!isSafeRef(ref) || !isSafeTreePath(path) || !isFormConfig(path)) return notFoundPage(ctx);
7273 const scope = localScope(ctx, repo);
7374 // A mirror you cannot push to proposes through its origin: the source editor's card.
@@ -264,7 +265,7 @@ export async function configSubmit(ctx: Ctx): Promise<Response> {
264265 // Who may write is settled before the body is read: a private repository
265266 // answers a stranger 404, as every page about it does.
266267 if (!loadRepo(ctx)) return notFoundPage(ctx);
267 if (!ctx.auth.user) return signInFirst(ctx);
268 if (!signedInPage(ctx, "config")) return signInFirst(ctx);
268269 const form = await readForm(ctx, "rw");
269270 if (form instanceof Response) return form;
270271 const ref = formValue(form, "ref");
src/web/pages/connections.ts +2 −1
@@ -34,6 +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";
3738
3839 const BACK = "/settings/model";
3940
@@ -212,7 +213,7 @@ export async function connectionRetest(ctx: Ctx): Promise<Response> {
212213 const form = await readForm(ctx, "admin");
213214 if (form instanceof Response) return form;
214215 const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? "");
215 if (c === undefined || (c.scope === "forge" && !user.isAdmin))
216 if (c === undefined || (c.scope === "forge" && !adminPage(ctx, "connections", user.isAdmin)))
216217 return notFoundPage(ctx);
217218 const test = await retestConnection(ctx.app, user, c.id);
218219 if (test === "busy") return flashTo(ctx, BACK, { tone: "danger", message: CONNECTION_REFUSED["busy"]! });
src/web/pages/crew-settings.ts +2 −1
@@ -16,6 +16,7 @@ import { field } from "../form.ts";
1616 import { flashTo, redirect } from "../layout.ts";
1717 import { adminForm } from "../admin_form.ts";
1818 import { saveGrants } from "./subscriptions.ts";
19 import { adminPage } from "../../http/page_may.ts";
1920
2021 // GET /:owner/:name/settings/crew
2122 export function crewSettingsPage(ctx: Ctx): Response {
@@ -29,7 +30,7 @@ export async function crewSubscriptionsSave(ctx: Ctx): Promise<Response> {
2930 const gate = await adminForm(ctx);
3031 if (gate instanceof Response) return gate;
3132 const { repo, form } = gate;
32 if (ctx.auth.user?.isAdmin !== true) return repoNotFound(ctx);
33 if (!adminPage(ctx, "crew-settings", ctx.auth.user?.isAdmin === true)) return repoNotFound(ctx);
3334 const crew = listCrew(ctx.app, ctx.auth.user, repo);
3435 saveGrants(ctx, form, repo.id, crew.ok ? crew.value : []);
3536 return flashTo(ctx, `${repoBase(repo)}/settings#crew`, {
src/web/pages/crew.ts +3 −2
@@ -6,6 +6,7 @@
66 * the crew is actually there, in words, before anyone assigns anything.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { memberRecords, type MemberRecord } from "../../crew/member_record.ts";
1011 import { crewTop, TOP_HELP } from "../crew_top.ts";
1112 import { sshOn } from "../../settings/ssh.ts";
@@ -96,8 +97,8 @@ import { forgeCeiling } from "../../flow/ceiling.ts";
9697
9798 /** The admin, or the response that turns everyone else away. */
9899 function requireAdmin(ctx: Ctx): Response | undefined {
99 if (!ctx.auth.user) return signInFirst(ctx);
100 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
100 if (!signedInPage(ctx, "crew")) return signInFirst(ctx);
101 if (!adminPage(ctx, "crew", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
101102 return undefined;
102103 }
103104
src/web/pages/data.ts +2 −1
@@ -21,6 +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";
2425
2526 const PURPOSE = "Every SQLite file you may read; secrets are masked.";
2627
@@ -61,7 +62,7 @@ export async function adminDataPage(ctx: Ctx): Promise<Response> {
6162 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
6263 const viewer = ctx.auth.user;
6364 if (!viewer) return signInFirst(ctx);
64 if (!viewer.isAdmin) return refuse(ctx);
65 if (!adminPage(ctx, "data", viewer.isAdmin)) return refuse(ctx);
6566 const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.kind === "forge");
6667 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." }));
6768 }
src/web/pages/dataset.ts +3 −2
@@ -5,6 +5,7 @@
55 * so the page stays quick on a forge with a long history.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
89 import { datasetAnswers as answers, lastExport } from "../../actions/dataset.ts";
910 import { datasetStats } from "../../core/dataset.ts";
1011 import type { Ctx } from "../../http/context.ts";
@@ -23,8 +24,8 @@ const usd = (n: number): string => `$${n.toFixed(2)}`;
2324 export function datasetPage(ctx: Ctx): Response {
2425 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2526 const rendering = performance.now();
26 if (!ctx.auth.user) return signInFirst(ctx);
27 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
27 if (!signedInPage(ctx, "dataset")) return signInFirst(ctx);
28 if (!adminPage(ctx, "dataset", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
2829 const stats = datasetStats(ctx.app.db);
2930 const last = lastExport(ctx.app);
3031 const a = answers(ctx.app.db);
src/web/pages/economics.ts +3 −2
@@ -13,6 +13,7 @@
1313 * Anyone else gets the not-found page.
1414 */
1515
16 import { adminPage, signedInPage } from "../../http/page_may.ts";
1617 import { sshOn } from "../../settings/ssh.ts";
1718 import { emptyNote } from "../empty_words.ts";
1819 import { ECONOMICS_WORDS, changeEconomics, readEconomics } from "../../actions/economics.ts";
@@ -32,7 +33,7 @@ const PATH = "/settings/economics";
3233 // GET /settings/economics
3334 export function economicsPage(ctx: Ctx): Response {
3435 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
35 if (!ctx.auth.user) return signInFirst(ctx);
36 if (!signedInPage(ctx, "economics")) return signInFirst(ctx);
3637 const read = timePhase(ctx.request, "economics", () => readEconomics(ctx.app, ctx.auth.user));
3738 if (!read.ok) return notFoundPage(ctx);
3839 const rendering = performance.now();
@@ -175,7 +176,7 @@ export function economicsPage(ctx: Ctx): Response {
175176 // POST /settings/economics
176177 export async function economicsSet(ctx: Ctx): Promise<Response> {
177178 // Checked before the body is read: a non-admin learns nothing of the door.
178 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
179 if (!adminPage(ctx, "economics", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
179180 const form = await readForm(ctx, "admin");
180181 if (form instanceof Response) return form;
181182 // A field the posted form does not carry is left undefined: kept as it stands.
src/web/pages/edit.ts +5 −4
@@ -17,6 +17,7 @@
1717 * preview are `editorJs`, and none of them is load-bearing.
1818 */
1919
20 import { signedInPage } from "../../http/page_may.ts";
2021 import { binaryRefusal } from "../render/opens_with.ts";
2122 import { fileKind, NO_BYTES } from "../render/kinds.ts";
2223 import { editFiles, fileAt, MAX_FILE_BYTES } from "../../actions/contents.ts";
@@ -651,7 +652,7 @@ const isMarkdownPath = (path: string): boolean =>
651652 function editContext(ctx: Ctx): { scope: RepoScope; ref: string } | Response {
652653 const repo = loadRepo(ctx);
653654 if (!repo) return notFoundPage(ctx);
654 if (!ctx.auth.user) return signInFirst(ctx);
655 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
655656 const scope = localScope(ctx, repo);
656657 // A reader may not change it; a fork is how they propose. Someone who cannot read never got here.
657658 if (!scope.caps.write) return cannotChangePage(ctx, scope, repo);
@@ -963,7 +964,7 @@ export async function runContribute(
963964 export async function contributeSubmit(ctx: Ctx): Promise<Response> {
964965 const repo = loadRepo(ctx);
965966 if (!repo) return notFoundPage(ctx);
966 if (!ctx.auth.user) return signInFirst(ctx);
967 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
967968 const form = await readForm(ctx, "rw");
968969 if (form instanceof Response) return form;
969970 const scope = localScope(ctx, repo);
@@ -1105,7 +1106,7 @@ async function dxfSubmit(ctx: Ctx, scope: RepoScope, repo: Repo, form: Form): Pr
11051106 export async function editSubmit(ctx: Ctx): Promise<Response> {
11061107 const repo = loadRepo(ctx);
11071108 if (!repo) return notFoundPage(ctx);
1108 if (!ctx.auth.user) return signInFirst(ctx);
1109 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
11091110 const form = await readForm(ctx, "rw");
11101111 if (form instanceof Response) return form;
11111112 const scope = localScope(ctx, repo);
@@ -1296,7 +1297,7 @@ export async function deleteFilePage(ctx: Ctx): Promise<Response> {
12961297 export async function deleteFileSubmit(ctx: Ctx): Promise<Response> {
12971298 const repo = loadRepo(ctx);
12981299 if (!repo) return notFoundPage(ctx);
1299 if (!ctx.auth.user) return signInFirst(ctx);
1300 if (!signedInPage(ctx, "edit")) return signInFirst(ctx);
13001301 const form = await readForm(ctx, "rw");
13011302 if (form instanceof Response) return form;
13021303 const scope = localScope(ctx, repo);
src/web/pages/everyday.ts +4 −3
@@ -40,6 +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";
4344
4445 const USERNAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/;
4546
@@ -166,7 +167,7 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> {
166167 const admin = ctx.auth.user;
167168 if (!admin) return refuse(401, "Sign in first.");
168169 if (ctx.auth.via !== "session") return refuse(403, "Passkeys are made from a signed-in browser.");
169 if (!admin.isAdmin) return refuse(403, NOT_ADMIN_HERE);
170 if (!adminPage(ctx, "everyday", admin.isAdmin)) return refuse(403, NOT_ADMIN_HERE);
170171 if (everydayOf(ctx.app.db, admin) !== undefined)
171172 return refuse(409, "You already have an everyday account.");
172173 const data = await boundedBody(ctx.request, STRANGER_MAX);
@@ -184,7 +185,7 @@ export async function everydayCreate(ctx: Ctx): Promise<Response> {
184185 if (!admin) return signInFirst(ctx);
185186 const form = await readForm(ctx, "admin");
186187 if (form instanceof Response) return form;
187 if (!admin.isAdmin) return forbiddenPage(ctx, NOT_ADMIN_HERE);
188 if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
188189 const existing = everydayOf(ctx.app.db, admin);
189190 if (existing !== undefined)
190191 return flashTo(ctx, "/settings", {
@@ -252,7 +253,7 @@ export async function everydayKeep(ctx: Ctx): Promise<Response> {
252253 if (!admin) return signInFirst(ctx);
253254 const form = await readForm(ctx, "admin");
254255 if (form instanceof Response) return form;
255 if (!admin.isAdmin) return forbiddenPage(ctx, NOT_ADMIN_HERE);
256 if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE);
256257 keepAdmin(ctx.app.db, admin);
257258 return flashTo(ctx, "/", {
258259 message:
src/web/pages/features.ts +3 −2
@@ -6,6 +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";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { upstreamBlob } from "../../core/upstream.ts";
1112 import {
@@ -39,8 +40,8 @@ import { badge, btn, empty, row, time } from "../ui.ts";
3940 import { accountSections } from "./origins.ts";
4041
4142 function requireAdmin(ctx: Ctx): Response | undefined {
42 if (!ctx.auth.user) return signInFirst(ctx);
43 if (!ctx.auth.user.isAdmin || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
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);
4445 return undefined;
4546 }
4647
src/web/pages/first.ts +2 −1
@@ -1,4 +1,5 @@
11 /** POST /:owner/:name/issues/:number/first — a writer puts a ready issue first (#7808). */
2 import { signedInPage } from "../../http/page_may.ts";
23 import { putIssueFirst } from "../../actions/first.ts";
34 import type { Ctx } from "../../http/context.ts";
45 import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts";
@@ -8,7 +9,7 @@ import { flashOrJson } from "../layout.ts";
89 export async function firstSubmit(ctx: Ctx): Promise<Response> {
910 const repo = loadRepo(ctx);
1011 if (!repo) return notFoundPage(ctx);
11 if (!ctx.auth.user) return signInFirst(ctx);
12 if (!signedInPage(ctx, "first")) return signInFirst(ctx);
1213 const form = await readForm(ctx, "rw");
1314 if (form instanceof Response) return form;
1415 const dest = backTo(form, `${repoBase(repo)}/map`);
src/web/pages/fleet-ops.ts +4 −3
@@ -6,6 +6,7 @@
66 * is same-origin (`readForm`), and only a signed-in person acts.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import {
1011 applyPreviewed,
1112 getFleetOp,
@@ -25,7 +26,7 @@ import { canAct, renderFleet } from "./fleet.ts";
2526
2627 /** POST /fleet */
2728 export async function fleetAct(ctx: Ctx): Promise<Response> {
28 if (!ctx.auth.user) return signInFirst(ctx);
29 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
2930 if (!canAct(ctx)) return notFoundPage(ctx);
3031 const form = await readForm(ctx, "rw");
3132 if (form instanceof Response) return form;
@@ -90,7 +91,7 @@ function refusal(
9091
9192 /** GET /fleet/ops/:id */
9293 export function fleetReceipt(ctx: Ctx): Response {
93 if (!ctx.auth.user) return signInFirst(ctx);
94 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
9495 const found = getFleetOp(ctx.app, ctx.auth.user, ctx.params.id ?? "");
9596 if (!found.ok) return notFoundPage(ctx);
9697 const op = found.value;
@@ -107,7 +108,7 @@ export function fleetReceipt(ctx: Ctx): Response {
107108
108109 /** POST /fleet/ops/:id/undo */
109110 export async function fleetUndo(ctx: Ctx): Promise<Response> {
110 if (!ctx.auth.user) return signInFirst(ctx);
111 if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx);
111112 if (!canAct(ctx)) return notFoundPage(ctx);
112113 const form = await readForm(ctx, "rw");
113114 if (form instanceof Response) return form;
src/web/pages/flow.ts +5 −4
@@ -14,6 +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";
1718 import { retryBackup } from "../../actions/backup_retry.ts";
1819 import { alarmBackup, type BackupAlarm } from "../../flow/alarm_backup.ts";
1920 import { acceptSuggestion, turnValveFor, type ValveError } from "../../actions/valves.ts";
@@ -160,7 +161,7 @@ export async function flowPage(ctx: Ctx): Promise<Response> {
160161 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
161162 const user = ctx.auth.user;
162163 if (user === undefined) return signInFirst(ctx);
163 if (!user.isAdmin || user.kind === "agent") return notFoundPage(ctx);
164 if (!adminPage(ctx, "flow", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx);
164165 // What a "Reading…" page asks: it answers when the worker has the picture, and draws nothing.
165166 if (waiting) {
166167 return waitAnswer(await flowPicture(ctx.app, user.id, LONG_WAIT_MS));
@@ -241,7 +242,7 @@ function done(ctx: Ctx, result: ReturnType<typeof turnValveFor>): Response {
241242
242243 // POST /flow/valve
243244 export async function valveSet(ctx: Ctx): Promise<Response> {
244 if (!ctx.auth.user) return signInFirst(ctx);
245 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
245246 const form = await readForm(ctx, "admin");
246247 if (form instanceof Response) return form;
247248 return done(ctx, turnValveFor(ctx.app, ctx.auth.user, field(form, "repo"), field(form, "level")));
@@ -249,7 +250,7 @@ export async function valveSet(ctx: Ctx): Promise<Response> {
249250
250251 // POST /flow/suggestion
251252 export async function suggestionTake(ctx: Ctx): Promise<Response> {
252 if (!ctx.auth.user) return signInFirst(ctx);
253 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
253254 const form = await readForm(ctx, "admin");
254255 if (form instanceof Response) return form;
255256 return done(ctx, acceptSuggestion(ctx.app, ctx.auth.user, field(form, "repo")));
@@ -257,7 +258,7 @@ export async function suggestionTake(ctx: Ctx): Promise<Response> {
257258
258259 // POST /flow/backup/retry: one snapshot now, through the service's own queue, so two never run at once.
259260 export async function backupRetry(ctx: Ctx): Promise<Response> {
260 if (!ctx.auth.user) return signInFirst(ctx);
261 if (!signedInPage(ctx, "flow")) return signInFirst(ctx);
261262 const form = await readForm(ctx, "admin");
262263 if (form instanceof Response) return form;
263264 const retried = await retryBackup(ctx.app, ctx.auth.user);
src/web/pages/flows-all.ts +2 −1
@@ -15,6 +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";
1819
1920 /** Lines drawn at once; the count above says how many matched. */
2021 const SHOWN = 500;
@@ -25,7 +26,7 @@ const TONE: Record<Health, Tone> = { ok: "default", behind: "attn", diverged: "d
2526 export function allFlowsPage(ctx: Ctx): Response {
2627 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2728 const user = ctx.auth.user;
28 if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx);
29 if (!adminPage(ctx, "flows", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx);
2930 const q = new URL(ctx.request.url).searchParams;
3031 const kind = parseKind(q.get("kind"));
3132 const stale = q.get("stale") === "1";
src/web/pages/following.ts +2 −1
@@ -10,6 +10,7 @@
1010 * — it becomes the crew's proposal, or an honest sentence about why not.
1111 */
1212
13 import { signedInPage } from "../../http/page_may.ts";
1314 import {
1415 relationOf,
1516 type ForkRelation,
@@ -602,7 +603,7 @@ export function followingCard(
602603 export async function followingSubmit(ctx: Ctx): Promise<Response> {
603604 const repo = loadRepo(ctx);
604605 if (!repo) return notFoundPage(ctx);
605 if (!ctx.auth.user) return signInFirst(ctx);
606 if (!signedInPage(ctx, "following")) return signInFirst(ctx);
606607 const form = await readForm(ctx, "rw");
607608 if (form instanceof Response) return form;
608609 const base = repoBase(repo);
src/web/pages/forge_machine.ts +3 −2
@@ -16,6 +16,7 @@ import { readForm } from "../form.ts";
1616 import { html } from "../html.ts";
1717 import { page } from "../layout.ts";
1818 import { btn } from "../ui.ts";
19 import { adminPage } from "../../http/page_may.ts";
1920
2021 const back = (name: string) => btn("Back to your forges", { href: `/forges#forge-${name}`, size: "sm" });
2122
@@ -29,7 +30,7 @@ const choose = (name: string, machines: readonly string[], recover: boolean) =>
2930
3031 export async function forgeMachineForm(ctx: Ctx): Promise<Response> {
3132 const user = ctx.auth.user;
32 if (!user?.isAdmin) return notFoundPage(ctx);
33 if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx);
3334 const name = ctx.params["name"] ?? "";
3435 const to = ctx.url.searchParams.get("to") ?? "";
3536 const recover = ctx.url.searchParams.get("recover") === "1";
@@ -57,7 +58,7 @@ export async function forgeMachineForm(ctx: Ctx): Promise<Response> {
5758
5859 export async function forgeMachineSubmit(ctx: Ctx): Promise<Response> {
5960 const user = ctx.auth.user;
60 if (!user?.isAdmin) return notFoundPage(ctx);
61 if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx);
6162 const form = await readForm(ctx, "admin");
6263 if (form instanceof Response) return form;
6364 const name = ctx.params["name"] ?? "";
src/web/pages/forge_move_in.ts +3 −2
@@ -16,6 +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";
1920
2021 const wrap = (title: string, body: Html) =>
2122 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>`;
@@ -27,7 +28,7 @@ const done = (response: Response): Response => {
2728
2829 export function forgeMoveInForm(ctx: Ctx): Response {
2930 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
30 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
31 if (!adminPage(ctx, "forge_move_in", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
3132 const rendering = performance.now();
3233 const cost = moveInCost();
3334 const body = html`<dl class="status-rows" data-preview>${cost.rows.map(([label, value]) => statusRow(label, html`${value}`))}</dl>
@@ -45,7 +46,7 @@ export function forgeMoveInForm(ctx: Ctx): Response {
4546
4647 export async function forgeMoveInSubmit(ctx: Ctx): Promise<Response> {
4748 const user = ctx.auth.user;
48 if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx);
49 if (!adminPage(ctx, "forge_move_in", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx);
4950 const form = await readForm(ctx, "admin", BODY_CAPS.moveIn.bytes);
5051 if (form instanceof Response) return form;
5152 const name = String(form.get("name") ?? "").trim().toLowerCase();
src/web/pages/forge_upgrade.ts +3 −2
@@ -15,6 +15,7 @@ import { html, type Html } from "../html.ts";
1515 import { page } from "../layout.ts";
1616 import { btn, selectField } from "../ui.ts";
1717 import { statusRow } from "./security.ts";
18 import { adminPage } from "../../http/page_may.ts";
1819
1920 const back = (name: string) => btn("Back to your forges", { href: `/forges#forge-${name}`, size: "sm" });
2021
@@ -23,7 +24,7 @@ const wrap = (name: string, body: Html) =>
2324
2425 export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> {
2526 const user = ctx.auth.user;
26 if (!user?.isAdmin) return notFoundPage(ctx);
27 if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx);
2728 const name = ctx.params["name"] ?? "";
2829 const plan = ctx.url.searchParams.get("plan") ?? "";
2930 const to = ctx.url.searchParams.get("to") ?? "";
@@ -52,7 +53,7 @@ export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> {
5253
5354 export async function forgeUpgradeSubmit(ctx: Ctx): Promise<Response> {
5455 const user = ctx.auth.user;
55 if (!user?.isAdmin) return notFoundPage(ctx);
56 if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx);
5657 const form = await readForm(ctx, "admin");
5758 if (form instanceof Response) return form;
5859 const name = ctx.params["name"] ?? "";
src/web/pages/forges.ts +13 −12
@@ -49,6 +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";
5253
5354
5455 /** "3 apps running", or which one is not and why. */
@@ -261,7 +262,7 @@ function refusedLink(ctx: Ctx): Html | null {
261262 // GET /forges/export.csv — the client list as a download, behind the page's own gate (a missing
262263 // page to anyone else).
263264 export async function forgesCsv(ctx: Ctx): Promise<Response> {
264 if (!ctx.auth.user?.isAdmin) return notFoundPage(ctx);
265 if (!adminPage(ctx, "forges", ctx.auth.user?.isAdmin === true)) return notFoundPage(ctx);
265266 const rows = sortForges(await servedRows(ctx.app), "attention");
266267 return new Response(clientsCsv(rows), {
267268 headers: {
@@ -276,7 +277,7 @@ export async function forgesCsv(ctx: Ctx): Promise<Response> {
276277 // GET /forges — an admin's only.
277278 export async function forgesPage(ctx: Ctx): Promise<Response> {
278279 const user = ctx.auth.user;
279 if (!user?.isAdmin) return notFoundPage(ctx);
280 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
280281 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
281282 const asked = ctx.url.searchParams.get("sort");
282283 const sort: ForgeSort = isForgeSort(asked) ? asked : "attention";
@@ -390,7 +391,7 @@ export async function forgeLinkForm(ctx: Ctx): Promise<Response> {
390391 // does it; nothing changes until it is pressed (#14518).
391392 export async function forgeRevokeConfirm(ctx: Ctx): Promise<Response> {
392393 const user = ctx.auth.user;
393 if (!user?.isAdmin) return notFoundPage(ctx);
394 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
394395 const name = ctx.params["name"] ?? "";
395396 if (!CHILD_NAME.test(name)) return notFoundPage(ctx);
396397 const response = page({
@@ -443,7 +444,7 @@ async function namedForges(ctx: Ctx, wanted: readonly string[]): Promise<string[
443444 // that does it.
444445 export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> {
445446 const user = ctx.auth.user;
446 if (!user?.isAdmin) return notFoundPage(ctx);
447 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
447448 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
448449 const names = await namedForges(ctx, ctx.url.searchParams.getAll("name"));
449450 const rows = (await servedRows(ctx.app)).filter((r) => names.includes(r.name));
@@ -477,7 +478,7 @@ export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> {
477478 // POST /forges/archive — archive each named forge, one after another; the receipt says each result.
478479 export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> {
479480 const user = ctx.auth.user;
480 if (!user?.isAdmin) return notFoundPage(ctx);
481 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
481482 const form = await readForm(ctx, "admin");
482483 if (form instanceof Response) return form;
483484 const names = await namedForges(ctx, form.getAll("name").filter((v): v is string => typeof v === "string"));
@@ -489,7 +490,7 @@ export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> {
489490 // POST /forges/:name/restore — bring an archived forge back under its name.
490491 export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> {
491492 const user = ctx.auth.user;
492 if (!user?.isAdmin) return notFoundPage(ctx);
493 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
493494 const form = await readForm(ctx, "admin");
494495 if (form instanceof Response) return form;
495496 const done = await restoreForge(ctx.app, ctx.params["name"] ?? "", { actorId: user.id });
@@ -554,7 +555,7 @@ function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null {
554555 function linkChange(act: "revoke" | "undo") {
555556 return async (ctx: Ctx): Promise<Response> => {
556557 const user = ctx.auth.user;
557 if (!user?.isAdmin) return notFoundPage(ctx);
558 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
558559 const form = await readForm(ctx, "admin");
559560 if (form instanceof Response) return form;
560561 const name = ctx.params["name"] ?? "";
@@ -571,7 +572,7 @@ export const forgeLinkUndo = linkChange("undo");
571572 function manageSubmit(act: (app: Ctx["app"], name: string) => Promise<Managed>, title: string) {
572573 return async (ctx: Ctx): Promise<Response> => {
573574 const user = ctx.auth.user;
574 if (!user?.isAdmin) return notFoundPage(ctx);
575 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
575576 const form = await readForm(ctx, "admin");
576577 if (form instanceof Response) return form;
577578 const done = await act(ctx.app, ctx.params["name"] ?? "");
@@ -599,7 +600,7 @@ export const forgeStopSubmit = manageSubmit(stopForge, "Forge stopped");
599600 // own (`spawn/move_cell.ts`).
600601 export async function forgeSandboxSubmit(ctx: Ctx): Promise<Response> {
601602 const user = ctx.auth.user;
602 if (!user?.isAdmin) return notFoundPage(ctx);
603 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
603604 const form = await readForm(ctx, "admin");
604605 if (form instanceof Response) return form;
605606 const name = ctx.params["name"] ?? "";
@@ -627,7 +628,7 @@ export const forgeRemoveSubmit = manageSubmit(removeForge, "Forge removed");
627628 // GET /forges/:name/remove — what removing would delete, and the one button that does it.
628629 export async function forgeRemoveConfirm(ctx: Ctx): Promise<Response> {
629630 const user = ctx.auth.user;
630 if (!user?.isAdmin) return notFoundPage(ctx);
631 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
631632 const name = ctx.params["name"] ?? "";
632633 const child = (await listChildren(ctx.app)).find((c) => c.name === name);
633634 if (child === undefined) return notFoundPage(ctx);
@@ -702,7 +703,7 @@ async function ownCodeSection(ctx: Ctx): Promise<Html | null> {
702703 // with a receipt.
703704 export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> {
704705 const user = ctx.auth.user;
705 if (!user?.isAdmin) return notFoundPage(ctx);
706 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
706707 const form = await readForm(ctx, "admin");
707708 if (form instanceof Response) return form;
708709 const want = form.get("on");
@@ -716,7 +717,7 @@ export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> {
716717 // POST /forges/:name/size — raise a forge to a larger size (xlarge); a receipt on the list.
717718 export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> {
718719 const user = ctx.auth.user;
719 if (!user?.isAdmin) return notFoundPage(ctx);
720 if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx);
720721 const form = await readForm(ctx, "admin");
721722 if (form instanceof Response) return form;
722723 const name = ctx.params["name"] ?? "";
src/web/pages/games.ts +5 −4
@@ -7,6 +7,7 @@
77 * the box's compose repository, so a merge redeploys and the crew can propose them too.
88 */
99
10 import { signedInPage } from "../../http/page_may.ts";
1011 import { cancelHeld, heldOf, holdUntilQuiet, QUIET_MINUTES } from "../../games/when_quiet.ts";
1112 import { addPluginUrl, commitServiceEnv, composeServices, readCompose, serviceEnv } from "../../games/compose.ts";
1213 import { verdictsOf } from "../../games/set_verdict.ts";
@@ -165,7 +166,7 @@ export async function gameServersSubmit(ctx: Ctx): Promise<Response> {
165166 }
166167
167168 export function boxOf(ctx: Ctx, need: Role, service = ""): { box: GameBox; role: Role } | Response {
168 if (!ctx.auth.user) return signInFirst(ctx);
169 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
169170 const box = boxNamed(ctx.app.db, ctx.params.box ?? "");
170171 if (box === undefined || !seesBox(ctx.app.db, ctx.auth.user, box.id)) return notFoundPage(ctx);
171172 const role = roleOn(ctx.app.db, ctx.auth.user, box.id, service);
@@ -184,7 +185,7 @@ const startBox = (): Html => html`<form method="post" action="/talk" class="mt">
184185 // GET /games
185186 export function gamesPage(ctx: Ctx): Response {
186187 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
187 if (!ctx.auth.user) return signInFirst(ctx);
188 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
188189 const user = ctx.auth.user;
189190 const boxes = listBoxes(ctx.app.db).filter((b) => seesBox(ctx.app.db, user, b.id));
190191 return timePhase(ctx.request, "render", () => page({
@@ -212,7 +213,7 @@ export function gamesPage(ctx: Ctx): Response {
212213 // POST /settings/minecraft/code: a one-time code (ten minutes) the person types in game as !forge
213214 // link <code>.
214215 export async function gameLinkCode(ctx: Ctx): Promise<Response> {
215 if (!ctx.auth.user) return signInFirst(ctx);
216 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
216217 const form = await readForm(ctx, "rw");
217218 if (form instanceof Response) return form;
218219 const code = newLinkCode(ctx.app, ctx.auth.user);
@@ -222,7 +223,7 @@ export async function gameLinkCode(ctx: Ctx): Promise<Response> {
222223
223224 // POST /settings/minecraft/unlink: forget one of the person's linked names.
224225 export async function gameLinkRemove(ctx: Ctx): Promise<Response> {
225 if (!ctx.auth.user) return signInFirst(ctx);
226 if (!signedInPage(ctx, "games")) return signInFirst(ctx);
226227 const form = await readForm(ctx, "rw");
227228 if (form instanceof Response) return form;
228229 unlink(ctx.app, ctx.auth.user.id, field(form, "box"), field(form, "player"));
src/web/pages/gate.ts +3 −2
@@ -4,6 +4,7 @@
44 * acting is `actions/gate.ts`.
55 */
66
7 import { signedInPage } from "../../http/page_may.ts";
78 import { applyGateReview, reviewGate } from "../../actions/gate_review.ts";
89 import { liftHold } from "../../actions/gate.ts";
910 import { BAD_DATE, REVIVE_UNTIL } from "../../core/gate_snooze.ts";
@@ -71,7 +72,7 @@ export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null {
7172 export async function liftHoldSubmit(ctx: Ctx): Promise<Response> {
7273 const found = threadContext(ctx, "issue");
7374 if (found instanceof Response) return found;
74 if (!ctx.auth.user) return signInFirst(ctx);
75 if (!signedInPage(ctx, "gate")) return signInFirst(ctx);
7576 const form = await readForm(ctx, "rw");
7677 if (form instanceof Response) return form;
7778 const repo = loadRepo(ctx) ?? found.repo;
@@ -222,7 +223,7 @@ export function heldPage(ctx: Ctx): Response {
222223 export async function heldApply(ctx: Ctx): Promise<Response> {
223224 const repo = loadRepo(ctx);
224225 if (!repo) return notFoundPage(ctx);
225 if (!ctx.auth.user) return signInFirst(ctx);
226 if (!signedInPage(ctx, "gate")) return signInFirst(ctx);
226227 const form = await readForm(ctx, "rw");
227228 if (form instanceof Response) return form;
228229 const dest = `${repoBase(repo)}/held`;
src/web/pages/gifts.ts +2 −1
@@ -5,6 +5,7 @@
55 * who is not a subscriber sees no block, and the POST answers not found.
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { GIFT_WORDS, giveGift, readGifts } from "../../actions/gifts.ts";
910 import { publicOrigin } from "../../core/public_origin.ts";
1011 import type { Ctx } from "../../http/context.ts";
@@ -51,7 +52,7 @@ export function giftsBlock(ctx: Ctx, shown?: Shown, refusal?: string): Html | nu
5152
5253 // POST /settings/gifts
5354 export async function giftMake(ctx: Ctx): Promise<Response> {
54 if (!ctx.auth.user) return signInFirst(ctx);
55 if (!signedInPage(ctx, "gifts")) return signInFirst(ctx);
5556 const form = await readForm(ctx);
5657 if (form instanceof Response) return form;
5758 const made = giveGift(ctx.app, ctx.auth.user, publicOrigin(ctx.app.config.url, ctx.url.origin));
src/web/pages/grants.ts +3 −2
@@ -7,6 +7,7 @@
77 * rows and the gate are `actions/oauth_grants.ts`, which the terminal's
88 * `screens/oauthgrants.ts` shares.
99 */
10 import { signedInPage } from "../../http/page_may.ts";
1011 import { myOAuthGrants, myReusedGrants, revokeOAuthGrant, revokedWords } from "../../actions/oauth_grants.ts";
1112 import { emptyNote } from "../empty_words.ts";
1213 import type { OAuthGrant, ReusedGrant } from "../../core/oauth_grants.ts";
@@ -75,7 +76,7 @@ function grantsView(grants: readonly OAuthGrant[], reused: readonly ReusedGrant[
7576
7677 // GET /settings/grants
7778 export function grantsPage(ctx: Ctx): Response {
78 if (!ctx.auth.user) return signInFirst(ctx);
79 if (!signedInPage(ctx, "grants")) return signInFirst(ctx);
7980 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
8081 const grants = timePhase(ctx.request, "grants", () => myOAuthGrants(ctx.app, ctx.auth.user));
8182 const reused = myReusedGrants(ctx.app, ctx.auth.user);
@@ -86,7 +87,7 @@ export function grantsPage(ctx: Ctx): Response {
8687
8788 // POST /settings/grants/:id/revoke
8889 export async function grantRevoke(ctx: Ctx): Promise<Response> {
89 if (!ctx.auth.user) return signInFirst(ctx);
90 if (!signedInPage(ctx, "grants")) return signInFirst(ctx);
9091 const form = await readForm(ctx, "admin");
9192 if (form instanceof Response) return form;
9293 const revoked = revokeOAuthGrant(ctx.app, ctx.auth.user, ctx.params.id ?? "");
src/web/pages/hosted-forges.ts +3 −2
@@ -11,6 +11,7 @@
1111 * `REACH_SETTINGS`, the section's own anchor.
1212 */
1313
14 import { adminPage, signedInPage } from "../../http/page_may.ts";
1415 import { sshOn } from "../../settings/ssh.ts";
1516 import {
1617 allowReach,
@@ -119,8 +120,8 @@ export function forgeReachRows(
119120 }
120121
121122 function requireAdmin(ctx: Ctx): Response | undefined {
122 if (!ctx.auth.user) return signInFirst(ctx);
123 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
123 if (!signedInPage(ctx, "hosted-forges")) return signInFirst(ctx);
124 if (!adminPage(ctx, "hosted-forges", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
124125 return undefined;
125126 }
126127
src/web/pages/identities.ts +3 −2
@@ -7,6 +7,7 @@
77 * for a tick first: removing it puts the account back behind the email gate.
88 */
99
10 import { signedInPage } from "../../http/page_may.ts";
1011 import { sshOn } from "../../settings/ssh.ts";
1112 import {
1213 CONNECTION_WORDS, MINECRAFT_PROOF, NOT_RETROACTIVE, SIGN_IN_ADDRESS, addConnection, addMinecraftConnection, chooseUse,
@@ -66,7 +67,7 @@ const card = (c: Connection): Html => {
6667 // GET /settings/identities
6768 export function identitiesPage(ctx: Ctx): Response {
6869 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
69 if (!ctx.auth.user) return signInFirst(ctx);
70 if (!signedInPage(ctx, "identities")) return signInFirst(ctx);
7071 const list = connectionsOf(ctx.app, ctx.auth.user);
7172 const body = html`<section class="settings-block">
7273 <h2>Proven identities</h2>
@@ -99,7 +100,7 @@ const said = (ctx: Ctx, message: string, ok: boolean): Response =>
99100
100101 /** Read the form as the signed-in account, same-origin; the acts below share it. */
101102 async function acting(ctx: Ctx): Promise<{ form: import("../form.ts").Form } | Response> {
102 if (!ctx.auth.user) return signInFirst(ctx);
103 if (!signedInPage(ctx, "identities")) return signInFirst(ctx);
103104 const form = await readForm(ctx, "admin");
104105 return form instanceof Response ? form : { form };
105106 }
src/web/pages/inventory.ts +2 −1
@@ -6,6 +6,7 @@
66 * The rows are `actions/inventory.ts`'s, the same the MCP answers.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import { holds, inventoryOfOrigins, moveRoom, type InventoryItem } from "../../actions/inventory.ts";
1011 import { listUserOrigins } from "../../actions/origins.ts";
1112 import { MIGRATION_STATES, STATE_WORDS, type MigrationState } from "../../origins/inventory.ts";
@@ -62,7 +63,7 @@ function tally(items: readonly InventoryItem[]): string {
6263 }
6364
6465 export async function inventoryPage(ctx: Ctx): Promise<Response> {
65 if (!ctx.auth.user) return signInFirst(ctx);
66 if (!signedInPage(ctx, "inventory")) return signInFirst(ctx);
6667 const user = ctx.auth.user;
6768 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
6869 const origins = listUserOrigins(ctx.app, user);
src/web/pages/issues.ts +6 −5
@@ -5,6 +5,7 @@
55 * Mobile-first, no JavaScript required.
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { originError } from "../../actions/merge_words.ts";
910 import { comeBack } from "../come_back.ts";
1011 import { CEILING_REFUSAL, PAUSE_REFUSAL } from "../../core/planner_pause.ts";
@@ -249,7 +250,7 @@ export function newIssueAnywhere(ctx: Ctx): Response {
249250 export async function newIssueSubmit(ctx: Ctx): Promise<Response> {
250251 const repo = loadRepo(ctx);
251252 if (!repo) return notFoundPage(ctx);
252 if (!ctx.auth.user) return signInFirst(ctx);
253 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
253254 const form = await readForm(ctx, "rw");
254255 if (form instanceof Response) return form;
255256
@@ -297,7 +298,7 @@ export function issueThreadFragment(ctx: Ctx): Response {
297298 export async function issueSealSubmit(ctx: Ctx): Promise<Response> {
298299 const found = threadContext(ctx, "issue");
299300 if (found instanceof Response) return found;
300 if (!ctx.auth.user) return signInFirst(ctx);
301 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
301302 const form = await readForm(ctx, "rw");
302303 if (form instanceof Response) return form;
303304 const sealed = field(form, "sealed") === "1";
@@ -322,7 +323,7 @@ export async function issueSealSubmit(ctx: Ctx): Promise<Response> {
322323 export async function issuePrivateSubmit(ctx: Ctx): Promise<Response> {
323324 const found = threadContext(ctx, "issue");
324325 if (found instanceof Response) return found;
325 if (!ctx.auth.user) return signInFirst(ctx);
326 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
326327 const form = await readForm(ctx, "rw");
327328 if (form instanceof Response) return form;
328329 const made = await privateRepoForSealed(ctx.app, ctx.auth.user, found.repo, found.issue);
@@ -356,7 +357,7 @@ const BACK = new Map<string, { to: string; said: (n: number) => string }>([
356357 export async function issueCommentSubmit(ctx: Ctx): Promise<Response> {
357358 const found = threadContext(ctx, "issue");
358359 if (found instanceof Response) return found;
359 if (!ctx.auth.user) return signInFirst(ctx);
360 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
360361 const form = await readForm(ctx, "rw");
361362 if (form instanceof Response) return form;
362363
@@ -413,7 +414,7 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> {
413414 export async function issueQuestionSubmit(ctx: Ctx): Promise<Response> {
414415 const found = threadContext(ctx, "issue");
415416 if (found instanceof Response) return found;
416 if (!ctx.auth.user) return signInFirst(ctx);
417 if (!signedInPage(ctx, "issues")) return signInFirst(ctx);
417418 const form = await readForm(ctx, "rw");
418419 if (form instanceof Response) return form;
419420 const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`;
src/web/pages/iterations.ts +2 −1
@@ -13,6 +13,7 @@
1313 * selections) are not on this forge yet.
1414 */
1515
16 import { signedInPage } from "../../http/page_may.ts";
1617 import { notePin } from "../../actions/builds.ts";
1718 import { iterationsOf, lanesOf, type IterationBuild, type IterationFork, type IterationLane } from "../../core/iterations.ts";
1819 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
@@ -583,7 +584,7 @@ const NOTE_ERRORS: Record<string, string> = {
583584 export async function noteSubmit(ctx: Ctx): Promise<Response> {
584585 const repo = loadRepo(ctx);
585586 if (!repo) return notFoundPage(ctx);
586 if (!ctx.auth.user) return signInFirst(ctx);
587 if (!signedInPage(ctx, "iterations")) return signInFirst(ctx);
587588 const form = await readForm(ctx, "rw");
588589 if (form instanceof Response) return form;
589590 const to = backTo(form, `${repoBase(repo)}/iterations`);
src/web/pages/knobs.ts +3 −2
@@ -5,6 +5,7 @@
55 * leaves the event the setting's own page leaves.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
89 import { setKnob } from "../../actions/knobs.ts";
910 import { derivedLine, readKnobs, type KnobRow } from "../../crew/knobs.ts";
1011 import type { Ctx } from "../../http/context.ts";
@@ -50,8 +51,8 @@ export function knobsCard(ctx: Ctx): Html {
5051
5152 // POST /settings/crew/knobs
5253 export async function knobSet(ctx: Ctx): Promise<Response> {
53 if (!ctx.auth.user) return signInFirst(ctx);
54 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
54 if (!signedInPage(ctx, "knobs")) return signInFirst(ctx);
55 if (!adminPage(ctx, "knobs", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
5556 const form = await readForm(ctx, "admin");
5657 if (form instanceof Response) return form;
5758 const knob = field(form, "knob");
src/web/pages/limb.ts +4 −3
@@ -6,6 +6,7 @@
66 * take it back once.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import { isReplanAction } from "../../actions/limb_replan.ts";
1011 import { getFleetOp, undoFleetOp } from "../../actions/fleet.ts";
1112 import {
@@ -152,7 +153,7 @@ export function limbPreviewPage(ctx: Ctx): Response {
152153 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
153154 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
154155 if (!repo) return notFoundPage(ctx);
155 if (!ctx.auth.user) return signInFirst(ctx);
156 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
156157 const number = Number(ctx.params.number);
157158 const action = ctx.url.searchParams.get("action");
158159 if (action === "replan") return replanPreviewPage(ctx, repo, number);
@@ -349,7 +350,7 @@ export function limbPreviewPage(ctx: Ctx): Response {
349350 export async function limbSubmit(ctx: Ctx): Promise<Response> {
350351 const repo = loadRepo(ctx);
351352 if (!repo) return notFoundPage(ctx);
352 if (!ctx.auth.user) return signInFirst(ctx);
353 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
353354 const form = await readForm(ctx, "admin");
354355 if (form instanceof Response) return form;
355356 const number = Number(ctx.params.number);
@@ -439,7 +440,7 @@ export function limbReceiptPage(ctx: Ctx): Response {
439440 export async function limbUndo(ctx: Ctx): Promise<Response> {
440441 const repo = loadRepo(ctx);
441442 if (!repo) return notFoundPage(ctx);
442 if (!ctx.auth.user) return signInFirst(ctx);
443 if (!signedInPage(ctx, "limb")) return signInFirst(ctx);
443444 const form = await readForm(ctx, "admin");
444445 if (form instanceof Response) return form;
445446 const number = Number(ctx.params.number);
src/web/pages/maintenance.ts +7 −6
@@ -4,6 +4,7 @@
44 * once the forge is back, when and what was verified.
55 */
66
7 import { adminPage, signedInPage } from "../../http/page_may.ts";
78 import { json } from "../../http/respond.ts";
89 import { emptyNote } from "../empty_words.ts";
910 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
@@ -41,8 +42,8 @@ import { diskLine } from "../../maintenance/disk_line.ts";
4142 import { readDisk } from "../../kernel/disk_reading.ts";
4243
4344 function admin(ctx: Ctx): Response | undefined {
44 if (!ctx.auth.user) return signInFirst(ctx);
45 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
45 if (!signedInPage(ctx, "maintenance")) return signInFirst(ctx);
46 if (!adminPage(ctx, "maintenance", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
4647 return undefined;
4748 }
4849
@@ -343,7 +344,7 @@ function quietedRows(withActions: boolean, rows: readonly Quieted[]): Html {
343344 function mayQuiet(ctx: Ctx): Response | undefined {
344345 const user = ctx.auth.user;
345346 if (user === undefined) return signInFirst(ctx);
346 if (!user.isAdmin) return notFoundPage(ctx);
347 if (!adminPage(ctx, "maintenance", user.isAdmin)) return notFoundPage(ctx);
347348 if (user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a person may quiet a finding." });
348349 return undefined;
349350 }
@@ -409,7 +410,7 @@ export function stalePullsSection(ctx: Ctx, withActions: boolean): Html {
409410 */
410411 export async function staleAction(ctx: Ctx): Promise<Response> {
411412 const user = ctx.auth.user;
412 if (user === undefined || !user.isAdmin || user.kind === "agent")
413 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
413414 return flashTo(ctx, "/maintenance", { tone: "danger", message: STALE_WORDS.forbidden });
414415 const form = await readForm(ctx, "admin");
415416 if (form instanceof Response) return form;
@@ -441,7 +442,7 @@ function mergedRows(withActions: boolean, found: readonly MergedBranch[]): Html
441442 */
442443 export async function mergedAction(ctx: Ctx): Promise<Response> {
443444 const user = ctx.auth.user;
444 if (user === undefined || !user.isAdmin || user.kind === "agent")
445 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
445446 return flashTo(ctx, "/maintenance", { tone: "danger", message: MERGED_WORDS.forbidden });
446447 const form = await readForm(ctx, "admin");
447448 if (form instanceof Response) return form;
@@ -474,7 +475,7 @@ function previewRows(withActions: boolean, found: readonly PreviewDir[]): Html {
474475 */
475476 export async function previewAction(ctx: Ctx): Promise<Response> {
476477 const user = ctx.auth.user;
477 if (user === undefined || !user.isAdmin || user.kind === "agent")
478 if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent"))
478479 return flashTo(ctx, "/maintenance", { tone: "danger", message: PREVIEW_WORDS.forbidden });
479480 const form = await readForm(ctx, "admin");
480481 if (form instanceof Response) return form;
src/web/pages/migrate.ts +4 −3
@@ -20,6 +20,7 @@
2020 * Every mutation is `migrateRepo`; the page only puts its answer into words.
2121 */
2222
23 import { signedInPage } from "../../http/page_may.ts";
2324 import { USERNAME_PATTERN } from "../username_pattern.ts";
2425 import { repositoryLimitMessage } from "../../actions/repos.ts";
2526 import { listAllAgents } from "../../actions/crew.ts";
@@ -709,7 +710,7 @@ async function show(
709710 // GET /migrate
710711 export async function migratePage(ctx: Ctx): Promise<Response> {
711712 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
712 if (!ctx.auth.user) return signInFirst(ctx);
713 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
713714 const q = ctx.url.searchParams;
714715 const origins = await timePhaseAsync(ctx.request, "origins", () =>
715716 originChoices(ctx),
@@ -758,7 +759,7 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
758759
759760 // POST /migrate
760761 export async function migrateSubmit(ctx: Ctx): Promise<Response> {
761 if (!ctx.auth.user) return signInFirst(ctx);
762 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
762763 const form = await readForm(ctx, "rw");
763764 if (form instanceof Response) return form;
764765 const values: MigrateValues = {
@@ -943,7 +944,7 @@ const migrateJobJs = /* js */ `
943944
944945 export function migrationJobPage(ctx: Ctx): Response {
945946 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
946 if (!ctx.auth.user) return signInFirst(ctx);
947 if (!signedInPage(ctx, "migrate")) return signInFirst(ctx);
947948 const user = ctx.auth.user;
948949 const found = timePhase(ctx.request, "job", () =>
949950 migrationJobFor(user, ctx.params.job ?? ""),
src/web/pages/milestones.ts +2 −1
@@ -10,6 +10,7 @@
1010 * Read-only: the page, the API and the MCP tool give the same numbers.
1111 */
1212
13 import { signedInPage } from "../../http/page_may.ts";
1314 import { issueCounts } from "../../core/milestone_front.ts";
1415 import {
1516 limbJson,
@@ -696,7 +697,7 @@ export async function milestonePage(
696697 export async function milestoneWatch(ctx: Ctx): Promise<Response> {
697698 const repo = loadRepo(ctx);
698699 if (!repo) return notFoundPage(ctx);
699 if (!ctx.auth.user) return signInFirst(ctx);
700 if (!signedInPage(ctx, "milestones")) return signInFirst(ctx);
700701 const form = await readForm(ctx, "rw");
701702 if (form instanceof Response) return form;
702703 const number = Number(ctx.params.number);
src/web/pages/model.ts +5 −4
@@ -6,6 +6,7 @@
66 * card). A token is typed once and never shown again.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { blockedWay } from "../blocked.ts";
1112 import { noBudgetBlocked } from "../../actions/blocked_words.ts";
@@ -152,8 +153,8 @@ export function grantCard(ctx: Ctx, user: User, at: string): Html {
152153
153154 // POST /settings/accounts/:username/model
154155 export async function grantAct(ctx: Ctx): Promise<Response> {
155 if (!ctx.auth.user) return signInFirst(ctx);
156 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
156 if (!signedInPage(ctx, "model")) return signInFirst(ctx);
157 if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
157158 const form = await readForm(ctx, "admin");
158159 if (form instanceof Response) return form;
159160 const username = ctx.params.username ?? "";
@@ -181,8 +182,8 @@ export async function grantAct(ctx: Ctx): Promise<Response> {
181182
182183 // POST /settings/accounts/:username/ceiling
183184 export async function ceilingAct(ctx: Ctx): Promise<Response> {
184 if (!ctx.auth.user) return signInFirst(ctx);
185 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
185 if (!signedInPage(ctx, "model")) return signInFirst(ctx);
186 if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
186187 const form = await readForm(ctx, "admin");
187188 if (form instanceof Response) return form;
188189 const username = ctx.params.username ?? "";
src/web/pages/next.ts +2 −1
@@ -6,6 +6,7 @@
66 * phone need no script; a row can also be dragged, or moved by the key shown
77 * beside each action (`j`/`k` choose the row), which post the same form.
88 */
9 import { signedInPage } from "../../http/page_may.ts";
910 import { keyStep } from "./next_keys.ts";
1011 import { keyOf, oldKeys } from "../keymap.ts";
1112 import { DEFAULT_DECLINE, decideOffer, decideOutsider, decisionOf, outsiderShelf } from "../../actions/outsider_decision.ts";
@@ -376,7 +377,7 @@ export function nextPage(ctx: Ctx): Response {
376377 export async function nextSubmit(ctx: Ctx): Promise<Response> {
377378 const repo: Repo | undefined = loadRepo(ctx);
378379 if (!repo) return notFoundPage(ctx);
379 if (!ctx.auth.user) return signInFirst(ctx);
380 if (!signedInPage(ctx, "next")) return signInFirst(ctx);
380381 const form = await readForm(ctx, "rw");
381382 if (form instanceof Response) return form;
382383 const dest = backTo(form, `${repoBase(repo)}/next`);
src/web/pages/next_batch.ts +2 −1
@@ -4,6 +4,7 @@
44 * needed; the POST lands back on the page with `?undo=` naming the rows, and
55 * the page offers Undo only for rows still inside their minute.
66 */
7 import { signedInPage } from "../../http/page_may.ts";
78 import { batchWords, BATCH_MAX, numbersOf, snoozeMany, undoable, undoMany, UNDO_MS } from "../../actions/next.ts";
89 import type { Ctx } from "../../http/context.ts";
910 import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts";
@@ -55,7 +56,7 @@ export function batchButtons(live: readonly number[]): Html {
5556 export async function nextBatch(ctx: Ctx): Promise<Response> {
5657 const repo = loadRepo(ctx);
5758 if (!repo) return notFoundPage(ctx);
58 if (!ctx.auth.user) return signInFirst(ctx);
59 if (!signedInPage(ctx, "next_batch")) return signInFirst(ctx);
5960 const form = await readForm(ctx, "rw");
6061 if (form instanceof Response) return form;
6162 const dest = backTo(form, `${repoBase(repo)}/next`);
src/web/pages/offer-receipt.ts +2 −1
@@ -3,6 +3,7 @@
33 * where it stands, in the words the MCP `offer` tool returns (`core/fork_offer.ts`). Only the
44 * offerer and the upstream's writers read it; anyone else sees the page of an id never given.
55 */
6 import { signedInPage } from "../../http/page_may.ts";
67 import { offerDay, readForkOffer } from "../../core/fork_offer.ts";
78 import { getRepo } from "../../core/repos.ts";
89 import type { Ctx } from "../../http/context.ts";
@@ -11,7 +12,7 @@ import { html } from "../html.ts";
1112 import { page } from "../layout.ts";
1213
1314 export function offerReceiptPage(ctx: Ctx): Response {
14 if (!ctx.auth.user) return signInFirst(ctx);
15 if (!signedInPage(ctx, "offer-receipt")) return signInFirst(ctx);
1516 const r = readForkOffer(ctx.app.db, ctx.auth.user, ctx.params.id ?? "");
1617 if (r === undefined) return notFoundPage(ctx);
1718 const [owner = "", name = ""] = r.upstream.split("/");
src/web/pages/offer-upstream.ts +4 −3
@@ -6,6 +6,7 @@
66 * `upstreamOffer`'s, shared with the terminal; no git here.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import { OFFER_COMMIT_WORDS, offerCommit } from "../../actions/offer_commit.ts";
1011 import { OFFER_PULL_WORDS, offerPull, previewOfferPull } from "../../actions/offer_pull.ts";
1112 import { OFFER_WITHDRAW_WORDS, withdrawOffer } from "../../actions/offer_withdraw.ts";
@@ -62,7 +63,7 @@ export function offerCommitButton(
6263 export async function offerCommitPost(ctx: Ctx): Promise<Response> {
6364 const repo = loadRepo(ctx);
6465 if (!repo) return notFoundPage(ctx);
65 if (!ctx.auth.user) return signInFirst(ctx);
66 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
6667 const form = await readForm(ctx, "rw");
6768 if (form instanceof Response) return form;
6869 const rev = ctx.params.oid ?? "";
@@ -87,7 +88,7 @@ export async function offerCommitPost(ctx: Ctx): Promise<Response> {
8788 export async function offerWithdrawPost(ctx: Ctx): Promise<Response> {
8889 const fork = loadRepo(ctx);
8990 if (!fork) return notFoundPage(ctx);
90 if (!ctx.auth.user) return signInFirst(ctx);
91 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
9192 const form = await readForm(ctx, "rw");
9293 if (form instanceof Response) return form;
9394 const number = Number(ctx.params.number);
@@ -127,7 +128,7 @@ export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null {
127128 export async function offerPullPost(ctx: Ctx): Promise<Response> {
128129 const repo = loadRepo(ctx);
129130 if (!repo) return notFoundPage(ctx);
130 if (!ctx.auth.user) return signInFirst(ctx);
131 if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx);
131132 const form = await readForm(ctx, "rw");
132133 if (form instanceof Response) return form;
133134 const number = Number(ctx.params.number);
src/web/pages/org.ts +3 −2
@@ -9,6 +9,7 @@
99 * unknown username now says so.
1010 */
1111
12 import { adminPage, signedInPage } from "../../http/page_may.ts";
1213 import { USERNAME_PATTERN } from "../username_pattern.ts";
1314 import { emptyNote } from "../empty_words.ts";
1415 import {
@@ -496,7 +497,7 @@ function orgSecrets(ctx: Ctx, name: string): Html | null {
496497 // POST /:owner/-/subscriptions
497498 export async function orgSubscriptionsSave(ctx: Ctx): Promise<Response> {
498499 const org = requireOrgAdmin(ctx);
499 if (!org || ctx.auth.user?.isAdmin !== true) return notFoundPage(ctx);
500 if (!org || ctx.auth.user === undefined || !adminPage(ctx, "org", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
500501 const form = await readForm(ctx, "admin");
501502 if (form instanceof Response) return form;
502503 saveGrants(ctx, form, org.id, agentsOnForge(ctx));
@@ -551,7 +552,7 @@ export function newOrgPage(ctx: Ctx): Response {
551552
552553 // POST /organizations/new
553554 export async function newOrgSubmit(ctx: Ctx): Promise<Response> {
554 if (!ctx.auth.user) return signInFirst(ctx);
555 if (!signedInPage(ctx, "org")) return signInFirst(ctx);
555556 const form = await readForm(ctx, "rw");
556557 if (form instanceof Response) return form;
557558 const name = field(form, "name");
src/web/pages/origin-reach.ts +3 −2
@@ -11,6 +11,7 @@
1111 * same.
1212 */
1313
14 import { signedInPage } from "../../http/page_may.ts";
1415 import {
1516 ASK_ERROR_WORDS,
1617 askHost,
@@ -182,7 +183,7 @@ export const reachJs = /* js */ `
182183
183184 // POST /settings/origins/reach — the button: ask the host to allow `host`.
184185 export async function originReachAsk(ctx: Ctx): Promise<Response> {
185 if (!ctx.auth.user) return signInFirst(ctx);
186 if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx);
186187 const form = await readForm(ctx, "rw");
187188 if (form instanceof Response) return form;
188189 const host = field(form, "host").trim();
@@ -208,7 +209,7 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> {
208209
209210 // POST /settings/origins/reach/dismiss — take one's own answered ask off the page.
210211 export async function originReachDismiss(ctx: Ctx): Promise<Response> {
211 if (!ctx.auth.user) return signInFirst(ctx);
212 if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx);
212213 const form = await readForm(ctx, "rw");
213214 if (form instanceof Response) return form;
214215 dismissAsk(ctx.app, ctx.auth.user, field(form, "host"));
src/web/pages/origins.ts +2 −1
@@ -17,6 +17,7 @@
1717 * where it was — that page and its poll live in `origin-flow.ts`.
1818 */
1919
20 import { signedInPage } from "../../http/page_may.ts";
2021 import { originIcon } from "../origin_icon.ts";
2122 import { sshOn } from "../../settings/ssh.ts";
2223 import type { Database } from "bun:sqlite";
@@ -247,7 +248,7 @@ export const callbackUri = (ctx: Ctx): string =>
247248 * enumerate whose GitHub is connected, let alone spend it.
248249 */
249250 export function accountOnly(ctx: Ctx): Response | undefined {
250 if (!ctx.auth.user) return signInFirst(ctx);
251 if (!signedInPage(ctx, "origins")) return signInFirst(ctx);
251252 if (ctx.auth.via === "session" || ctx.auth.via === "password")
252253 return undefined;
253254 if (ctx.auth.scope === "admin") return undefined;
src/web/pages/packs-settings.ts +3 −2
@@ -6,6 +6,7 @@
66 * the change is on /packs at once.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1112 import { refreshCatalogQuietly } from "../../packs/catalog.ts";
@@ -20,8 +21,8 @@ import { btn, field as uiField, row } from "../ui.ts";
2021 import { accountSections } from "./origins.ts";
2122
2223 function requireAdmin(ctx: Ctx): Response | undefined {
23 if (!ctx.auth.user) return signInFirst(ctx);
24 if (!ctx.auth.user.isAdmin || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
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);
2526 return undefined;
2627 }
2728
src/web/pages/packs.ts +2 −1
@@ -20,6 +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";
2324
2425 const plural = (n: number, one: string): string => `${n} ${one}${n === 1 ? "" : "s"}`;
2526
@@ -225,7 +226,7 @@ export async function packPage(ctx: Ctx): Promise<Response> {
225226
226227 // POST /packs/mirror (admin)
227228 export async function packsMirror(ctx: Ctx): Promise<Response> {
228 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
229 if (!adminPage(ctx, "packs", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
229230 const form = await readForm(ctx, "admin");
230231 if (form instanceof Response) return form;
231232 const done = await mirrorPacks(ctx.app, ctx.auth.user);
src/web/pages/passkeys.ts +4 −3
@@ -6,6 +6,7 @@
66 * same-origin checked, and a challenge answers once.
77 */
88
9 import { signedInPage } from "../../http/page_may.ts";
910 import { challenges, verifyAssertion, verifyRegistration } from "../../auth/webauthn.ts";
1011 import type { App } from "../../app.ts";
1112 import {
@@ -62,7 +63,7 @@ const refuse = (status: number, message: string) =>
6263 /** A signed-in browser, on a same-origin request; else the refusal to send. */
6364 function sessionOnly(ctx: Ctx): Response | undefined {
6465 if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE);
65 if (!ctx.auth.user) return refuse(401, "Sign in first.");
66 if (!signedInPage(ctx, "passkeys")) return refuse(401, "Sign in first.");
6667 // A browser the platform edge signed in is a signed-in browser too: adding a
6768 // passkey there is how an account comes to sign in without the edge (#9432).
6869 if (ctx.auth.via !== "session" && ctx.auth.via !== "edge")
@@ -73,7 +74,7 @@ function sessionOnly(ctx: Ctx): Response | undefined {
7374 // GET /settings/passkeys
7475 export function passkeysPage(ctx: Ctx): Response {
7576 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
76 if (!ctx.auth.user) return signInFirst(ctx);
77 if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx);
7778 const user = ctx.auth.user;
7879 const keys = timePhase(ctx.request, "passkeys", () => listPasskeys(ctx.app.db, user.id));
7980 const rendering = performance.now();
@@ -164,7 +165,7 @@ export async function passkeyAdd(ctx: Ctx): Promise<Response> {
164165
165166 // POST /settings/passkeys/:id/delete
166167 export async function passkeyDelete(ctx: Ctx): Promise<Response> {
167 if (!ctx.auth.user) return signInFirst(ctx);
168 if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx);
168169 const form = await readForm(ctx, "admin");
169170 if (form instanceof Response) return form;
170171 const gone = removeOwnPasskey(ctx.app, ctx.auth.user, ctx.params.id ?? "");
src/web/pages/people.ts +5 −4
@@ -10,6 +10,7 @@
1010 * username wraps anywhere, so the page never scrolls sideways (#9374).
1111 */
1212
13 import { adminPage, signedInPage } from "../../http/page_may.ts";
1314 import { sshOn } from "../../settings/ssh.ts";
1415 import { setRole } from "../../actions/roles.ts";
1516 import { GRANT_MAX_USD } from "../../core/model_grant.ts";
@@ -45,8 +46,8 @@ export function appsMade(ctx: Ctx): Map<string, string[]> {
4546
4647 // GET /settings/people
4748 export function peoplePage(ctx: Ctx): Response {
48 if (!ctx.auth.user) return signInFirst(ctx);
49 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
49 if (!signedInPage(ctx, "people")) return signInFirst(ctx);
50 if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
5051 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
5152 const only = wordFilter(ctx.url.searchParams.get("role"));
5253 const rows = timePhase(ctx.request, "people", () => peopleByActivity(ctx.app.db, only));
@@ -125,8 +126,8 @@ export function peoplePage(ctx: Ctx): Response {
125126
126127 // POST /settings/people/:username/role
127128 export async function roleAct(ctx: Ctx): Promise<Response> {
128 if (!ctx.auth.user) return signInFirst(ctx);
129 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
129 if (!signedInPage(ctx, "people")) return signInFirst(ctx);
130 if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
130131 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
131132 const form = await readForm(ctx, "admin");
132133 if (form instanceof Response) return form;
src/web/pages/proven_identities.ts +2 −1
@@ -5,6 +5,7 @@
55 * Minecraft name by a code typed in game (#17284), shown where the forge has a game box, and
66 * unlinked here. The terminal says the same in Your profile (`tui/screens/profile.ts`).
77 */
8 import { signedInPage } from "../../http/page_may.ts";
89 import { listOf, NO_EMAIL_TO_REMOVE, REMOVED_EMAIL, removeEmail, typeBackEmail, type Identity } from "../../core/proven_identities.ts";
910 import { isStandInEmail } from "../../core/users.ts";
1011 import type { Ctx } from "../../http/context.ts";
@@ -55,7 +56,7 @@ export function identitiesBlock(ctx: Ctx): Html {
5556 // again. Only from the confirm page (`/-/confirm`), with the address typed back: the terminal asks
5657 // first too.
5758 export async function emailRemove(ctx: Ctx): Promise<Response> {
58 if (!ctx.auth.user) return signInFirst(ctx);
59 if (!signedInPage(ctx, "proven_identities")) return signInFirst(ctx);
5960 const form = await readForm(ctx, "rw");
6061 if (form instanceof Response) return form;
6162 if (field(form, "confirm") !== ctx.auth.user.email)
src/web/pages/pull-guest.ts +2 −1
@@ -7,6 +7,7 @@
77 * says what happens next in one sentence, read from the diff on the server.
88 */
99
10 import { signedInPage } from "../../http/page_may.ts";
1011 import type { Ctx } from "../../http/context.ts";
1112 import type { Pull } from "../../core/pulls.ts";
1213 import type { Repo } from "../../core/repos.ts";
@@ -73,7 +74,7 @@ export async function guestWalls(ctx: Ctx, repo: Repo, pull: Pull, baseOid: stri
7374 export async function pullApproveGuestSubmit(ctx: Ctx): Promise<Response> {
7475 const found = pullContext(ctx);
7576 if (found instanceof Response) return found;
76 if (!ctx.auth.user) return signInFirst(ctx);
77 if (!signedInPage(ctx, "pull-guest")) return signInFirst(ctx);
7778 const form = await readForm(ctx, "rw");
7879 if (form instanceof Response) return form;
7980 const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`;
src/web/pages/pull.ts +6 −5
@@ -8,6 +8,7 @@
88 * it needs.
99 */
1010
11 import { signedInPage } from "../../http/page_may.ts";
1112 import { paneJs } from "../studio/pane.ts";
1213 import { pullProposalAt } from "../../core/proposal_token.ts";
1314 import { keyOf, oldKeys } from "../keymap.ts";
@@ -1351,7 +1352,7 @@ export function pullThreadFragment(ctx: Ctx): Response {
13511352 export async function pullCommentSubmit(ctx: Ctx): Promise<Response> {
13521353 const found = pullContext(ctx);
13531354 if (found instanceof Response) return found;
1354 if (!ctx.auth.user) return signInFirst(ctx);
1355 if (!signedInPage(ctx, "pull")) return signInFirst(ctx);
13551356 const form = await readForm(ctx, "rw");
13561357 if (form instanceof Response) return form;
13571358
@@ -1389,7 +1390,7 @@ export async function pullCommentSubmit(ctx: Ctx): Promise<Response> {
13891390 export async function pullReviewSubmit(ctx: Ctx): Promise<Response> {
13901391 const found = pullContext(ctx);
13911392 if (found instanceof Response) return found;
1392 if (!ctx.auth.user) return signInFirst(ctx);
1393 if (!signedInPage(ctx, "pull")) return signInFirst(ctx);
13931394 const form = await readForm(ctx, "rw");
13941395 if (form instanceof Response) return form;
13951396
@@ -1484,7 +1485,7 @@ export function approveHereCard(
14841485 export async function pullApproveHereSubmit(ctx: Ctx): Promise<Response> {
14851486 const found = pullContext(ctx);
14861487 if (found instanceof Response) return found;
1487 if (!ctx.auth.user) return signInFirst(ctx);
1488 if (!signedInPage(ctx, "pull")) return signInFirst(ctx);
14881489 const form = await readForm(ctx, "rw");
14891490 if (form instanceof Response) return form;
14901491 const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`;
@@ -1527,7 +1528,7 @@ export async function pullApproveHereSubmit(ctx: Ctx): Promise<Response> {
15271528 export async function pullReviewStateSubmit(ctx: Ctx): Promise<Response> {
15281529 const found = pullContext(ctx);
15291530 if (found instanceof Response) return found;
1530 if (!ctx.auth.user) return signInFirst(ctx);
1531 if (!signedInPage(ctx, "pull")) return signInFirst(ctx);
15311532 const form = await readForm(ctx, "rw");
15321533 if (form instanceof Response) return form;
15331534
@@ -1589,7 +1590,7 @@ export function threadResolveSubmit(
15891590 return async (ctx: Ctx): Promise<Response> => {
15901591 const found = pullContext(ctx);
15911592 if (found instanceof Response) return found;
1592 if (!ctx.auth.user) return signInFirst(ctx);
1593 if (!signedInPage(ctx, "pull")) return signInFirst(ctx);
15931594 const form = await readForm(ctx, "rw");
15941595 if (form instanceof Response) return form;
15951596
src/web/pages/pulls.ts +3 −2
@@ -5,6 +5,7 @@
55 * `src/web/studio/lists.ts`).
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { DELETING_SAYS } from "../../core/repo_deleting.ts";
910 import { openPull } from "../../actions/pulls.ts";
1011 import { VERIFY_FIRST } from "../../actions/verify_words.ts";
@@ -139,7 +140,7 @@ export async function newPullPage(ctx: Ctx): Promise<Response> {
139140 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
140141 const repo = loadRepo(ctx);
141142 if (!repo) return notFoundPage(ctx);
142 if (!ctx.auth.user) return signInFirst(ctx);
143 if (!signedInPage(ctx, "pulls")) return signInFirst(ctx);
143144 const forceSelf = ctx.url.searchParams.get("self") !== null;
144145 const comparing = performance.now();
145146 const c = await composeContext(ctx, repo, forceSelf);
@@ -220,7 +221,7 @@ const COMPOSE_ERRORS: Record<string, string> = {
220221 export async function newPullSubmit(ctx: Ctx): Promise<Response> {
221222 const repo = loadRepo(ctx);
222223 if (!repo) return notFoundPage(ctx);
223 if (!ctx.auth.user) return signInFirst(ctx);
224 if (!signedInPage(ctx, "pulls")) return signInFirst(ctx);
224225 const form = await readForm(ctx, "rw");
225226 if (form instanceof Response) return form;
226227
src/web/pages/repo.ts +5 −4
@@ -8,6 +8,7 @@
88 * path segment and can never smuggle a path of its own.
99 */
1010
11 import { signedInPage } from "../../http/page_may.ts";
1112 import { clamp } from "../clamp.ts";
1213 import { reviewCard } from "./review.ts";
1314 import { keyOf } from "../keymap.ts";
@@ -379,7 +380,7 @@ function forkBar(ctx: Ctx, repo: Repo, visible: readonly RecentFork[]): Html {
379380 export async function forkSubmit(ctx: Ctx): Promise<Response> {
380381 const repo = loadRepo(ctx);
381382 if (!repo) return notFoundPage(ctx);
382 if (!ctx.auth.user) return signInFirst(ctx);
383 if (!signedInPage(ctx, "repo")) return signInFirst(ctx);
383384 const form = await readForm(ctx, "rw");
384385 if (form instanceof Response) return form;
385386
@@ -447,7 +448,7 @@ export async function forkSubmit(ctx: Ctx): Promise<Response> {
447448 export async function repoSyncSubmit(ctx: Ctx): Promise<Response> {
448449 const repo = loadRepo(ctx);
449450 if (!repo) return notFoundPage(ctx);
450 if (!ctx.auth.user) return signInFirst(ctx);
451 if (!signedInPage(ctx, "repo")) return signInFirst(ctx);
451452 const form = await readForm(ctx, "rw");
452453 if (form instanceof Response) return form;
453454
@@ -503,7 +504,7 @@ function mirrorRefusal(repo: Repo, error: "unauthorized" | "forbidden" | "not_fo
503504 export async function repoTakeSubmit(ctx: Ctx): Promise<Response> {
504505 const repo = loadRepo(ctx);
505506 if (!repo) return notFoundPage(ctx);
506 if (!ctx.auth.user) return signInFirst(ctx);
507 if (!signedInPage(ctx, "repo")) return signInFirst(ctx);
507508 const form = await readForm(ctx, "rw");
508509 if (form instanceof Response) return form;
509510 const taken = await takeFromOrigin(ctx.app, ctx.auth.user, repo);
@@ -529,7 +530,7 @@ export async function repoTakeSubmit(ctx: Ctx): Promise<Response> {
529530 export async function pinSubmit(ctx: Ctx): Promise<Response> {
530531 const repo = loadRepo(ctx);
531532 if (!repo) return notFoundPage(ctx);
532 if (!ctx.auth.user) return signInFirst(ctx);
533 if (!signedInPage(ctx, "repo")) return signInFirst(ctx);
533534 const form = await readForm(ctx, "rw");
534535 if (form instanceof Response) return form;
535536
src/web/pages/reports.ts +4 −3
@@ -9,6 +9,7 @@
99 * gets the usual 404.
1010 */
1111
12 import { signedInPage } from "../../http/page_may.ts";
1213 import {
1314 acceptReport,
1415 dismissReport,
@@ -365,7 +366,7 @@ export function reportsPage(ctx: Ctx): Response {
365366 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
366367 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
367368 if (!repo) return notFoundPage(ctx);
368 if (!ctx.auth.user) return signInFirst(ctx);
369 if (!signedInPage(ctx, "reports")) return signInFirst(ctx);
369370 // A read-only token (an app process holds its owner's) never reads them.
370371 if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "rw"))
371372 return notFoundPage(ctx);
@@ -413,7 +414,7 @@ export function reportsPage(ctx: Ctx): Response {
413414 export async function reportAcceptSubmit(ctx: Ctx): Promise<Response> {
414415 const repo = loadRepo(ctx);
415416 if (!repo) return notFoundPage(ctx);
416 if (!ctx.auth.user) return signInFirst(ctx);
417 if (!signedInPage(ctx, "reports")) return signInFirst(ctx);
417418 const form = await readForm(ctx, "rw");
418419 if (form instanceof Response) return form;
419420 const accepted = await acceptReport(
@@ -447,7 +448,7 @@ export async function reportAcceptSubmit(ctx: Ctx): Promise<Response> {
447448 export async function reportDismissSubmit(ctx: Ctx): Promise<Response> {
448449 const repo = loadRepo(ctx);
449450 if (!repo) return notFoundPage(ctx);
450 if (!ctx.auth.user) return signInFirst(ctx);
451 if (!signedInPage(ctx, "reports")) return signInFirst(ctx);
451452 const form = await readForm(ctx, "rw");
452453 if (form instanceof Response) return form;
453454 const dismissed = dismissReport(
src/web/pages/resilience.ts +5 −4
@@ -8,6 +8,7 @@
88 * any forge given no bucket — that they are off here and why, said plainly.
99 */
1010
11 import { adminPage, signedInPage } from "../../http/page_may.ts";
1112 import { readResilience, type Row } from "../../checks/resilience.ts";
1213 import type { Standing } from "../../core/threats.ts";
1314 import type { Ctx } from "../../http/context.ts";
@@ -45,8 +46,8 @@ export function nightlyHtml(ctx: Ctx): Html {
4546 // GET /resilience/nightly/:job: the newest output of one nightly job, the
4647 // run its `Flaky:` and `Red:` issues link to. An admin's, as /resilience is.
4748 export function nightlyOutputPage(ctx: Ctx): Response {
48 if (!ctx.auth.user) return signInFirst(ctx);
49 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
49 if (!signedInPage(ctx, "resilience")) return signInFirst(ctx);
50 if (!adminPage(ctx, "resilience", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
5051 const at = JOBS.findIndex((j) => j.name === ctx.params.job);
5152 const job = JOBS[at];
5253 if (job === undefined) return notFoundPage(ctx);
@@ -100,8 +101,8 @@ export function protectionsHtml(rows: readonly Row[]): Html {
100101 // GET /resilience: a forge admin's, since live red lines name what to attack.
101102 export function resiliencePage(ctx: Ctx): Response {
102103 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
103 if (!ctx.auth.user) return signInFirst(ctx);
104 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
104 if (!signedInPage(ctx, "resilience")) return signInFirst(ctx);
105 if (!adminPage(ctx, "resilience", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
105106 const rows = timePhase(ctx.request, "threats", () => readResilience(ctx.app.config.dataDir));
106107 const rendering = performance.now();
107108 const count = (s: Standing): number => rows.filter((r) => r.s === s).length;
src/web/pages/runners.ts +4 −3
@@ -8,6 +8,7 @@
88 * routes are marked `open` in `http/marks/settings.json`, as `/admin/flows` is, so this page's own
99 * check answers rather than the admin gate's 403.
1010 */
11 import { adminPage, signedInPage } from "../../http/page_may.ts";
1112 import { listLending, offerLending, resumeLending, stopLending, type LendView } from "../../actions/lending.ts";
1213 import { setRunnerTrust } from "../../actions/environments.ts";
1314 import { enrol, list, pause, removeHandMade, resume, revoke, runnerState } from "../../actions/runners.ts";
@@ -32,8 +33,8 @@ import { accountSections } from "./origins.ts";
3233 const HERE = "/settings/runners";
3334
3435 function admin(ctx: Ctx): Response | undefined {
35 if (!ctx.auth.user) return signInFirst(ctx);
36 return ctx.auth.user.isAdmin && ctx.auth.user.kind === "user" ? undefined : notFoundPage(ctx);
36 if (!signedInPage(ctx, "runners")) return signInFirst(ctx);
37 return adminPage(ctx, "runners", ctx.auth.user.isAdmin && ctx.auth.user.kind === "user") ? undefined : notFoundPage(ctx);
3738 }
3839
3940 /**
@@ -222,7 +223,7 @@ export async function runnerPause(ctx: Ctx): Promise<Response> {
222223
223224 // GET /settings/runners/lending/live
224225 export function lendingLive(ctx: Ctx): Response {
225 if (!ctx.auth.user?.isAdmin || ctx.auth.user.kind !== "user") return fragment(html``, { status: 404 });
226 if (!adminPage(ctx, "runners", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind === "user")) return fragment(html``, { status: 404 });
226227 return fragment(lendingNowPart(ctx), { request: ctx.request });
227228 }
228229
src/web/pages/runs.ts +5 −4
@@ -11,6 +11,7 @@
1111 * id, so the redirect itself says nothing about what exists.
1212 */
1313
14 import { signedInPage } from "../../http/page_may.ts";
1415 import { crewFace } from "../pixel.ts";
1516 import { steerRefusedWords } from "../../actions/steer_words.ts";
1617 import { readLooks } from "../../checks/looks.ts";
@@ -397,7 +398,7 @@ export async function runPage(ctx: Ctx): Promise<Response> {
397398 export async function runSteer(ctx: Ctx): Promise<Response> {
398399 const repo = loadRepo(ctx);
399400 if (!repo) return notFoundPage(ctx);
400 if (!ctx.auth.user) return signInFirst(ctx);
401 if (!signedInPage(ctx, "runs")) return signInFirst(ctx);
401402 const form = await readForm(ctx, "rw");
402403 if (form instanceof Response) return form;
403404 const id = ctx.params.id ?? "";
@@ -426,7 +427,7 @@ export async function runSteer(ctx: Ctx): Promise<Response> {
426427
427428 // GET /runs/:id — the run's own page, wherever it lives.
428429 export function runRedirect(ctx: Ctx): Response {
429 if (!ctx.auth.user) return signInFirst(ctx);
430 if (!signedInPage(ctx, "runs")) return signInFirst(ctx);
430431 const run = getRun(ctx.app.db, ctx.params.id ?? "");
431432 const repo =
432433 run === undefined ? undefined : getRepoById(ctx.app.db, run.repoId);
@@ -439,7 +440,7 @@ export function runRedirect(ctx: Ctx): Response {
439440 export async function runCancel(ctx: Ctx): Promise<Response> {
440441 const repo = loadRepo(ctx);
441442 if (!repo) return notFoundPage(ctx);
442 if (!ctx.auth.user) return signInFirst(ctx);
443 if (!signedInPage(ctx, "runs")) return signInFirst(ctx);
443444 const form = await readForm(ctx, "rw");
444445 if (form instanceof Response) return form;
445446 const id = ctx.params.id ?? "";
@@ -471,7 +472,7 @@ const REQUEUE_REFUSED: Record<string, string> = {
471472 export async function runRequeue(ctx: Ctx): Promise<Response> {
472473 const repo = loadRepo(ctx);
473474 if (!repo) return notFoundPage(ctx);
474 if (!ctx.auth.user) return signInFirst(ctx);
475 if (!signedInPage(ctx, "runs")) return signInFirst(ctx);
475476 const form = await readForm(ctx, "rw");
476477 if (form instanceof Response) return form;
477478 const queued = requeueRepoRun(ctx.app, ctx.auth.user, repo, ctx.params.id ?? "");
src/web/pages/scrapes.ts +3 −2
@@ -6,6 +6,7 @@
66 * of identity stops at a network or a group, and says so.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1112 import type { Ctx } from "../../http/context.ts";
@@ -37,8 +38,8 @@ const days = (raw: string | null): number => {
3738 };
3839
3940 function admin(ctx: Ctx): Response | null {
40 if (!ctx.auth.user) return signInFirst(ctx);
41 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
41 if (!signedInPage(ctx, "scrapes")) return signInFirst(ctx);
42 if (!adminPage(ctx, "scrapes", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
4243 return null;
4344 }
4445
src/web/pages/secrets.ts +3 −2
@@ -7,6 +7,7 @@
77 * when something last opened it.
88 */
99
10 import { adminPage, signedInPage } from "../../http/page_may.ts";
1011 import { sshOn } from "../../settings/ssh.ts";
1112 import type { SecretUse } from "../../core/app_secrets.ts";
1213 import { lookMailAws, setUpMailAws, testMailAws, undoMailAws } from "../../actions/mail_aws.ts";
@@ -152,8 +153,8 @@ export function secretsSection(
152153 }
153154
154155 function requireAdmin(ctx: Ctx): Response | undefined {
155 if (!ctx.auth.user) return signInFirst(ctx);
156 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
156 if (!signedInPage(ctx, "secrets")) return signInFirst(ctx);
157 if (!adminPage(ctx, "secrets", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
157158 return undefined;
158159 }
159160
src/web/pages/security.ts +5 −4
@@ -6,6 +6,7 @@
66 * names, never the value of a token or key.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { upstreamBlob } from "../../core/upstream.ts";
1112 import { readFileSync, statSync } from "node:fs";
@@ -309,8 +310,8 @@ function scriptErrorRow(db: Database, nowMs: number): Html | null {
309310 }
310311
311312 export function securityPage(ctx: Ctx): Response {
312 if (!ctx.auth.user) return signInFirst(ctx);
313 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
313 if (!signedInPage(ctx, "security")) return signInFirst(ctx);
314 if (!adminPage(ctx, "security", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
314315 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
315316 const rendering = performance.now();
316317 const nowMs = Date.now();
@@ -400,8 +401,8 @@ export function securityPage(ctx: Ctx): Response {
400401
401402 /** POST /settings/security/shield: move the Shield; the page's Undo posts here too. */
402403 export async function securityShieldSet(ctx: Ctx): Promise<Response> {
403 if (!ctx.auth.user) return signInFirst(ctx);
404 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
404 if (!signedInPage(ctx, "security")) return signInFirst(ctx);
405 if (!adminPage(ctx, "security", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
405406 const form = await readForm(ctx, "admin");
406407 if (form instanceof Response) return form;
407408 const changed = changeShield(ctx.app, ctx.auth.user, field(form, "state"));
src/web/pages/security_controls.ts +3 −2
@@ -3,6 +3,7 @@
33 * (`checks/controls.ts`).
44 */
55
6 import { adminPage, signedInPage } from "../../http/page_may.ts";
67 import { sshOn } from "../../settings/ssh.ts";
78 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
89 import { controlStandings, type Standing } from "../../checks/controls.ts";
@@ -40,8 +41,8 @@ function line(s: Standing): Html {
4041 }
4142
4243 export function securityControlsPage(ctx: Ctx): Response {
43 if (!ctx.auth.user) return signInFirst(ctx);
44 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
44 if (!signedInPage(ctx, "security_controls")) return signInFirst(ctx);
45 if (!adminPage(ctx, "security_controls", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
4546 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
4647 const rendering = performance.now();
4748 const standings = controlStandings(ctx.app.config.dataDir, Date.now());
src/web/pages/series.ts +4 −3
@@ -7,6 +7,7 @@
77 * forge admin who is a person. Everything lives in the address (`q`,
88 * `range`, `from`, `to`), so a view is a link; the only script is none.
99 */
10 import { signedInPage } from "../../http/page_may.ts";
1011 import { canSeeMemory } from "../../boards/memory.ts";
1112 import type { Ctx } from "../../http/context.ts";
1213 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
@@ -91,7 +92,7 @@ function savedList(rows: readonly Saved[], minutes: number): Html {
9192
9293 export function seriesPage(ctx: Ctx): Response {
9394 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
94 if (!ctx.auth.user) return signInFirst(ctx);
95 if (!signedInPage(ctx, "series")) return signInFirst(ctx);
9596 if (!canSeeMemory(ctx.auth.user)) return notFoundPage(ctx);
9697 const ask = askOf(ctx.url.searchParams);
9798 const a = answer(ctx.app.db, ask, Date.now());
@@ -115,7 +116,7 @@ export function seriesPage(ctx: Ctx): Response {
115116
116117 /** POST /explore/series/save: a pin or a report. */
117118 export async function seriesSave(ctx: Ctx): Promise<Response> {
118 if (!ctx.auth.user) return signInFirst(ctx);
119 if (!signedInPage(ctx, "series")) return signInFirst(ctx);
119120 const form = await readForm(ctx, "admin");
120121 if (form instanceof Response) return form;
121122 if (!canSeeMemory(ctx.auth.user)) return ctx.auth.user.kind === "agent" ? forbiddenPage(ctx, "Saving a query is a person's.") : notFoundPage(ctx);
@@ -127,7 +128,7 @@ export async function seriesSave(ctx: Ctx): Promise<Response> {
127128
128129 /** POST /explore/series/remove: forget one saved query. */
129130 export async function seriesRemove(ctx: Ctx): Promise<Response> {
130 if (!ctx.auth.user) return signInFirst(ctx);
131 if (!signedInPage(ctx, "series")) return signInFirst(ctx);
131132 const form = await readForm(ctx, "admin");
132133 if (form instanceof Response) return form;
133134 if (!canSeeMemory(ctx.auth.user)) return ctx.auth.user.kind === "agent" ? forbiddenPage(ctx, "Removing a saved query is a person's.") : notFoundPage(ctx);
src/web/pages/site.ts +3 −2
@@ -8,6 +8,7 @@
88 * typed still in it. A dead end that loses input is a bug, not a message.
99 */
1010
11 import { signedInPage } from "../../http/page_may.ts";
1112 import { contributorMay } from "../../text/contributor.ts";
1213 import { closeState, closingSays } from "../../actions/account_close.ts";
1314 import { USERNAME_PATTERN } from "../username_pattern.ts";
@@ -991,7 +992,7 @@ function newRepoForm(
991992 }
992993
993994 export function newRepoPage(ctx: Ctx): Response {
994 if (!ctx.auth.user) return signInFirst(ctx);
995 if (!signedInPage(ctx, "site")) return signInFirst(ctx);
995996 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
996997 const owners = ownersFor(ctx, ctx.auth.user);
997998 const rendering = performance.now();
@@ -1014,7 +1015,7 @@ export function newRepoPage(ctx: Ctx): Response {
10141015 }
10151016
10161017 export async function newRepoSubmit(ctx: Ctx): Promise<Response> {
1017 if (!ctx.auth.user) return signInFirst(ctx);
1018 if (!signedInPage(ctx, "site")) return signInFirst(ctx);
10181019 const form = await readForm(ctx, "rw");
10191020 if (form instanceof Response) return form;
10201021 const values: RepoValues = {
src/web/pages/sources.ts +3 −2
@@ -9,6 +9,7 @@
99 * stored views (`perf/views_store.ts`) in one indexed read.
1010 */
1111
12 import { adminPage, signedInPage } from "../../http/page_may.ts";
1213 import { sshOn } from "../../settings/ssh.ts";
1314 import { getAppById } from "../../core/apps.ts";
1415 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
@@ -269,8 +270,8 @@ export function sourcesBody(ctx: Ctx, q: Query, label: string): Html {
269270
270271 /** GET /settings/traffic/sources — the forge's view, or `?app=<id>` for any app; admins only. */
271272 export function sourcesPage(ctx: Ctx): Response {
272 if (!ctx.auth.user) return signInFirst(ctx);
273 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
273 if (!signedInPage(ctx, "sources")) return signInFirst(ctx);
274 if (!adminPage(ctx, "sources", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
274275 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
275276 const asked = ctx.url.searchParams.get("app");
276277 const record = asked === null ? undefined : getAppById(ctx.app.db, asked);
src/web/pages/spend-tab.ts +3 −2
@@ -4,6 +4,7 @@
44 * on the Subscriptions page before; the numbers are the same.
55 */
66
7 import { adminPage, signedInPage } from "../../http/page_may.ts";
78 import { readSpend } from "../../actions/spend.ts";
89 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
910 import type { Ctx } from "../../http/context.ts";
@@ -15,8 +16,8 @@ import { usageShell } from "./usage-tabs.ts";
1516
1617 // GET /settings/spend
1718 export function spendPage(ctx: Ctx): Response {
18 if (!ctx.auth.user) return signInFirst(ctx);
19 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
19 if (!signedInPage(ctx, "spend-tab")) return signInFirst(ctx);
20 if (!adminPage(ctx, "spend-tab", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
2021 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2122 const spend = timePhase(ctx.request, "spend", () => readSpend(ctx.app, new Date()));
2223 const rendering = performance.now();
src/web/pages/subscriptions.ts +3 −2
@@ -5,6 +5,7 @@
55 * for. A token is typed once and never shown again.
66 */
77
8 import { adminPage, signedInPage } from "../../http/page_may.ts";
89 import { ACCOUNTS_WORDS, allowAccount, crewAccountWords } from "../../actions/crew_accounts.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import { listAgents, type Agent } from "../../core/agents.ts";
@@ -75,8 +76,8 @@ import { limitValue } from "../../settings/limits.ts";
7576 const POOL = "/settings/subscriptions";
7677
7778 function requireAdmin(ctx: Ctx): Response | undefined {
78 if (!ctx.auth.user) return signInFirst(ctx);
79 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
79 if (!signedInPage(ctx, "subscriptions")) return signInFirst(ctx);
80 if (!adminPage(ctx, "subscriptions", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
8081 return undefined;
8182 }
8283
src/web/pages/system.ts +4 −3
@@ -21,6 +21,7 @@
2121 * line each for memory, CPU and disk; a parent lists each child's use
2222 * against its size (#10853, `spawn/usage.ts`).
2323 */
24 import { signedInPage } from "../../http/page_may.ts";
2425 import { askingOf, type Asker } from "../../perf/asking.ts";
2526 import { keyOf } from "../keymap.ts";
2627 import { emptyNote } from "../empty_words.ts";
@@ -358,7 +359,7 @@ export { CENSUS_AGENT_REFUSED };
358359
359360 /** POST /system/heap-census: one census, a person admin's, at most every ten minutes. */
360361 export async function heapCensusSubmit(ctx: Ctx): Promise<Response> {
361 if (!ctx.auth.user) return signInFirst(ctx);
362 if (!signedInPage(ctx, "system")) return signInFirst(ctx);
362363 const form = await readForm(ctx, "admin");
363364 if (form instanceof Response) return form;
364365 // An agent hears why in one sentence; a person who is not an admin finds no such page.
@@ -738,7 +739,7 @@ export const sampleFrame = (v: SystemView): { regions: Record<string, string> }
738739
739740 // GET /system/stream: the owner's live samples, one frame each.
740741 export function systemStream(ctx: Ctx): Response {
741 if (!ctx.auth.user) return signInFirst(ctx);
742 if (!signedInPage(ctx, "system")) return signInFirst(ctx);
742743 if (telemetryReader(ctx.app, ctx.auth.user)?.kind !== "owner") return notFoundPage(ctx);
743744 const sampler = live();
744745 return eventStream(ctx.app, ctx.request, (emit, _close, ready) => {
@@ -763,7 +764,7 @@ export function floorLine(held: FloorHold): Html {
763764
764765 // GET /system
765766 export async function systemPage(ctx: Ctx, patterns: () => readonly string[]): Promise<Response> {
766 if (!ctx.auth.user) return signInFirst(ctx);
767 if (!signedInPage(ctx, "system")) return signInFirst(ctx);
767768 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
768769 const reader = timePhase(ctx.request, "reader", () => telemetryReader(ctx.app, ctx.auth.user!));
769770 if (reader?.kind !== "owner") return notFoundPage(ctx);
src/web/pages/teams.ts +3 −2
@@ -20,6 +20,7 @@ import { flashTo, page } from "../layout.ts";
2020 import { btn, icon, row, time } from "../ui.ts";
2121 import { emptyLine, emptyList } from "../empty_words.ts";
2222 import { accountSections } from "./origins.ts";
23 import { adminPage } from "../../http/page_may.ts";
2324
2425 const isAdminPerson = (ctx: Ctx): boolean =>
2526 ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent";
@@ -159,7 +160,7 @@ export const teamsLiveJs = /* js */ `
159160
160161 // GET /settings/teams/stream: the page's regions again, each time a team changes.
161162 export function teamsStream(ctx: Ctx): Response {
162 if (!isAdminPerson(ctx)) return notFoundPage(ctx);
163 if (!adminPage(ctx, "teams", isAdminPerson(ctx))) return notFoundPage(ctx);
163164 return eventStream(ctx.app, ctx.request, (emit, _close, ready) => {
164165 const send = () => {
165166 const r = regions(ctx);
@@ -203,7 +204,7 @@ export function teamsPage(ctx: Ctx): Response {
203204 // POST /settings/teams/:slug
204205 export async function teamSet(ctx: Ctx): Promise<Response> {
205206 // Checked before the body is read: a non-admin learns nothing of the door.
206 if (!isAdminPerson(ctx)) return notFoundPage(ctx);
207 if (!adminPage(ctx, "teams", isAdminPerson(ctx))) return notFoundPage(ctx);
207208 const form = await readForm(ctx, "admin");
208209 if (form instanceof Response) return form;
209210 const slug = ctx.params.slug ?? "";
src/web/pages/telemetry.ts +3 −2
@@ -2,6 +2,7 @@
22 * Settings → Telemetry, for the owner: which named agents hold
33 * `telemetry:read`, one switch each, and the reads they have made (#1789).
44 */
5 import { adminPage, signedInPage } from "../../http/page_may.ts";
56 import { setTelemetryGrant } from "../../actions/telemetry.ts";
67 import { grantable, recentReads } from "../../core/telemetry.ts";
78 import type { Ctx } from "../../http/context.ts";
@@ -14,8 +15,8 @@ import { btn, icon, row, time } from "../ui.ts";
1415 import { usageShell } from "./usage-tabs.ts";
1516
1617 function owner(ctx: Ctx): Response | undefined {
17 if (!ctx.auth.user) return signInFirst(ctx);
18 return ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx);
18 if (!signedInPage(ctx, "telemetry")) return signInFirst(ctx);
19 return adminPage(ctx, "telemetry", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx);
1920 }
2021
2122 // GET /settings/telemetry
src/web/pages/thread.ts +8 −7
@@ -8,6 +8,7 @@
88 * is what makes a long thread skimmable.
99 */
1010
11 import { signedInPage } from "../../http/page_may.ts";
1112 import { originError } from "../../actions/merge_words.ts";
1213 import { keyOf } from "../keymap.ts";
1314 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
@@ -922,7 +923,7 @@ export async function assigneeSubmit(
922923 ): Promise<Response> {
923924 const found = threadContext(ctx, kind);
924925 if (found instanceof Response) return found;
925 if (!ctx.auth.user) return signInFirst(ctx);
926 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
926927 const form = await readForm(ctx, "rw");
927928 if (form instanceof Response) return form;
928929
@@ -972,7 +973,7 @@ export async function stateSubmit(
972973 ): Promise<Response> {
973974 const found = threadContext(ctx, kind);
974975 if (found instanceof Response) return found;
975 if (!ctx.auth.user) return signInFirst(ctx);
976 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
976977 const form = await readForm(ctx, "rw");
977978 if (form instanceof Response) return form;
978979
@@ -1049,7 +1050,7 @@ export async function wordsSubmit(
10491050 ): Promise<Response> {
10501051 const found = threadContext(ctx, kind);
10511052 if (found instanceof Response) return found;
1052 if (!ctx.auth.user) return signInFirst(ctx);
1053 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
10531054 const form = await readForm(ctx, "rw");
10541055 if (form instanceof Response) return form;
10551056 const dest = `${repoBase(found.repo)}/${kind === "pull" ? "pulls" : "issues"}/${found.issue.number}`;
@@ -1084,7 +1085,7 @@ export async function labelsSubmit(
10841085 ): Promise<Response> {
10851086 const found = threadContext(ctx, kind);
10861087 if (found instanceof Response) return found;
1087 if (!ctx.auth.user) return signInFirst(ctx);
1088 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
10881089 const form = await readForm(ctx, "rw");
10891090 if (form instanceof Response) return form;
10901091
@@ -1121,7 +1122,7 @@ export async function labelsSubmit(
11211122 export async function flowSubmit(ctx: Ctx): Promise<Response> {
11221123 const found = threadContext(ctx, "issue");
11231124 if (found instanceof Response) return found;
1124 if (!ctx.auth.user) return signInFirst(ctx);
1125 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
11251126 const form = await readForm(ctx, "rw");
11261127 if (form instanceof Response) return form;
11271128 const asked = field(form, "flow");
@@ -1172,7 +1173,7 @@ export function issueTeamsCard(ctx: Ctx, repo: Repo, issue: Issue, action: strin
11721173 export async function teamsSubmit(ctx: Ctx): Promise<Response> {
11731174 const found = threadContext(ctx, "issue");
11741175 if (found instanceof Response) return found;
1175 if (!ctx.auth.user) return signInFirst(ctx);
1176 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
11761177 const form = await readForm(ctx, "rw");
11771178 if (form instanceof Response) return form;
11781179 const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`;
@@ -1288,7 +1289,7 @@ export function dependenciesCard(
12881289 export async function dependencySubmit(ctx: Ctx): Promise<Response> {
12891290 const found = threadContext(ctx, "issue");
12901291 if (found instanceof Response) return found;
1291 if (!ctx.auth.user) return signInFirst(ctx);
1292 if (!signedInPage(ctx, "thread")) return signInFirst(ctx);
12921293 const form = await readForm(ctx, "rw");
12931294 if (form instanceof Response) return form;
12941295 const dest = backTo(form, `${repoBase(found.repo)}/issues/${found.issue.number}`);
src/web/pages/traffic.ts +3 −2
@@ -6,6 +6,7 @@
66 * but an admin.
77 */
88
9 import { adminPage, signedInPage } from "../../http/page_may.ts";
910 import { sshOn } from "../../settings/ssh.ts";
1011 import type { Ctx } from "../../http/context.ts";
1112 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
@@ -113,8 +114,8 @@ function legend(): Html {
113114 }
114115
115116 export function trafficPage(ctx: Ctx): Response {
116 if (!ctx.auth.user) return signInFirst(ctx);
117 if (!ctx.auth.user.isAdmin) return notFoundPage(ctx);
117 if (!signedInPage(ctx, "traffic")) return signInFirst(ctx);
118 if (!adminPage(ctx, "traffic", ctx.auth.user.isAdmin)) return notFoundPage(ctx);
118119 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
119120 const rendering = performance.now();
120121 const now = Date.now();
src/web/pages/trusted.ts +3 −2
@@ -3,6 +3,7 @@
33 * a person's review, until when; a one-click remove; the kill switch that
44 * stops all folding in; and the revert of one source's landings.
55 */
6 import { adminPage, signedInPage } from "../../http/page_may.ts";
67 import { sshOn } from "../../settings/ssh.ts";
78 import { addTrust, removeTrust, revertBySource, setFoldInStopped } from "../../actions/trusted_sources.ts";
89 import {
@@ -23,8 +24,8 @@ import { emptyList } from "../empty_words.ts";
2324 import { accountSections } from "./origins.ts";
2425
2526 function owner(ctx: Ctx): Response | undefined {
26 if (!ctx.auth.user) return signInFirst(ctx);
27 return ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx);
27 if (!signedInPage(ctx, "trusted")) return signInFirst(ctx);
28 return adminPage(ctx, "trusted", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx);
2829 }
2930
3031 const WORDS: Record<TrustError | "not_found", string> = {
src/web/pages/variants.ts +2 −1
@@ -5,6 +5,7 @@
55 * of script. A reader sees the cards and no buttons; their post is refused.
66 */
77
8 import { signedInPage } from "../../http/page_may.ts";
89 import { DEFAULT_REASON, REASON_MAX, voteVariant } from "../../actions/variants.ts";
910 import { getAppByRepo } from "../../core/apps.ts";
1011 import { variantMembers, type Pull } from "../../core/pulls.ts";
@@ -121,7 +122,7 @@ export const variantVoteSubmit =
121122 async (ctx: Ctx): Promise<Response> => {
122123 const repo = loadRepo(ctx);
123124 if (!repo) return notFoundPage(ctx);
124 if (!ctx.auth.user) return signInFirst(ctx);
125 if (!signedInPage(ctx, "variants")) return signInFirst(ctx);
125126 const form = await readForm(ctx, "rw");
126127 if (form instanceof Response) return form;
127128 const group = ctx.params.group ?? "";
src/web/pages/visitor_bring.ts +4 −3
@@ -9,6 +9,7 @@
99 * undoes them (`tui/screens/visitor_bring.ts`).
1010 */
1111
12 import { signedInPage } from "../../http/page_may.ts";
1213 import { BRING_WORDS, broughtCount, bringable, bringToAccount, broughtReceipts, movedApps, mayBring, undoBrought } from "../../actions/visitor_bring.ts";
1314 import { MADE_SHOWN, type Made, type MovedApp, type Receipt } from "../../core/visitor_bring.ts";
1415 import type { Ctx } from "../../http/context.ts";
@@ -58,7 +59,7 @@ const receiptRow = (r: Receipt, now: number): Html => {
5859 // GET /settings/bring
5960 export function visitorBringPage(ctx: Ctx): Response {
6061 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
61 if (!ctx.auth.user) return signInFirst(ctx);
62 if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx);
6263 const user = ctx.auth.user;
6364 const carry = carryOf(ctx.url.searchParams.get("carry"));
6465 const { made, more } = bringable(ctx.app, { carry, headers: ctx.request.headers });
@@ -105,7 +106,7 @@ export function visitorBringPage(ctx: Ctx): Response {
105106
106107 // POST /settings/bring
107108 export async function visitorBringSubmit(ctx: Ctx): Promise<Response> {
108 if (!ctx.auth.user) return signInFirst(ctx);
109 if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx);
109110 const form = await readForm(ctx, "admin");
110111 if (form instanceof Response) return form;
111112 const carry = carryOf(field(form, "carry"));
@@ -118,7 +119,7 @@ export async function visitorBringSubmit(ctx: Ctx): Promise<Response> {
118119
119120 // POST /settings/bring/:id/undo
120121 export async function visitorBringUndo(ctx: Ctx): Promise<Response> {
121 if (!ctx.auth.user) return signInFirst(ctx);
122 if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx);
122123 const form = await readForm(ctx, "admin");
123124 if (form instanceof Response) return form;
124125 const done = undoBrought(ctx.app, ctx.auth.user, ctx.params["id"] ?? "");
src/web/pages/visitors.ts +2 −1
@@ -17,6 +17,7 @@ import { flashTo } from "../layout.ts";
1717 import { TRAFFIC_TONES } from "../studio/kpi_row.ts";
1818 import { btn, row } from "../ui.ts";
1919 import { emptyList } from "../empty_words.ts";
20 import { adminPage } from "../../http/page_may.ts";
2021
2122 const W = 600;
2223 const H = 72;
@@ -110,7 +111,7 @@ export function visitorsBlock(ctx: Ctx, now: number): Html {
110111
111112 /** POST /settings/traffic/returning: an admin turns the setting on or off. */
112113 export async function returningSet(ctx: Ctx): Promise<Response> {
113 if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx);
114 if (ctx.auth.user === undefined || !adminPage(ctx, "visitors", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx);
114115 const form = await readForm(ctx, "admin");
115116 if (form instanceof Response) return form;
116117 const value = field(form, "returning");
src/web/pages/week.ts +2 −1
@@ -4,6 +4,7 @@
44 * proposals, each its own form: one tap by someone who writes here takes it,
55 * and nothing else on the page changes anything.
66 */
7 import { signedInPage } from "../../http/page_may.ts";
78 import { takeProposal } from "../../actions/week.ts";
89 import { emptyNote } from "../empty_words.ts";
910 import { whileFull, whileFullLine } from "../../checks/full_window_recheck.ts";
@@ -121,7 +122,7 @@ export function weekPage(ctx: Ctx): Response {
121122 export async function weekSubmit(ctx: Ctx): Promise<Response> {
122123 const repo = loadRepo(ctx);
123124 if (!repo) return notFoundPage(ctx);
124 if (!ctx.auth.user) return signInFirst(ctx);
125 if (!signedInPage(ctx, "week")) return signInFirst(ctx);
125126 const form = await readForm(ctx, "rw");
126127 if (form instanceof Response) return form;
127128 const dest = backTo(form, `${repoBase(repo)}/week`);

11 more files not shown.

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

Keyboard shortcuts

Docs