Public: anyone can read this; the crew can change it.
Access 3, web pages: the two known partings are decided, then each page's own isAdmin and sign-in check is deleted and may() alone decides #18430
Merged 11h 12m ago, live in production
mason/forge:mason/18424-access-3-web-pages-the-two-known-parting → main 0 commits fork
145 files
changed +596
−584
- docs/ROLES.md
- docs/features/may.md
- src/core/access_disagreement.ts
- src/design/door_checks.ts
- src/http/may_beside.ts
- src/http/page_may.ts
- src/web/pages/access.ts
- src/web/pages/account.ts
- src/web/pages/accounts.ts
- src/web/pages/admin-limits.ts
- src/web/pages/advisories.ts
- src/web/pages/app_templates.ts
- src/web/pages/app_variants.ts
- src/web/pages/apps.ts
- src/web/pages/archive.ts
- src/web/pages/audit.ts
- src/web/pages/backups.ts
- src/web/pages/billing.ts
- src/web/pages/board.ts
- src/web/pages/boards-index-stream.ts
- src/web/pages/boards-stream.ts
- src/web/pages/boards-view.ts
- src/web/pages/boards.ts
- src/web/pages/bottleneck.ts
- src/web/pages/branches.ts
- src/web/pages/builds.ts
- src/web/pages/capacity.ts
- src/web/pages/chain.ts
- src/web/pages/changelog.ts
- src/web/pages/chapters.ts
- src/web/pages/client_cloud.ts
- src/web/pages/cloud.ts
- src/web/pages/cockpit.ts
- src/web/pages/config.ts
- src/web/pages/confirms.ts
- src/web/pages/conflicts.ts
- src/web/pages/connections.ts
- src/web/pages/crew-settings.ts
- src/web/pages/crew.ts
- src/web/pages/data.ts
- src/web/pages/dataset.ts
- src/web/pages/displays.ts
- src/web/pages/economics.ts
- src/web/pages/edit.ts
- src/web/pages/everyday.ts
- src/web/pages/features.ts
- src/web/pages/first.ts
- src/web/pages/flags.ts
- src/web/pages/fleet-graph.ts
- src/web/pages/fleet-ops.ts
- src/web/pages/flow.ts
- src/web/pages/flows-all.ts
- src/web/pages/following.ts
- src/web/pages/forge-it.ts
- src/web/pages/forge-template-setting.ts
- src/web/pages/forge_machine.ts
- src/web/pages/forge_move_in.ts
- src/web/pages/forge_upgrade.ts
- src/web/pages/forges.ts
- src/web/pages/fork-flows.ts
- src/web/pages/games.ts
- src/web/pages/games_client_pack.ts
- src/web/pages/gate.ts
- src/web/pages/gifts.ts
- src/web/pages/global-map.ts
- src/web/pages/grants.ts
- src/web/pages/home_flow.ts
- src/web/pages/hosted-forges.ts
- src/web/pages/identities.ts
- src/web/pages/inventory.ts
- src/web/pages/issues.ts
- src/web/pages/iterations.ts
- src/web/pages/knobs.ts
- src/web/pages/limb.ts
- src/web/pages/maintenance.ts
- src/web/pages/maintenance_budgets.ts
- src/web/pages/migrate.ts
- src/web/pages/milestones.ts
- src/web/pages/model.ts
- src/web/pages/my-repos.ts
- src/web/pages/new-forge.ts
- src/web/pages/next.ts
- src/web/pages/next_all.ts
- src/web/pages/next_batch.ts
- src/web/pages/notes.ts
- src/web/pages/now.ts
- src/web/pages/oauth.ts
- src/web/pages/offer-receipt.ts
- src/web/pages/offer-upstream.ts
- src/web/pages/og.ts
- src/web/pages/org.ts
- src/web/pages/origin-reach.ts
- src/web/pages/origins.ts
- src/web/pages/packs-settings.ts
- src/web/pages/packs.ts
- src/web/pages/passkeys.ts
- src/web/pages/payments.ts
- src/web/pages/people.ts
- src/web/pages/proven_identities.ts
- src/web/pages/pull-guest.ts
docs/ROLES.md +8 −6
| @@ -112,13 +112,15 @@ small pack that expands when git reads it still costs CPU and memory. | ||
| 112 | 112 | |
| 113 | 113 | ## Inline checks in a moved door |
| 114 | 114 | |
| 115 | The repository routes under `src/http/api/` and the MCP tools (`src/http/mcp.ts`, | |
| 116 | `src/http/mcp/`) have moved to `may` (Access 3, #18406), so a new line in them | |
| 117 | that gates on `isAdmin`, on `scopeAllows(…, "rw")` or on `!ctx.auth.user` fails | |
| 115 | The repository routes under `src/http/api/`, the MCP tools (`src/http/mcp.ts`, | |
| 116 | `src/http/mcp/`) and the web pages (`src/web/pages/`) have moved to `may` (Access 3, | |
| 117 | #18406, #18424), so a new line in them that gates on `isAdmin`, on | |
| 118 | `scopeAllows(…, "rw")` or on `!ctx.auth.user` fails | |
| 118 | 119 | `test/door-inline-checks.test.ts`, which names the file and line and the helper to |
| 119 | ask instead: `adminPage` or `mayBeside(ctx, door, "forge.administer", old)` for an | |
| 120 | admin, `mayBeside(ctx, door, "forge.write", old)` (`mayToolWrite(ctx)` in the MCP) for | |
| 121 | a write, `signedInPage` for an account. Only gate shapes count: a role passed on | |
| 120 | ask instead: `adminPage(ctx)` or `personAdminPage(ctx)` on a page and | |
| 121 | `holds(db, principalOf(ctx.auth), "forge.administer")` on a route for an admin, | |
| 122 | `holds(db, principalOf(ctx.auth), "forge.write")` (`mayToolWrite(ctx)` in the MCP) for | |
| 123 | a write, `signedInPage(ctx)` for an account. Only gate shapes count: a role passed on | |
| 122 | 124 | for display is a read, and `scopeAllows(…, "admin")` is a token's reach, not a |
| 123 | 125 | role. The lines that stay are listed in `DOOR_LINES` (`src/design/door_checks.ts`), |
| 124 | 126 | each with a reason; the list only shrinks, because an entry whose line is gone |
docs/features/may.md +7 −7
| @@ -47,13 +47,13 @@ something asks `forge.write` with the credential you send, so an `ro` token is t | ||
| 47 | 47 | (`src/http/mcp/tool_may.ts`). The old scope floor was worked out beside it until the count under `mcp <tool>` held |
| 48 | 48 | nothing a request can make (#18405); `may`'s answer is now the only one. The terminal's "What I can do" lists `forge.write` with the rest. |
| 49 | 49 | |
| 50 | **The web pages ask it.** A page only the admin sees asks `forge.administer`, and a page that needs you signed in asks | |
| 51 | by what the request does: `forge.read` to open it (GET), `forge.write` to change something (POST), both with the | |
| 52 | credential you send (`src/http/page_may.ts`). An `ro` token that opens its own page is no parting; one that posts is. | |
| 53 | An anonymous visit to a signed-in page parts on `forge.read`, which is open to all: that row says the page needs more | |
| 54 | than reading. The page's old check (`isAdmin`, an account | |
| 55 | behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is | |
| 56 | `web <page>`, the page's module. Nothing you can open on the web changes while the count is read. | |
| 50 | **The web pages ask it alone.** Web pages have one access check: `may`, through `src/http/page_may.ts`, asked of the | |
| 51 | account behind the request. A page only the admin sees asks `forge.administer` (`adminPage`; `personAdminPage` where the | |
| 52 | page is a person's and an admin agent is turned away, as before), and a page that needs you signed in asks `forge.write` | |
| 53 | (`signedInPage`), which every account holds and nobody without one does: an anonymous visit is told `unauthorized` and | |
| 54 | sent to sign in, as before. A token's scope is judged where it was, by the form a change reads, so an `ro` token opens | |
| 55 | what its account opens and is refused the changes it was refused before. The pages' inline `isAdmin` and signed-in | |
| 56 | checks are gone (#18424), and `test/door-inline-checks.test.ts` keeps them gone from `src/web/pages/`. | |
| 57 | 57 | |
| 58 | 58 | **The infrastructure pages and the cloud API ask it alone.** Every `/infra` page and change, and |
| 59 | 59 | `GET /api/v1/cloud/accounts`, decide by `forge.administer` (`src/http/infra_routes.ts`, `src/http/api/cloud.ts`); |
src/core/access_disagreement.ts +2 −2
| @@ -35,8 +35,8 @@ export function noteDisagreement( | ||
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Ask `may` beside `old`, the answer of the check it is replacing, and count a parting under |
| 38 | * `door`: what every door in shadow does (`http/may_beside.ts`, the terminal's palette, the game | |
| 39 | * grants). Returns what `may` said; a door still in shadow keeps its old answer itself. | |
| 38 | * `door`: what every door in shadow does (the terminal's palette, the game grants). Returns what | |
| 39 | * `may` said; a door still in shadow keeps its old answer itself. | |
| 40 | 40 | */ |
| 41 | 41 | export function askBeside(db: Database, asking: Principal, door: string, action: Action, old: boolean, resource?: Resource): boolean { |
| 42 | 42 | const said = holds(db, asking, action, resource); |
src/design/door_checks.ts +20 −10
| @@ -2,10 +2,10 @@ | ||
| 2 | 2 | * The inline access check does not come back into a moved door (#18406, Access 3's last step). The |
| 3 | 3 | * repository routes under `src/http/api/`, the MCP tools (`src/http/mcp.ts`, `src/http/mcp/`), the |
| 4 | 4 | * infrastructure pages and the cloud API (`src/http/infra_routes.ts`, `src/http/api/cloud.ts`) |
| 5 | * now ask `may`; this ratchet reads their source and finds each line that gates on the account | |
| 6 | * inline: a refusal on `isAdmin` (`!user.isAdmin`, `isAdmin !== true`, or `isAdmin` in an `if`), a | |
| 7 | * `scopeAllows(…, "rw")` write floor, or a signed-out test (`!ctx.auth.user`, `ctx.auth.user === | |
| 8 | * undefined` in a condition). | |
| 5 | * and the web pages (`src/web/pages/`, #18424) now ask `may`; this ratchet reads their source and | |
| 6 | * finds each line that gates on the account inline: a refusal on `isAdmin` (`!user.isAdmin`, | |
| 7 | * `isAdmin !== true`, or `isAdmin` in an `if`), a `scopeAllows(…, "rw")` write floor, or a | |
| 8 | * signed-out test (`!ctx.auth.user`, `ctx.auth.user === undefined` in a condition). | |
| 9 | 9 | * |
| 10 | 10 | * Only gate shapes count: a role passed on for display (`familyView(app, user.isAdmin === true)`) |
| 11 | 11 | * is a read, not a door, and is not matched. `scopeAllows(…, "admin")` is how far a token reaches, |
| @@ -29,15 +29,15 @@ export interface DoorFound { | ||
| 29 | 29 | |
| 30 | 30 | /** What to ask instead, by the check found. */ |
| 31 | 31 | const HELPER: Record<DoorCheck, string> = { |
| 32 | isAdmin: `adminPage(ctx, door, old) or mayBeside(ctx, door, "forge.administer", old)`, | |
| 33 | scopeAllows: `mayBeside(ctx, door, "forge.write", old) (mayToolWrite in the MCP)`, | |
| 34 | signedOut: "signedInPage(ctx, door)", | |
| 32 | isAdmin: `adminPage(ctx) or personAdminPage(ctx) on a page, holds(db, principalOf(ctx.auth), "forge.administer") on a route`, | |
| 33 | scopeAllows: `holds(db, principalOf(ctx.auth), "forge.write") (mayToolWrite in the MCP)`, | |
| 34 | signedOut: "signedInPage(ctx)", | |
| 35 | 35 | }; |
| 36 | 36 | |
| 37 | 37 | /** The fix that ends each finding: which helper, or which list line to delete. */ |
| 38 | 38 | export const DOOR_FIX = { |
| 39 | 39 | newLine: (c: DoorCheck): string => |
| 40 | `Fix: ask ${HELPER[c]} (src/http/page_may.ts, src/http/may_beside.ts); never add the line to DOOR_LINES in src/design/door_checks.ts.`, | |
| 40 | `Fix: ask ${HELPER[c]} (src/http/page_may.ts, src/core/may.ts); never add the line to DOOR_LINES in src/design/door_checks.ts.`, | |
| 41 | 41 | gone: "Fix: the check is gone, so delete its entry from DOOR_LINES in src/design/door_checks.ts; lowering is the right move.", |
| 42 | 42 | } as const; |
| 43 | 43 | |
| @@ -63,12 +63,12 @@ const MOVED = new Set(["src/http/mcp.ts", "src/http/infra_routes.ts"]); | ||
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The files the moved doors live in: repository route modules and the cloud API under |
| 66 | * src/http/api, the infrastructure pages, and the MCP. | |
| 66 | * src/http/api, the infrastructure pages, the MCP, and the web pages. | |
| 67 | 67 | */ |
| 68 | 68 | export function doorSources(root: string): Source[] { |
| 69 | 69 | const api = tsSources(root, "src/http/api").filter((f) => f.text.includes("/api/v1/repos/") || f.path === "src/http/api/cloud.ts"); |
| 70 | 70 | const mcp = tsSources(root, "src/http").filter((f) => MOVED.has(f.path)); |
| 71 | return [...api, ...mcp, ...tsSources(root, "src/http/mcp")]; | |
| 71 | return [...api, ...mcp, ...tsSources(root, "src/http/mcp"), ...tsSources(root, "src/web/pages")]; | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** A line that keeps its inline check, by file and exact trimmed text, and why. Only shrinks. */ |
| @@ -80,6 +80,7 @@ export interface DoorLine { | ||
| 80 | 80 | |
| 81 | 81 | const NOT_ONLY_HERE = "an admin-only tool hidden as not found; moves when the tool's own rule asks may"; |
| 82 | 82 | const ADMIN_READ = "an admin-only read refused by name; moves when the tool's own rule asks may"; |
| 83 | const SHOWN = "the account shown, not the one asking"; | |
| 83 | 84 | |
| 84 | 85 | export const DOOR_LINES: readonly DoorLine[] = [ |
| 85 | 86 | { file: "src/http/api/issues.ts", text: "if (ctx.auth.user === undefined) {", why: "which door a stranger is shown, not whether they pass" }, |
| @@ -110,6 +111,15 @@ export const DOOR_LINES: readonly DoorLine[] = [ | ||
| 110 | 111 | { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads what it stands on");', why: ADMIN_READ }, |
| 111 | 112 | { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its off-site backup lane");', why: ADMIN_READ }, |
| 112 | 113 | { file: "src/http/mcp/tools/system.ts", text: 'if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its CSP violations");', why: ADMIN_READ }, |
| 114 | { file: "src/web/pages/home_flow.ts", text: "if (!isAdmin) return [];", why: "plain data in: the caller asked may and passes its answer" }, | |
| 115 | { file: "src/web/pages/home_flow.ts", text: "if (!viewer.isAdmin) return null;", why: "plain data in: the caller asked may and passes its answer" }, | |
| 116 | { file: "src/web/pages/everyday.ts", text: 'if (user.isAdmin && user.kind === "user") return everydayForm(ctx, user, false);', why: SHOWN }, | |
| 117 | { file: "src/web/pages/everyday.ts", text: 'if (!admin?.isAdmin) return new Response("not found", { status: 404 });', why: "the admin an everyday account is paired with, not the one asking" }, | |
| 118 | { file: "src/web/pages/repo.ts", text: "if (!isAdmin(ctx, repo)) return null;", why: "a repository's admin, asked through canAdmin" }, | |
| 119 | { file: "src/web/pages/accounts.ts", text: 'const actionable = a.kind === "user" && !a.isAdmin && a.removedAt === null;', why: SHOWN }, | |
| 120 | { file: "src/web/pages/accounts.ts", text: "const ordinary = !user.isAdmin;", why: SHOWN }, | |
| 121 | { file: "src/web/pages/new-forge.ts", text: "if (user?.isAdmin !== true || plans.every((p) => p.key === FREE)) return null;", why: "a render helper handed the account, which shows a field and gates nothing" }, | |
| 122 | { file: "src/web/pages/reports.ts", text: 'if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "rw"))', why: "a token's scope, judged where it was" }, | |
| 113 | 123 | ]; |
| 114 | 124 | |
| 115 | 125 | const key = (file: string, text: string): string => `${file}\n${text}`; |
src/http/may_beside.ts deleted −15
| @@ -1,15 +0,0 @@ | ||
| 1 | /** | |
| 2 | * `may` asked beside the check it is replacing (#18091, #18092, #18395): the principal the | |
| 3 | * request carries is asked `action`, and where its answer parts from `old` one row is counted in | |
| 4 | * `access_disagreement` under `door` (`core/access_disagreement.ts`). Returns what `may` said; a | |
| 5 | * door still in shadow returns its old answer itself. | |
| 6 | */ | |
| 7 | ||
| 8 | import { askBeside } from "../core/access_disagreement.ts"; | |
| 9 | import type { Action } from "../core/may.ts"; | |
| 10 | import { principalOf } from "../core/principal.ts"; | |
| 11 | import type { Ctx } from "./context.ts"; | |
| 12 | ||
| 13 | export function mayBeside(ctx: Ctx, door: string, action: Action, old: boolean): boolean { | |
| 14 | return askBeside(ctx.app.db, principalOf(ctx.auth), door, action, old); | |
| 15 | } |
src/http/page_may.ts +24 −26
| @@ -1,38 +1,36 @@ | ||
| 1 | 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. | |
| 2 | * The web pages' one access check (#18424, Access 3): `may` alone decides who opens a page, as it | |
| 3 | * does for `/infra` (`http/infra_routes.ts`). The inline `isAdmin` and signed-in checks the pages | |
| 4 | * held are gone, and `test/door-inline-checks.test.ts` keeps them gone. | |
| 7 | 5 | * |
| 6 | * `may` is asked of the account behind the request (`principalOfUser`), never of the token's scope: | |
| 7 | * a token's scope is judged where it was before, by the form a change reads | |
| 8 | * (`readForm(ctx, scope)`) or the action it calls, so nobody's access moved when the inline checks | |
| 9 | * went. | |
| 10 | * | |
| 11 | * - `signedInPage`: a page that needs an account asks `forge.write`, the action every account holds | |
| 12 | * over what is its own and nobody without one does (`may` says `unauthorized`). `forge.read` is | |
| 13 | * open to all, so asking it was the parting the shadow counted for an anonymous visit (#18400). | |
| 8 | 14 | * - `adminPage`: a page only the forge's admin sees asks `forge.administer`. |
| 9 | * - `signedInPage`: a page that needs an account asks by what the request does. A read (GET, HEAD) | |
| 10 | * asks `forge.read`, so an `ro` token that reads its own page is no parting; a write asks | |
| 11 | * `forge.write`, which an `ro` token is refused. An anonymous read parts on `forge.read` | |
| 12 | * (open to all) from the sign-in gate (accounts only): that is a real difference, and the row | |
| 13 | * says so. | |
| 15 | * - `personAdminPage`: the admin pages that are a person's, never an agent's, ask the same and that | |
| 16 | * the account is not an agent (an admin agent is refused there, as before). | |
| 14 | 17 | */ |
| 15 | 18 | |
| 16 | import type { Action } from "../core/may.ts"; | |
| 19 | import { holds, type Action } from "../core/may.ts"; | |
| 20 | import { principalOfUser } from "../core/principal.ts"; | |
| 17 | 21 | import type { User } from "../core/users.ts"; |
| 18 | 22 | 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 | 23 | |
| 30 | 24 | /** A request with an account behind it. */ |
| 31 | 25 | export type SignedIn = Ctx & { auth: Ctx["auth"] & { user: User } }; |
| 32 | 26 | |
| 33 | /** What a request to a page does, as `may` names it: reading, or a change. */ | |
| 34 | export const pageAction = (method: string): Action => (method === "GET" || method === "HEAD" ? "forge.read" : "forge.write"); | |
| 27 | const asks = (ctx: Ctx, action: Action): boolean => holds(ctx.app.db, principalOfUser(ctx.auth.user), action); | |
| 35 | 28 | |
| 36 | /** The sign-in gate of `page`: is there an account? Asked of `may` beside it. */ | |
| 37 | export const signedInPage = (ctx: Ctx, page: string): ctx is SignedIn => | |
| 38 | shadow(ctx, page, pageAction(ctx.request.method), ctx.auth.user !== undefined); | |
| 29 | /** Is there an account behind the request? `may` answers `forge.write` of it. */ | |
| 30 | export const signedInPage = (ctx: Ctx): ctx is SignedIn => asks(ctx, "forge.write"); | |
| 31 | ||
| 32 | /** Does the account behind the request administer the forge? */ | |
| 33 | export const adminPage = (ctx: Ctx): ctx is SignedIn => asks(ctx, "forge.administer"); | |
| 34 | ||
| 35 | /** The forge's admin, and a person rather than an agent: the admin pages that are a person's. */ | |
| 36 | export const personAdminPage = (ctx: Ctx): ctx is SignedIn => adminPage(ctx) && ctx.auth.user.kind !== "agent"; |
src/web/pages/access.ts +1 −1
| @@ -19,7 +19,7 @@ import { accountSections } from "./origins.ts"; | ||
| 19 | 19 | // GET /settings/access |
| 20 | 20 | export function accessPage(ctx: Ctx): Response { |
| 21 | 21 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 22 | if (!signedInPage(ctx, "access")) return signInFirst(ctx); | |
| 22 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 23 | 23 | const user = ctx.auth.user; |
| 24 | 24 | const ua = ctx.url.searchParams.get("ua")?.slice(0, 100) ?? ""; |
| 25 | 25 | const path = ctx.url.searchParams.get("path")?.slice(0, 200) ?? ""; |
src/web/pages/account.ts +27 −27
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | * has been read once. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { signedInPage } from "../../http/page_may.ts"; | |
| 12 | import { signedInPage, adminPage } from "../../http/page_may.ts"; | |
| 13 | 13 | import { UPSTREAM_REPO } from "../../core/upstream.ts"; |
| 14 | 14 | import { emptyNote } from "../empty_words.ts"; |
| 15 | 15 | import { resendVerification } from "../../actions/verify.ts"; |
| @@ -256,7 +256,7 @@ function dotfilesView(ctx: Ctx, error?: string): Html { | ||
| 256 | 256 | |
| 257 | 257 | // POST /settings/dotfiles |
| 258 | 258 | export async function dotfilesUpdate(ctx: Ctx): Promise<Response> { |
| 259 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 259 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 260 | 260 | const form = await readForm(ctx, "admin"); |
| 261 | 261 | if (form instanceof Response) return form; |
| 262 | 262 | const saved = setDotfilesRepo(ctx.app.db, ctx.auth.user, field(form, "repo")); |
| @@ -316,7 +316,7 @@ function parentLinkView(ctx: Ctx): Html { | ||
| 316 | 316 | |
| 317 | 317 | // POST /settings/parent/unlink |
| 318 | 318 | export async function parentUnlink(ctx: Ctx): Promise<Response> { |
| 319 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 319 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 320 | 320 | const form = await readForm(ctx, "admin"); |
| 321 | 321 | if (form instanceof Response) return form; |
| 322 | 322 | const issuer = parentIssuerOf(ctx.app.config); |
| @@ -329,7 +329,7 @@ export async function parentUnlink(ctx: Ctx): Promise<Response> { | ||
| 329 | 329 | |
| 330 | 330 | // POST /settings/edge/link |
| 331 | 331 | export async function edgeLink(ctx: Ctx): Promise<Response> { |
| 332 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 332 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 333 | 333 | const form = await readForm(ctx, "admin"); |
| 334 | 334 | if (form instanceof Response) return form; |
| 335 | 335 | const login = edgeIdentity(ctx.request, activeEdgeToken(ctx.app)); |
| @@ -353,7 +353,7 @@ export async function edgeLink(ctx: Ctx): Promise<Response> { | ||
| 353 | 353 | |
| 354 | 354 | // POST /settings/edge/unlink |
| 355 | 355 | export async function edgeUnlink(ctx: Ctx): Promise<Response> { |
| 356 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 356 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 357 | 357 | const form = await readForm(ctx, "admin"); |
| 358 | 358 | if (form instanceof Response) return form; |
| 359 | 359 | if (unlinkEdgeLogin(ctx.app.db, ctx.auth.user.id)) |
| @@ -384,7 +384,7 @@ function unverifiedNotice(ctx: Ctx): Html { | ||
| 384 | 384 | |
| 385 | 385 | // POST /settings/email/verify |
| 386 | 386 | export async function resendVerifyLink(ctx: Ctx): Promise<Response> { |
| 387 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 387 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 388 | 388 | const form = await readForm(ctx); |
| 389 | 389 | if (form instanceof Response) return form; |
| 390 | 390 | const sent = await resendVerification(ctx.app, ctx.auth.user); |
| @@ -596,7 +596,7 @@ export function appearancePage(ctx: Ctx): Response { | ||
| 596 | 596 | |
| 597 | 597 | // GET /settings/shells |
| 598 | 598 | export function shellsPage(ctx: Ctx): Response { |
| 599 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 599 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 600 | 600 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 601 | 601 | const body = html`${dotfilesView(ctx)}${shellsView(ctx, ctx.auth.user)}`; |
| 602 | 602 | return timePhase(ctx.request, "render", () => accountShell(ctx, "shells", "Shells", body)); |
| @@ -604,7 +604,7 @@ export function shellsPage(ctx: Ctx): Response { | ||
| 604 | 604 | |
| 605 | 605 | // POST /settings/shells/:id/stop |
| 606 | 606 | export async function shellStop(ctx: Ctx): Promise<Response> { |
| 607 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 607 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 608 | 608 | const form = await readForm(ctx, "admin"); |
| 609 | 609 | if (form instanceof Response) return form; |
| 610 | 610 | const id = ctx.params.id ?? ""; |
| @@ -614,7 +614,7 @@ export async function shellStop(ctx: Ctx): Promise<Response> { | ||
| 614 | 614 | |
| 615 | 615 | // POST /settings/shells/stop-idle |
| 616 | 616 | export async function shellsStopIdle(ctx: Ctx): Promise<Response> { |
| 617 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 617 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 618 | 618 | const form = await readForm(ctx, "admin"); |
| 619 | 619 | if (form instanceof Response) return form; |
| 620 | 620 | return flashTo(ctx, "/settings/shells", { message: stoppedIdleSays(stopIdleShells(ctx.app, ctx.auth.user.id)) }); |
| @@ -633,7 +633,7 @@ function hostedBackupRow(dataDir: string): Html | null { | ||
| 633 | 633 | |
| 634 | 634 | // GET /settings |
| 635 | 635 | export function accountPage(ctx: Ctx): Response { |
| 636 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 636 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 637 | 637 | const user = ctx.auth.user; |
| 638 | 638 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 639 | 639 | // Read in the order the page lays them out; each phase is named for what it reads. |
| @@ -665,7 +665,7 @@ export function accountPage(ctx: Ctx): Response { | ||
| 665 | 665 | |
| 666 | 666 | // POST /settings/notify |
| 667 | 667 | export async function notifyUpdate(ctx: Ctx): Promise<Response> { |
| 668 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 668 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 669 | 669 | const form = await readForm(ctx, "admin"); |
| 670 | 670 | if (form instanceof Response) return form; |
| 671 | 671 | const saved = setNotifyUrl(ctx.app.db, ctx.auth.user.id, field(form, "url")); |
| @@ -690,7 +690,7 @@ export async function notifyUpdate(ctx: Ctx): Promise<Response> { | ||
| 690 | 690 | |
| 691 | 691 | // POST /settings/focus |
| 692 | 692 | export async function focusUpdate(ctx: Ctx): Promise<Response> { |
| 693 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 693 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 694 | 694 | if (ctx.auth.user.kind !== "user") return forbiddenPage(ctx, "A focus is a person's, not an agent's."); |
| 695 | 695 | const form = await readForm(ctx, "admin"); |
| 696 | 696 | if (form instanceof Response) return form; |
| @@ -705,7 +705,7 @@ export async function focusUpdate(ctx: Ctx): Promise<Response> { | ||
| 705 | 705 | |
| 706 | 706 | // POST /settings |
| 707 | 707 | export async function accountUpdate(ctx: Ctx): Promise<Response> { |
| 708 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 708 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 709 | 709 | const form = await readForm(ctx, "admin"); |
| 710 | 710 | if (form instanceof Response) return form; |
| 711 | 711 | const displayName = field(form, "displayName").trim(); |
| @@ -786,7 +786,7 @@ function passwordView(error?: { | ||
| 786 | 786 | |
| 787 | 787 | // GET /settings/password |
| 788 | 788 | export function passwordPage(ctx: Ctx): Response { |
| 789 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 789 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 790 | 790 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 791 | 791 | const standing = closeStanding(ctx.app.db, ctx.auth.user.id); |
| 792 | 792 | const body = html`${passwordView()}${closeView(ctx, standing)}`; |
| @@ -796,7 +796,7 @@ export function passwordPage(ctx: Ctx): Response { | ||
| 796 | 796 | |
| 797 | 797 | // POST /settings/password |
| 798 | 798 | export async function passwordUpdate(ctx: Ctx): Promise<Response> { |
| 799 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 799 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 800 | 800 | const form = await readForm(ctx, "admin"); |
| 801 | 801 | if (form instanceof Response) return form; |
| 802 | 802 | const current = field(form, "current"); |
| @@ -915,7 +915,7 @@ function tokensView(ctx: Ctx): Html { | ||
| 915 | 915 | ); |
| 916 | 916 | // A site admin's token acts as admin whatever its scope (#596), |
| 917 | 917 | // so the list says so beside it (#12466). |
| 918 | const actsAsAdmin = ctx.auth.user!.isAdmin ? badge(ACTS_AS_ADMIN_WORDS) : null; | |
| 918 | const actsAsAdmin = adminPage(ctx) ? badge(ACTS_AS_ADMIN_WORDS) : null; | |
| 919 | 919 | const list = tokens.length === 0 |
| 920 | 920 | ? emptyNote("noAccessCodesYet") |
| 921 | 921 | : html`<ul class="list setting-list"> |
| @@ -979,7 +979,7 @@ function tokensView(ctx: Ctx): Html { | ||
| 979 | 979 | |
| 980 | 980 | // GET /settings/tokens |
| 981 | 981 | export function tokensPage(ctx: Ctx): Response { |
| 982 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 982 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 983 | 983 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 984 | 984 | const body = tokensView(ctx); |
| 985 | 985 | return timePhase(ctx.request, "render", () => accountShell(ctx, "tokens", "Access codes", body)); |
| @@ -987,7 +987,7 @@ export function tokensPage(ctx: Ctx): Response { | ||
| 987 | 987 | |
| 988 | 988 | // POST /settings/tokens |
| 989 | 989 | export async function tokenCreate(ctx: Ctx): Promise<Response> { |
| 990 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 990 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 991 | 991 | // Minting a token must come from the account itself — a browser session, |
| 992 | 992 | // the platform edge's sign-in, or the password — never from another token |
| 993 | 993 | // (no privilege bootstrapping). readForm below refuses a cross-site post. |
| @@ -998,7 +998,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> { | ||
| 998 | 998 | if (form instanceof Response) return form; |
| 999 | 999 | // A site admin's token acts as admin, whatever its scope: minted only on |
| 1000 | 1000 | // purpose (#596), never by a form left at its defaults. |
| 1001 | if (ctx.auth.user.isAdmin && field(form, "aiAdmin") !== "on") | |
| 1001 | if (adminPage(ctx) && field(form, "aiAdmin") !== "on") | |
| 1002 | 1002 | return flashTo(ctx, "/settings/tokens", { |
| 1003 | 1003 | tone: "danger", |
| 1004 | 1004 | message: "You are the forge's admin: tick that you mean to give this access code admin, or make it from your everyday account.", |
| @@ -1024,7 +1024,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> { | ||
| 1024 | 1024 | |
| 1025 | 1025 | // POST /settings/tokens/:id/delete |
| 1026 | 1026 | export async function tokenDelete(ctx: Ctx): Promise<Response> { |
| 1027 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1027 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1028 | 1028 | const form = await readForm(ctx, "admin"); |
| 1029 | 1029 | if (form instanceof Response) return form; |
| 1030 | 1030 | const revoked = deleteToken(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| @@ -1037,7 +1037,7 @@ export async function tokenDelete(ctx: Ctx): Promise<Response> { | ||
| 1037 | 1037 | |
| 1038 | 1038 | // POST /settings/sessions/:id/delete |
| 1039 | 1039 | export async function sessionDelete(ctx: Ctx): Promise<Response> { |
| 1040 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1040 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1041 | 1041 | const form = await readForm(ctx, "admin"); |
| 1042 | 1042 | if (form instanceof Response) return form; |
| 1043 | 1043 | const user = ctx.auth.user; |
| @@ -1056,7 +1056,7 @@ export async function sessionDelete(ctx: Ctx): Promise<Response> { | ||
| 1056 | 1056 | |
| 1057 | 1057 | // POST /settings/sessions/end-others |
| 1058 | 1058 | export async function sessionsOthersDelete(ctx: Ctx): Promise<Response> { |
| 1059 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1059 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1060 | 1060 | const form = await readForm(ctx, "admin"); |
| 1061 | 1061 | if (form instanceof Response) return form; |
| 1062 | 1062 | const done = signOutElsewhere(ctx.app, ctx.auth.user, cookieValue(ctx.request, "forge_session")); |
| @@ -1142,7 +1142,7 @@ function keysOff(ctx: Ctx): Response { | ||
| 1142 | 1142 | |
| 1143 | 1143 | // GET /settings/keys |
| 1144 | 1144 | export function keysPage(ctx: Ctx): Response { |
| 1145 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1145 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1146 | 1146 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1147 | 1147 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 1148 | 1148 | const body = keysView(ctx, { name: "", key: "" }); |
| @@ -1151,7 +1151,7 @@ export function keysPage(ctx: Ctx): Response { | ||
| 1151 | 1151 | |
| 1152 | 1152 | // POST /settings/keys |
| 1153 | 1153 | export async function keyCreate(ctx: Ctx): Promise<Response> { |
| 1154 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1154 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1155 | 1155 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1156 | 1156 | // A key outlives the token and opens the terminal, so an rw token is |
| 1157 | 1157 | // refused here as over the API and MCP (#14762); a session is admin. |
| @@ -1184,7 +1184,7 @@ export async function keyCreate(ctx: Ctx): Promise<Response> { | ||
| 1184 | 1184 | |
| 1185 | 1185 | // POST /settings/keys/:id/delete |
| 1186 | 1186 | export async function keyDelete(ctx: Ctx): Promise<Response> { |
| 1187 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1187 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1188 | 1188 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1189 | 1189 | // A key outlives the token and opens the terminal, so an rw token is |
| 1190 | 1190 | // refused here as over the API and MCP (#14762); a session is admin. |
| @@ -1278,7 +1278,7 @@ function closeRefused(ctx: Ctx, said: CloseSaid): Response { | ||
| 1278 | 1278 | |
| 1279 | 1279 | // POST /settings/account/close |
| 1280 | 1280 | export async function accountClose(ctx: Ctx): Promise<Response> { |
| 1281 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1281 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1282 | 1282 | if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF); |
| 1283 | 1283 | const user = ctx.auth.user; |
| 1284 | 1284 | const form = await readForm(ctx, "admin"); |
| @@ -1304,7 +1304,7 @@ const CLOSE_ITSELF = "Closing an account, or keeping it, is asked from the accou | ||
| 1304 | 1304 | |
| 1305 | 1305 | // POST /settings/account/keep |
| 1306 | 1306 | export async function accountKeep(ctx: Ctx): Promise<Response> { |
| 1307 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1307 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1308 | 1308 | if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF); |
| 1309 | 1309 | const form = await readForm(ctx, "admin"); |
| 1310 | 1310 | if (form instanceof Response) return form; |
src/web/pages/accounts.ts +15 −15
| @@ -141,8 +141,8 @@ function wayBackForms(ctx: Ctx): Html | null { | ||
| 141 | 141 | |
| 142 | 142 | // POST /settings/accounts/:username/way-back — the link, shown once on the page. |
| 143 | 143 | export async function wayBackAct(ctx: Ctx): Promise<Response> { |
| 144 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 145 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 144 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 145 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 146 | 146 | const form = await readForm(ctx, "admin"); |
| 147 | 147 | if (form instanceof Response) return form; |
| 148 | 148 | const username = ctx.params.username ?? ""; |
| @@ -179,7 +179,7 @@ export function accountsPage(ctx: Ctx): Response { | ||
| 179 | 179 | |
| 180 | 180 | /** The page, with what an act needs said first (`notice`) when it did not finish. */ |
| 181 | 181 | function accountsView(ctx: Ctx, notice?: Html, status = 200): Response { |
| 182 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 182 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 183 | 183 | const user = ctx.auth.user; |
| 184 | 184 | const listed = timePhase(ctx.request, "accounts", () => |
| 185 | 185 | listAccounts(ctx.app, user), |
| @@ -340,8 +340,8 @@ function isOtherAdmin(ctx: Ctx, username: string): boolean { | ||
| 340 | 340 | |
| 341 | 341 | // GET /settings/accounts/:username — one person, on one screen, with what an admin may do |
| 342 | 342 | export function personSignInsPage(ctx: Ctx): Response { |
| 343 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 344 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 343 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 344 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 345 | 345 | const username = ctx.params.username ?? ""; |
| 346 | 346 | const named = getUserByName(ctx.app.db, username); |
| 347 | 347 | // An organization has no sign-ins: its page is its model grant and spend ceilings. |
| @@ -441,8 +441,8 @@ export function personSignInsPage(ctx: Ctx): Response { | ||
| 441 | 441 | // POST /settings/accounts/:username/(reset|end-sessions) |
| 442 | 442 | export function accessAct(act: "reset" | "end-sessions") { |
| 443 | 443 | return async (ctx: Ctx): Promise<Response> => { |
| 444 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 445 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 444 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 445 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 446 | 446 | const form = await readForm(ctx, "admin"); |
| 447 | 447 | if (form instanceof Response) return form; |
| 448 | 448 | const username = ctx.params.username ?? ""; |
| @@ -468,8 +468,8 @@ export function accessAct(act: "reset" | "end-sessions") { | ||
| 468 | 468 | // POST /settings/accounts/:username/(tokens|sessions)/:id/delete |
| 469 | 469 | export function signInAct(what: "token" | "session") { |
| 470 | 470 | return async (ctx: Ctx): Promise<Response> => { |
| 471 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 472 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 471 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 472 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 473 | 473 | const form = await readForm(ctx, "admin"); |
| 474 | 474 | if (form instanceof Response) return form; |
| 475 | 475 | const username = ctx.params.username ?? ""; |
| @@ -503,8 +503,8 @@ const DONE: Readonly<Record<Act, string>> = { | ||
| 503 | 503 | // POST /settings/accounts/:username/(suspend|unsuspend|remove) |
| 504 | 504 | export function accountAct(act: Act) { |
| 505 | 505 | return async (ctx: Ctx): Promise<Response> => { |
| 506 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 507 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 506 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 507 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 508 | 508 | const form = await readForm(ctx, "admin"); |
| 509 | 509 | if (form instanceof Response) return form; |
| 510 | 510 | const username = ctx.params.username ?? ""; |
| @@ -548,8 +548,8 @@ export function accountAct(act: Act) { | ||
| 548 | 548 | |
| 549 | 549 | // GET /settings/accounts/:username/retire — everything removal would take; removes nothing |
| 550 | 550 | export function retirePage(ctx: Ctx): Response { |
| 551 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 552 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 551 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 552 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 553 | 553 | const username = ctx.params.username ?? ""; |
| 554 | 554 | const plan = retirementPlan(ctx.app, ctx.auth.user, username); |
| 555 | 555 | if (!plan.ok) |
| @@ -606,8 +606,8 @@ export function retirePage(ctx: Ctx): Response { | ||
| 606 | 606 | |
| 607 | 607 | // POST /settings/accounts/:username/retire |
| 608 | 608 | export async function retireAct(ctx: Ctx): Promise<Response> { |
| 609 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 610 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 609 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 610 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 611 | 611 | const form = await readForm(ctx, "admin"); |
| 612 | 612 | if (form instanceof Response) return form; |
| 613 | 613 | const username = ctx.params.username ?? ""; |
src/web/pages/admin-limits.ts +8 −8
| @@ -29,7 +29,7 @@ import { btn, confirmAction, icon, row, time } from "../ui.ts"; | ||
| 29 | 29 | import { emptyList } from "../empty_words.ts"; |
| 30 | 30 | import { plansRow } from "../settings/plans.ts"; |
| 31 | 31 | import { accountSections } from "./origins.ts"; |
| 32 | import { adminPage } from "../../http/page_may.ts"; | |
| 32 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 33 | 33 | |
| 34 | 34 | // GET /admin/limits |
| 35 | 35 | export function limitsPage(ctx: Ctx): Response { |
| @@ -258,7 +258,7 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 258 | 258 | // POST /admin/limits |
| 259 | 259 | export async function limitsSet(ctx: Ctx): Promise<Response> { |
| 260 | 260 | // Checked before the body is read: a non-admin learns nothing of the door. |
| 261 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 261 | if (!personAdminPage(ctx)) | |
| 262 | 262 | return notFoundPage(ctx); |
| 263 | 263 | const form = await readForm(ctx, "admin"); |
| 264 | 264 | if (form instanceof Response) return form; |
| @@ -294,7 +294,7 @@ export async function limitsSet(ctx: Ctx): Promise<Response> { | ||
| 294 | 294 | |
| 295 | 295 | // POST /admin/quotas |
| 296 | 296 | export async function quotasSet(ctx: Ctx): Promise<Response> { |
| 297 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 297 | if (!personAdminPage(ctx)) | |
| 298 | 298 | return notFoundPage(ctx); |
| 299 | 299 | const form = await readForm(ctx, "admin"); |
| 300 | 300 | if (form instanceof Response) return form; |
| @@ -315,7 +315,7 @@ export async function quotasSet(ctx: Ctx): Promise<Response> { | ||
| 315 | 315 | |
| 316 | 316 | // POST /admin/signup |
| 317 | 317 | export async function signupSet(ctx: Ctx): Promise<Response> { |
| 318 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 318 | if (!personAdminPage(ctx)) | |
| 319 | 319 | return notFoundPage(ctx); |
| 320 | 320 | const form = await readForm(ctx, "admin"); |
| 321 | 321 | if (form instanceof Response) return form; |
| @@ -332,7 +332,7 @@ export async function signupSet(ctx: Ctx): Promise<Response> { | ||
| 332 | 332 | |
| 333 | 333 | // POST /admin/agent-start |
| 334 | 334 | export async function agentStartSet(ctx: Ctx): Promise<Response> { |
| 335 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 335 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 336 | 336 | const form = await readForm(ctx, "admin"); |
| 337 | 337 | if (form instanceof Response) return form; |
| 338 | 338 | const changed = changeAgentStart(ctx.app, ctx.auth.user, field(form, "agent_start")); |
| @@ -348,7 +348,7 @@ export async function agentStartSet(ctx: Ctx): Promise<Response> { | ||
| 348 | 348 | |
| 349 | 349 | // POST /admin/billing-links |
| 350 | 350 | export async function billingLinksSet(ctx: Ctx): Promise<Response> { |
| 351 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 351 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 352 | 352 | const form = await readForm(ctx, "admin"); |
| 353 | 353 | if (form instanceof Response) return form; |
| 354 | 354 | const changed = changeBillingLinks( |
| @@ -368,7 +368,7 @@ export async function billingLinksSet(ctx: Ctx): Promise<Response> { | ||
| 368 | 368 | |
| 369 | 369 | // POST /admin/invites |
| 370 | 370 | export async function inviteMint(ctx: Ctx): Promise<Response> { |
| 371 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 371 | if (!personAdminPage(ctx)) | |
| 372 | 372 | return notFoundPage(ctx); |
| 373 | 373 | const form = await readForm(ctx, "admin"); |
| 374 | 374 | if (form instanceof Response) return form; |
| @@ -390,7 +390,7 @@ export async function inviteMint(ctx: Ctx): Promise<Response> { | ||
| 390 | 390 | |
| 391 | 391 | // POST /admin/invites/:id/revoke |
| 392 | 392 | export async function inviteRevoke(ctx: Ctx): Promise<Response> { |
| 393 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 393 | if (!personAdminPage(ctx)) | |
| 394 | 394 | return notFoundPage(ctx); |
| 395 | 395 | const form = await readForm(ctx, "admin"); |
| 396 | 396 | if (form instanceof Response) return form; |
src/web/pages/advisories.ts +2 −2
| @@ -14,10 +14,10 @@ import { field, readForm } from "../form.ts"; | ||
| 14 | 14 | import { html } from "../html.ts"; |
| 15 | 15 | import { flashTo, page } from "../layout.ts"; |
| 16 | 16 | import { badge, btn, disclosure, empty, listCard, row } from "../ui.ts"; |
| 17 | import { adminPage } from "../../http/page_may.ts"; | |
| 17 | import { personAdminPage, signedInPage } from "../../http/page_may.ts"; | |
| 18 | 18 | |
| 19 | 19 | const gate = (ctx: Ctx): Response | undefined => |
| 20 | !ctx.auth.user ? signInFirst(ctx) : adminPage(ctx, "advisories", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx); | |
| 20 | !signedInPage(ctx) ? signInFirst(ctx) : personAdminPage(ctx) ? undefined : notFoundPage(ctx); | |
| 21 | 21 | |
| 22 | 22 | const line = (a: Seen) => |
| 23 | 23 | row({ |
src/web/pages/app_templates.ts +3 −4
| @@ -15,12 +15,11 @@ import { flashTo, page } from "../layout.ts"; | ||
| 15 | 15 | import { btn, empty, field as formField, icon, row } from "../ui.ts"; |
| 16 | 16 | import { emptyLine } from "../empty_words.ts"; |
| 17 | 17 | import { accountSections } from "./origins.ts"; |
| 18 | import { adminPage } from "../../http/page_may.ts"; | |
| 18 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 19 | 19 | |
| 20 | 20 | function denied(ctx: Ctx): Response | undefined { |
| 21 | const user = ctx.auth.user; | |
| 22 | if (!user) return signInFirst(ctx); | |
| 23 | if (adminPage(ctx, "app_templates", user.isAdmin && user.kind === "user")) return undefined; | |
| 21 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 22 | if (adminPage(ctx) && ctx.auth.user.kind === "user") return undefined; | |
| 24 | 23 | return page( |
| 25 | 24 | { |
| 26 | 25 | ctx, |
src/web/pages/app_variants.ts +1 −1
| @@ -99,7 +99,7 @@ type Verb = (ctx: Ctx, repo: NonNullable<ReturnType<typeof loadRepo>>, form: For | ||
| 99 | 99 | async function mutate(ctx: Ctx, verb: Verb): Promise<Response> { |
| 100 | 100 | const repo = loadRepo(ctx); |
| 101 | 101 | if (!repo) return notFoundPage(ctx); |
| 102 | if (!signedInPage(ctx, "app_variants")) return signInFirst(ctx); | |
| 102 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 103 | 103 | const form = await readForm(ctx, "rw"); |
| 104 | 104 | if (form instanceof Response) return form; |
| 105 | 105 | return verb(ctx, repo, form); |
src/web/pages/apps.ts +4 −4
| @@ -438,7 +438,7 @@ function newAppForm( | ||
| 438 | 438 | |
| 439 | 439 | // GET /apps/new |
| 440 | 440 | export async function newAppPage(ctx: Ctx): Promise<Response> { |
| 441 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 441 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 442 | 442 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 443 | 443 | const picks = plannerOffered(ctx); |
| 444 | 444 | const offered = await timePhaseAsync(ctx.request, "templates", () => templateChoices(ctx.app, ctx.auth.user)); |
| @@ -462,7 +462,7 @@ export async function newAppPage(ctx: Ctx): Promise<Response> { | ||
| 462 | 462 | |
| 463 | 463 | // POST /apps/new |
| 464 | 464 | export async function newAppSubmit(ctx: Ctx): Promise<Response> { |
| 465 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 465 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 466 | 466 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 467 | 467 | const form = await readForm(ctx, "rw"); |
| 468 | 468 | if (form instanceof Response) return form; |
| @@ -814,7 +814,7 @@ function appsOpenResponse(ctx: Ctx): Response { | ||
| 814 | 814 | // up: a private app and a name nobody holds answer alike (#13678). |
| 815 | 815 | const target = resolveAppHostname(ctx.app, runtime.options.domain, host); |
| 816 | 816 | if (target === undefined) return notFoundPage(ctx); |
| 817 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 817 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 818 | 818 | if (target === "unknown") return notFoundPage(ctx); |
| 819 | 819 | const repo = getRepoById(ctx.app.db, target.app.repoId); |
| 820 | 820 | if (!repo) return notFoundPage(ctx); |
| @@ -865,7 +865,7 @@ async function envForm( | ||
| 865 | 865 | ): Promise<{ repo: Repo; env: string; user: User } | Response> { |
| 866 | 866 | const repo = loadRepo(ctx); |
| 867 | 867 | if (!repo) return notFoundPage(ctx); |
| 868 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 868 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 869 | 869 | const form = await readForm(ctx, "rw"); |
| 870 | 870 | if (form instanceof Response) return form; |
| 871 | 871 | return { repo, env: ctx.params.env ?? "", user: ctx.auth.user }; |
src/web/pages/archive.ts +2 −1
| @@ -19,6 +19,7 @@ import { html, type Html } from "../html.ts"; | ||
| 19 | 19 | import { page, redirect } from "../layout.ts"; |
| 20 | 20 | import { time } from "../time_element.ts"; |
| 21 | 21 | import { btn, row, rowList } from "../ui.ts"; |
| 22 | import { signedInPage } from "../../http/page_may.ts"; | |
| 22 | 23 | |
| 23 | 24 | const KIND_WORD: Record<ArchivedKind, string> = { app: "app", repository: "repository", conversation: "conversation" }; |
| 24 | 25 | |
| @@ -84,8 +85,8 @@ async function move(ctx: Ctx, user: User, kind: string, id: string, archived: bo | ||
| 84 | 85 | |
| 85 | 86 | /** The two posts: unarchive (its receipt's Undo archives again) and its undo. */ |
| 86 | 87 | async function archivePost(ctx: Ctx, archived: boolean): Promise<Response> { |
| 88 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 87 | 89 | const user = ctx.auth.user; |
| 88 | if (!user) return signInFirst(ctx); | |
| 89 | 90 | const form = await readForm(ctx, "admin"); |
| 90 | 91 | if (form instanceof Response) return form; |
| 91 | 92 | const kind = String(form.get("kind") ?? ""); |
src/web/pages/audit.ts +1 −1
| @@ -385,7 +385,7 @@ export async function auditCsv(ctx: Ctx): Promise<Response> { | ||
| 385 | 385 | export async function auditProbeSubmit(ctx: Ctx): Promise<Response> { |
| 386 | 386 | const repo = loadRepo(ctx); |
| 387 | 387 | if (!repo) return notFoundPage(ctx); |
| 388 | if (!signedInPage(ctx, "audit")) return signInFirst(ctx); | |
| 388 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 389 | 389 | const form = await readForm(ctx, "rw"); |
| 390 | 390 | if (form instanceof Response) return form; |
| 391 | 391 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) |
src/web/pages/backups.ts +6 −6
| @@ -57,8 +57,8 @@ import { badge, btn, fileSize, icon, row, time } from "../ui.ts"; | ||
| 57 | 57 | import { accountSections } from "./origins.ts"; |
| 58 | 58 | |
| 59 | 59 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 60 | if (!signedInPage(ctx, "backups")) return signInFirst(ctx); | |
| 61 | if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 60 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 61 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 62 | 62 | return undefined; |
| 63 | 63 | } |
| 64 | 64 | |
| @@ -227,7 +227,7 @@ function drilled(d: ResilienceRow): Html { | ||
| 227 | 227 | |
| 228 | 228 | /** Each failure domain and its last drill; nothing when the viewer may not read them. */ |
| 229 | 229 | function domainsCard(ctx: Ctx): Html | null { |
| 230 | if (!ctx.auth.user) return null; | |
| 230 | if (!signedInPage(ctx)) return null; | |
| 231 | 231 | const listed = listResilience(ctx.app, ctx.auth.user); |
| 232 | 232 | if (!listed.ok) return null; |
| 233 | 233 | const rows = listed.value.map((d) => { |
| @@ -291,7 +291,7 @@ export async function backupsPage(ctx: Ctx): Promise<Response> { | ||
| 291 | 291 | |
| 292 | 292 | /** GET /settings/backups/live — the moving part alone, which the page refetches on an event. */ |
| 293 | 293 | export async function backupsLive(ctx: Ctx): Promise<Response> { |
| 294 | if (!adminPage(ctx, "backups", ctx.auth.user?.isAdmin === true)) return fragment(html``, { status: 404 }); | |
| 294 | if (!adminPage(ctx)) return fragment(html``, { status: 404 }); | |
| 295 | 295 | const svc = snapshotsOf(ctx.app); |
| 296 | 296 | if (svc === undefined || svc.store === undefined) return fragment(html``, { status: 404 }); |
| 297 | 297 | return fragment(await movingPart(ctx, svc, svc.store), { request: ctx.request }); |
| @@ -657,8 +657,8 @@ export function lanesCard(ctx: Ctx): Html | "" { | ||
| 657 | 657 | |
| 658 | 658 | /** POST /settings/backups/drill — restore the newest snapshot, keep what came of it. */ |
| 659 | 659 | export async function backupsDrill(ctx: Ctx): Promise<Response> { |
| 660 | if (!signedInPage(ctx, "backups")) return signInFirst(ctx); | |
| 661 | if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) | |
| 660 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 661 | if (!adminPage(ctx)) | |
| 662 | 662 | return new Response("Forbidden", { |
| 663 | 663 | status: 403, |
| 664 | 664 | headers: { "content-type": "text/plain; charset=utf-8" }, |
src/web/pages/billing.ts +15 −17
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * Anyone else gets the not-found page. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 8 | import { signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 9 | 9 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 10 | import { emptyNote } from "../empty_words.ts"; |
| 11 | 11 | import { ledBlock } from "./visitors.ts"; |
| @@ -44,8 +44,6 @@ interface Shown { | ||
| 44 | 44 | readonly link: string; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | const isPerson = (ctx: Ctx): boolean => ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent"; | |
| 48 | ||
| 49 | 47 | const day = (iso: string): string => iso.slice(0, 10); |
| 50 | 48 | |
| 51 | 49 | /** The Codes section: make one, copy it once, then one line per code with its one action. */ |
| @@ -109,7 +107,7 @@ const codeWords = (e: CodeError): string => (e === "not_found" ? "Not found" : C | ||
| 109 | 107 | * not a loss. |
| 110 | 108 | */ |
| 111 | 109 | function soldSection(ctx: Ctx): Html | null { |
| 112 | if (!isPerson(ctx)) return null; | |
| 110 | if (!personAdminPage(ctx)) return null; | |
| 113 | 111 | const sold = soldRows(ctx.app.db); |
| 114 | 112 | if (sold.length === 0) return null; |
| 115 | 113 | return html`<section class="settings-block" id="sold" data-sold> |
| @@ -148,7 +146,7 @@ function linksSection(ctx: Ctx, r: Refused | undefined): Html | null { | ||
| 148 | 146 | |
| 149 | 147 | /** The one billing-portal address every paying forge's Plan row links to. */ |
| 150 | 148 | function portalSection(ctx: Ctx, r: Refused | undefined): Html | null { |
| 151 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return null; | |
| 149 | if (!personAdminPage(ctx)) return null; | |
| 152 | 150 | return html`<section class="settings-block" id="portal"> |
| 153 | 151 | <h2>Billing portal</h2> |
| 154 | 152 | <p class="muted small">Stripe's customer-portal sign-in. A forge that pays through Stripe links its owner here to change a card; empty shows no link.</p> |
| @@ -161,7 +159,7 @@ function portalSection(ctx: Ctx, r: Refused | undefined): Html | null { | ||
| 161 | 159 | |
| 162 | 160 | // POST /settings/billing/portal |
| 163 | 161 | export async function billingSetPortal(ctx: Ctx): Promise<Response> { |
| 164 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 162 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 165 | 163 | const form = await readForm(ctx, "admin"); |
| 166 | 164 | if (form instanceof Response) return form; |
| 167 | 165 | const value = field(form, "portal_url"); |
| @@ -173,7 +171,7 @@ export async function billingSetPortal(ctx: Ctx): Promise<Response> { | ||
| 173 | 171 | |
| 174 | 172 | // POST /settings/billing/links |
| 175 | 173 | export async function billingSetLinks(ctx: Ctx): Promise<Response> { |
| 176 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 174 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 177 | 175 | const form = await readForm(ctx, "admin"); |
| 178 | 176 | if (form instanceof Response) return form; |
| 179 | 177 | const current = readBillingLinks(ctx.app, ctx.auth.user); |
| @@ -216,7 +214,7 @@ function lapseWords(l: Lapse): string { | ||
| 216 | 214 | // GET /settings/billing |
| 217 | 215 | export function billingPage(ctx: Ctx): Response { |
| 218 | 216 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 219 | if (!signedInPage(ctx, "billing")) return signInFirst(ctx); | |
| 217 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 220 | 218 | return billingView(ctx); |
| 221 | 219 | } |
| 222 | 220 | |
| @@ -313,7 +311,7 @@ function billingView(ctx: Ctx, shown?: Shown, status = 200, refusal?: Refused): | ||
| 313 | 311 | |
| 314 | 312 | // POST /settings/billing/codes |
| 315 | 313 | export async function billingMakeCode(ctx: Ctx): Promise<Response> { |
| 316 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 314 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 317 | 315 | const form = await readForm(ctx, "admin"); |
| 318 | 316 | if (form instanceof Response) return form; |
| 319 | 317 | const values = { kind: field(form, "kind"), plan: field(form, "plan"), uses: field(form, "uses"), note: field(form, "note"), expires: field(form, "expires") }; |
| @@ -324,7 +322,7 @@ export async function billingMakeCode(ctx: Ctx): Promise<Response> { | ||
| 324 | 322 | |
| 325 | 323 | // POST /settings/billing/codes/revoke |
| 326 | 324 | export async function billingRevokeCode(ctx: Ctx): Promise<Response> { |
| 327 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 325 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 328 | 326 | const form = await readForm(ctx, "admin"); |
| 329 | 327 | if (form instanceof Response) return form; |
| 330 | 328 | const done = revoke(ctx.app, ctx.auth.user, field(form, "id")); |
| @@ -362,14 +360,14 @@ function changeView(ctx: Ctx, forge: string, plan: string, refused = false): Res | ||
| 362 | 360 | |
| 363 | 361 | // GET /settings/billing/change?forge=&plan= — the preview, before the confirm. |
| 364 | 362 | export function billingChange(ctx: Ctx): Response { |
| 365 | if (!signedInPage(ctx, "billing")) return signInFirst(ctx); | |
| 366 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 363 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 364 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 367 | 365 | return changeView(ctx, ctx.url.searchParams.get("forge") ?? "", ctx.url.searchParams.get("plan") ?? ""); |
| 368 | 366 | } |
| 369 | 367 | |
| 370 | 368 | // POST /settings/billing/grant — the confirm: it must carry what the preview showed. |
| 371 | 369 | export async function billingGrant(ctx: Ctx): Promise<Response> { |
| 372 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 370 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 373 | 371 | const form = await readForm(ctx, "admin"); |
| 374 | 372 | if (form instanceof Response) return form; |
| 375 | 373 | const forge = field(form, "forge"); |
| @@ -389,7 +387,7 @@ const back = (ctx: Ctx, r: { ok: true; message: string } | { ok: false; error: B | ||
| 389 | 387 | |
| 390 | 388 | // POST /settings/billing/stripe/connect |
| 391 | 389 | export async function stripeConnect(ctx: Ctx): Promise<Response> { |
| 392 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 390 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 393 | 391 | const form = await readForm(ctx, "admin"); |
| 394 | 392 | if (form instanceof Response) return form; |
| 395 | 393 | const r = await connectStripe(ctx.app, ctx.auth.user, field(form, "key"), field(form, "secret")); |
| @@ -398,7 +396,7 @@ export async function stripeConnect(ctx: Ctx): Promise<Response> { | ||
| 398 | 396 | |
| 399 | 397 | // POST /settings/billing/stripe/secret |
| 400 | 398 | export async function stripeSecret(ctx: Ctx): Promise<Response> { |
| 401 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 399 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 402 | 400 | const form = await readForm(ctx, "admin"); |
| 403 | 401 | if (form instanceof Response) return form; |
| 404 | 402 | const r = saveSigningSecret(ctx.app, ctx.auth.user, field(form, "secret")); |
| @@ -407,7 +405,7 @@ export async function stripeSecret(ctx: Ctx): Promise<Response> { | ||
| 407 | 405 | |
| 408 | 406 | // POST /settings/billing/stripe/disconnect |
| 409 | 407 | export async function stripeDisconnect(ctx: Ctx): Promise<Response> { |
| 410 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 408 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 411 | 409 | const form = await readForm(ctx, "admin"); |
| 412 | 410 | if (form instanceof Response) return form; |
| 413 | 411 | const r = await disconnectStripe(ctx.app, ctx.auth.user); |
| @@ -417,7 +415,7 @@ export async function stripeDisconnect(ctx: Ctx): Promise<Response> { | ||
| 417 | 415 | // POST /settings/billing/orders/retry — an admin who is a person retries a paid order whose forge |
| 418 | 416 | // was not made. |
| 419 | 417 | export async function orderRetry(ctx: Ctx): Promise<Response> { |
| 420 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 418 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 421 | 419 | const form = await readForm(ctx, "admin"); |
| 422 | 420 | if (form instanceof Response) return form; |
| 423 | 421 | const r = await retryOrder(ctx.app, ctx.auth.user, field(form, "id")); |
src/web/pages/board.ts +6 −5
| @@ -128,6 +128,7 @@ import { appsRuntime } from "../../apps/runtime_registry.ts"; | ||
| 128 | 128 | import { lookUrl } from "../../core/looks.ts"; |
| 129 | 129 | import { thumbLook } from "./looks.ts"; |
| 130 | 130 | import { milestoneHref } from "./milestones.ts"; |
| 131 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 131 | 132 | |
| 132 | 133 | // ---- words ---- |
| 133 | 134 | |
| @@ -241,8 +242,8 @@ export async function boardPage(ctx: Ctx): Promise<Response> { | ||
| 241 | 242 | // The kiosk is the cockpit (#1152): one screen, four keys, no top bar. |
| 242 | 243 | if (ctx.url.searchParams.has("kiosk")) return cockpitPage(ctx, true); |
| 243 | 244 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 245 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 244 | 246 | const user = ctx.auth.user; |
| 245 | if (!user) return signInFirst(ctx); | |
| 246 | 247 | const db = ctx.app.db; |
| 247 | 248 | const rq = ctx.request; |
| 248 | 249 | const visible = timePhase(rq, "repos", () => listReposVisibleTo(db, user, { limit: 200 })); |
| @@ -427,7 +428,7 @@ function moneyStrip(ctx: Ctx): Html | null { | ||
| 427 | 428 | * cloud body is configured. Nobody else pays for the reads. |
| 428 | 429 | */ |
| 429 | 430 | function forgeNotes(ctx: Ctx): { notes: Note[]; ok: boolean; placement: Html | null } | null { |
| 430 | if (!ctx.auth.user?.isAdmin) return null; | |
| 431 | if (!adminPage(ctx)) return null; | |
| 431 | 432 | const v = forgeVitals(ctx.app); |
| 432 | 433 | const fh = forgeHealth(); |
| 433 | 434 | const verdict = forgeVerdict(fh, Date.now()); |
| @@ -504,8 +505,8 @@ function reviewNotes(ctx: Ctx, scope: BoardScope): Note[] { | ||
| 504 | 505 | * anything has asked. |
| 505 | 506 | */ |
| 506 | 507 | function asksStrip(ctx: Ctx): Html | null { |
| 508 | if (!signedInPage(ctx)) return null; | |
| 507 | 509 | const user = ctx.auth.user; |
| 508 | if (!user) return null; | |
| 509 | 510 | const m = askMeasureWeek(ctx.app.db, user.id); |
| 510 | 511 | if (asksMeasureEmpty(m)) return null; |
| 511 | 512 | return html`<a class="muted small" id="asks-measure" href="/?waits=me" |
| @@ -528,8 +529,8 @@ function asksStrip(ctx: Ctx): Html | null { | ||
| 528 | 529 | * viewer holds no owner facts here or nothing ran. |
| 529 | 530 | */ |
| 530 | 531 | function returnsStrip(ctx: Ctx, scope: BoardScope): Html | null { |
| 532 | if (!signedInPage(ctx)) return null; | |
| 531 | 533 | const user = ctx.auth.user; |
| 532 | if (!user) return null; | |
| 533 | 534 | // The crew spends on every repository, app or not: the whole of the |
| 534 | 535 | // viewer's own unless `?apps=` narrows the board. |
| 535 | 536 | const apps = ctx.url.searchParams.get("apps"); |
| @@ -644,7 +645,7 @@ function figures(parts: readonly FigureWords[]): Html { | ||
| 644 | 645 | * its own. |
| 645 | 646 | */ |
| 646 | 647 | function windowsStrip(ctx: Ctx): Html | null { |
| 647 | if (!ctx.auth.user?.isAdmin) return null; | |
| 648 | if (!adminPage(ctx)) return null; | |
| 648 | 649 | const db = ctx.app.db; |
| 649 | 650 | const pool = listCredentials(db); |
| 650 | 651 | if (pool.length === 0) return null; |
src/web/pages/boards-index-stream.ts +2 −3
| @@ -15,7 +15,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 15 | 15 | import { background } from "../../perf/jobs.ts"; |
| 16 | 16 | import { eventStream } from "../../http/sse.ts"; |
| 17 | 17 | import { notFoundPage } from "../chrome.ts"; |
| 18 | import { adminPage } from "../../http/page_may.ts"; | |
| 18 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 19 | 19 | |
| 20 | 20 | /** A burst of events is read once, this long after the first. */ |
| 21 | 21 | export const SETTLE_MS = 100; |
| @@ -28,8 +28,7 @@ export function readNumbers(app: App, now = Date.now()): Numbers { | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | export function boardsIndexStream(ctx: Ctx): Response { |
| 31 | const u = ctx.auth.user; | |
| 32 | if (!adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent")) return notFoundPage(ctx); | |
| 31 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 33 | 32 | const { app } = ctx; |
| 34 | 33 | return eventStream(app, ctx.request, (emit, _close, ready) => { |
| 35 | 34 | let sent = readNumbers(app); |
src/web/pages/boards-stream.ts +2 −3
| @@ -12,12 +12,11 @@ import { isSlug } from "../../boards/store.ts"; | ||
| 12 | 12 | import type { Ctx } from "../../http/context.ts"; |
| 13 | 13 | import { eventStream } from "../../http/sse.ts"; |
| 14 | 14 | import { notFoundPage } from "../chrome.ts"; |
| 15 | import { adminPage } from "../../http/page_may.ts"; | |
| 15 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 16 | 16 | |
| 17 | 17 | export async function boardStream(ctx: Ctx): Promise<Response> { |
| 18 | const u = ctx.auth.user; | |
| 19 | 18 | const slug = ctx.params.slug ?? ""; |
| 20 | if (u === undefined || !adminPage(ctx, "boards-stream", u.isAdmin && u.kind !== "agent") || !isSlug(slug)) return notFoundPage(ctx); | |
| 19 | if (!personAdminPage(ctx) || !isSlug(slug)) return notFoundPage(ctx); | |
| 21 | 20 | const view = readView(ctx.url.searchParams); |
| 22 | 21 | const picture = await boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined); |
| 23 | 22 | if (picture === undefined || isFailed(picture) || picture.board === null) return notFoundPage(ctx); |
src/web/pages/boards-view.ts +3 −6
| @@ -38,7 +38,7 @@ import { boardMarks } from "../../boards/marks.ts"; | ||
| 38 | 38 | import { drawnPanel, panelData, runFor, type PanelDrawn } from "../../boards/panel_data.ts"; |
| 39 | 39 | import { readParams } from "../../boards/params.ts"; |
| 40 | 40 | import { paramsOf, queryFields } from "./boards.ts"; |
| 41 | import { adminPage } from "../../http/page_may.ts"; | |
| 41 | import { personAdminPage, signedInPage } from "../../http/page_may.ts"; | |
| 42 | 42 | |
| 43 | 43 | const sizes = (max: number, word: string, now: number) => |
| 44 | 44 | [1, 2, 3].slice(0, max).map((n) => ({ value: String(n), label: `${String(n)} ${word}`, selected: n === now })); |
| @@ -90,10 +90,7 @@ function grid(app: App, slug: string, board: Board, panels: readonly PanelDrawn[ | ||
| 90 | 90 | </section>`; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | const denied = (ctx: Ctx) => { | |
| 94 | const u = ctx.auth.user; | |
| 95 | return !adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent"); | |
| 96 | }; | |
| 93 | const denied = (ctx: Ctx) => !personAdminPage(ctx); | |
| 97 | 94 | |
| 98 | 95 | /** |
| 99 | 96 | * Start reading `/boards`' picture now and draw the panel once from it, so the |
| @@ -118,8 +115,8 @@ const liveLine = (paused: boolean): Html => | ||
| 118 | 115 | |
| 119 | 116 | export async function boardsList(ctx: Ctx): Promise<Response> { |
| 120 | 117 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 118 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 121 | 119 | const user = ctx.auth.user; |
| 122 | if (user === undefined) return signInFirst(ctx); | |
| 123 | 120 | if (denied(ctx)) { |
| 124 | 121 | // Not a forge admin: the page is the holds of the repositories they administer, or not found. |
| 125 | 122 | const holds = boardsHoldsCard(ctx.app.db, user); |
src/web/pages/boards.ts +3 −3
| @@ -24,7 +24,7 @@ import { btn, card, chartFrame, empty, field, selectField } from "../ui.ts"; | ||
| 24 | 24 | import { count, figure, figures, fold, reading, readingFailed, readingReplaceJs } from "../figure.ts"; |
| 25 | 25 | import { readForm } from "../form.ts"; |
| 26 | 26 | import { emptyList } from "../empty_words.ts"; |
| 27 | import { adminPage } from "../../http/page_may.ts"; | |
| 27 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 28 | 28 | |
| 29 | 29 | const AGGREGATES = ["count", "sum", "avg", "max"] as const; |
| 30 | 30 | const OPS = ["eq", "ne", "lt", "lte", "gt", "gte", "starts"] as const; |
| @@ -106,16 +106,16 @@ export function paramsOf(q: Record<string, unknown>, chart: Chart = "line"): Par | ||
| 106 | 106 | |
| 107 | 107 | // GET /boards/data: a `?ask=` sentence is read by the rules only, so no link can spend the model. |
| 108 | 108 | export async function boardsPage(ctx: Ctx): Promise<Response> { |
| 109 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 109 | 110 | const user = ctx.auth.user; |
| 110 | if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 111 | 111 | return explorer(ctx, user, ctx.url.searchParams.get("ask"), false); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // POST /boards/data: the page's own sentence box. Only here may a miss ask the model, which spends the |
| 115 | 115 | // asker's budget; `readForm` refuses a form another site sent (`crossOrigin`), as every mutation is. |
| 116 | 116 | export async function boardsAsk(ctx: Ctx): Promise<Response> { |
| 117 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 117 | 118 | const user = ctx.auth.user; |
| 118 | if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 119 | 119 | const form = await readForm(ctx, "admin"); |
| 120 | 120 | if (form instanceof Response) return form; |
| 121 | 121 | const asked = form.get("ask"); |
src/web/pages/bottleneck.ts +1 −1
| @@ -32,7 +32,7 @@ function opRow(o: Op): Html { | ||
| 32 | 32 | |
| 33 | 33 | export async function bottleneckPage(ctx: Ctx): Promise<Response> { |
| 34 | 34 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 35 | if (!signedInPage(ctx, "bottleneck")) return signInFirst(ctx); | |
| 35 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 36 | 36 | const reader = telemetryReader(ctx.app, ctx.auth.user); |
| 37 | 37 | if (reader?.kind !== "owner") return notFoundPage(ctx); |
| 38 | 38 | const rendering = performance.now(); |
src/web/pages/branches.ts +2 −2
| @@ -421,7 +421,7 @@ export async function renderBranches( | ||
| 421 | 421 | export async function branchCreate(ctx: Ctx): Promise<Response> { |
| 422 | 422 | const repo = loadRepo(ctx); |
| 423 | 423 | if (!repo) return notFoundPage(ctx); |
| 424 | if (!signedInPage(ctx, "branches")) return signInFirst(ctx); | |
| 424 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 425 | 425 | const form = await readForm(ctx, "rw"); |
| 426 | 426 | if (form instanceof Response) return form; |
| 427 | 427 | |
| @@ -447,7 +447,7 @@ export async function branchCreate(ctx: Ctx): Promise<Response> { | ||
| 447 | 447 | export async function branchDelete(ctx: Ctx): Promise<Response> { |
| 448 | 448 | const repo = loadRepo(ctx); |
| 449 | 449 | if (!repo) return notFoundPage(ctx); |
| 450 | if (!signedInPage(ctx, "branches")) return signInFirst(ctx); | |
| 450 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 451 | 451 | const form = await readForm(ctx, "rw"); |
| 452 | 452 | if (form instanceof Response) return form; |
| 453 | 453 |
src/web/pages/builds.ts +4 −4
| @@ -77,7 +77,7 @@ export async function buildsPage(ctx: Ctx): Promise<Response> { | ||
| 77 | 77 | export async function deletePinSubmit(ctx: Ctx): Promise<Response> { |
| 78 | 78 | const repo = loadRepo(ctx); |
| 79 | 79 | if (!repo) return notFoundPage(ctx); |
| 80 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 80 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 81 | 81 | const form = await readForm(ctx, "rw"); |
| 82 | 82 | if (form instanceof Response) return form; |
| 83 | 83 | const gone = await deletePin(ctx.app, ctx.auth.user, repo, ctx.params.label ?? ""); |
| @@ -154,7 +154,7 @@ export async function newBuildPage(ctx: Ctx): Promise<Response> { | ||
| 154 | 154 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 155 | 155 | const repo = loadRepo(ctx); |
| 156 | 156 | if (!repo) return notFoundPage(ctx); |
| 157 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 157 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 158 | 158 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx); |
| 159 | 159 | const base = repoBase(repo); |
| 160 | 160 | const dir = repoDir(ctx.app.reposRoot, repo.ownerName, repo.name); |
| @@ -223,7 +223,7 @@ const PIN_ERRORS: Record<string, string> = { | ||
| 223 | 223 | export async function pinBuildSubmit(ctx: Ctx): Promise<Response> { |
| 224 | 224 | const repo = loadRepo(ctx); |
| 225 | 225 | if (!repo) return notFoundPage(ctx); |
| 226 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 226 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 227 | 227 | const form = await readForm(ctx, "rw"); |
| 228 | 228 | if (form instanceof Response) return form; |
| 229 | 229 | const base = repoBase(repo); |
| @@ -258,7 +258,7 @@ const PREVIEW_ERRORS: Record<string, string> = { | ||
| 258 | 258 | export async function previewBuildSubmit(ctx: Ctx): Promise<Response> { |
| 259 | 259 | const repo = loadRepo(ctx); |
| 260 | 260 | if (!repo) return notFoundPage(ctx); |
| 261 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 261 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 262 | 262 | const form = await readForm(ctx, "rw"); |
| 263 | 263 | if (form instanceof Response) return form; |
| 264 | 264 | const preview = await previewBuild(ctx.app, ctx.auth.user, repo, formValue(form, "sha")); |
src/web/pages/capacity.ts +2 −2
| @@ -27,8 +27,8 @@ import { lentLine } from "../../checks/lent_scope.ts"; | ||
| 27 | 27 | import { lentIn } from "../../checks/runner_jobs.ts"; |
| 28 | 28 | |
| 29 | 29 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 30 | if (!signedInPage(ctx, "capacity")) return signInFirst(ctx); | |
| 31 | if (!adminPage(ctx, "capacity", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 30 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 31 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 32 | 32 | return undefined; |
| 33 | 33 | } |
| 34 | 34 |
src/web/pages/chain.ts +5 −5
| @@ -184,7 +184,7 @@ export async function chainPage(ctx: Ctx): Promise<Response> { | ||
| 184 | 184 | export async function severSubmit(ctx: Ctx): Promise<Response> { |
| 185 | 185 | const repo = loadRepo(ctx); |
| 186 | 186 | if (!repo) return notFoundPage(ctx); |
| 187 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 187 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 188 | 188 | const form = await readForm(ctx, "rw"); |
| 189 | 189 | if (form instanceof Response) return form; |
| 190 | 190 | const to = `${repoBase(repo)}/following`; |
| @@ -203,7 +203,7 @@ export async function severSubmit(ctx: Ctx): Promise<Response> { | ||
| 203 | 203 | export async function checkSubmit(ctx: Ctx): Promise<Response> { |
| 204 | 204 | const repo = loadRepo(ctx); |
| 205 | 205 | if (!repo) return notFoundPage(ctx); |
| 206 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 206 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 207 | 207 | const form = await readForm(ctx, "rw"); |
| 208 | 208 | if (form instanceof Response) return form; |
| 209 | 209 | const to = `${repoBase(repo)}/following`; |
| @@ -218,7 +218,7 @@ export async function checkSubmit(ctx: Ctx): Promise<Response> { | ||
| 218 | 218 | export async function takeSubmit(ctx: Ctx): Promise<Response> { |
| 219 | 219 | const repo = loadRepo(ctx); |
| 220 | 220 | if (!repo) return notFoundPage(ctx); |
| 221 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 221 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 222 | 222 | const form = await readForm(ctx, "rw"); |
| 223 | 223 | if (form instanceof Response) return form; |
| 224 | 224 | const to = `${repoBase(repo)}/following`; |
| @@ -238,7 +238,7 @@ export async function takeSubmit(ctx: Ctx): Promise<Response> { | ||
| 238 | 238 | export async function modeSubmit(ctx: Ctx): Promise<Response> { |
| 239 | 239 | const repo = loadRepo(ctx); |
| 240 | 240 | if (!repo) return notFoundPage(ctx); |
| 241 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 241 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 242 | 242 | const form = await readForm(ctx, "rw"); |
| 243 | 243 | if (form instanceof Response) return form; |
| 244 | 244 | const to = `${repoBase(repo)}/following`; |
| @@ -254,7 +254,7 @@ export async function modeSubmit(ctx: Ctx): Promise<Response> { | ||
| 254 | 254 | export async function proposeParentSubmit(ctx: Ctx): Promise<Response> { |
| 255 | 255 | const repo = loadRepo(ctx); |
| 256 | 256 | if (!repo) return notFoundPage(ctx); |
| 257 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 257 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 258 | 258 | const form = await readForm(ctx, "rw"); |
| 259 | 259 | if (form instanceof Response) return form; |
| 260 | 260 | const to = `${repoBase(repo)}/following`; |
src/web/pages/changelog.ts +2 −1
| @@ -40,6 +40,7 @@ import { shippedHeld } from "../../release/answer.ts"; | ||
| 40 | 40 | import { html, type Html } from "../html.ts"; |
| 41 | 41 | import { page } from "../layout.ts"; |
| 42 | 42 | import { badge, row, seg, sha, time, timeAgo } from "../ui.ts"; |
| 43 | import { signedInPage } from "../../http/page_may.ts"; | |
| 43 | 44 | |
| 44 | 45 | /** Where the live client looks: a merge lands, or production serves a commit. */ |
| 45 | 46 | const LIVE = "pull.merged,app.serving"; |
| @@ -463,7 +464,7 @@ function older(more: string | undefined, last: string | undefined, choice: strin | ||
| 463 | 464 | export function cacheHeaders(ctx: Ctx, etag: string): { matched: boolean; response: Response; headers: Headers } | undefined { |
| 464 | 465 | if (ctx.request.method !== "GET" && ctx.request.method !== "HEAD") return undefined; |
| 465 | 466 | const h = ctx.request.headers; |
| 466 | const anonymous = !h.has("cookie") && !h.has("authorization") && !h.has("x-plat-user") && !h.has("x-plat-edge-token") && ctx.auth.user === undefined; | |
| 467 | const anonymous = !h.has("cookie") && !h.has("authorization") && !h.has("x-plat-user") && !h.has("x-plat-edge-token") && !signedInPage(ctx); | |
| 467 | 468 | const headers = new Headers({ etag }); |
| 468 | 469 | if (anonymous) { |
| 469 | 470 | headers.set("cache-control", `public, max-age=0, s-maxage=${EDGE_FRESH}, stale-while-revalidate=${EDGE_STALE}`); |
src/web/pages/chapters.ts +2 −1
| @@ -18,6 +18,7 @@ import { backTo, field, readForm } from "../form.ts"; | ||
| 18 | 18 | import { html, type Html } from "../html.ts"; |
| 19 | 19 | import { flashTo, page } from "../layout.ts"; |
| 20 | 20 | import { badge, btn, row } from "../ui.ts"; |
| 21 | import { signedInPage } from "../../http/page_may.ts"; | |
| 21 | 22 | |
| 22 | 23 | const usd = (n: number): string => `$${n.toFixed(2)}`; |
| 23 | 24 | const day = (iso: string | null): string => (iso === null ? "" : iso.slice(0, 10)); |
| @@ -170,8 +171,8 @@ export async function chapterAct(ctx: Ctx): Promise<Response> { | ||
| 170 | 171 | if (form instanceof Response) return form; |
| 171 | 172 | const list = `${repoBase(repo)}/chapters`; |
| 172 | 173 | const name = ctx.params.chapter; |
| 174 | if (!signedInPage(ctx)) return flashTo(ctx, list, { tone: "danger", message: "Sign in first." }); | |
| 173 | 175 | const user = ctx.auth.user; |
| 174 | if (user === undefined) return flashTo(ctx, list, { tone: "danger", message: "Sign in first." }); | |
| 175 | 176 | const app = ctx.app; |
| 176 | 177 | if (name === undefined) { |
| 177 | 178 | const made = draft(app, user, repo, { name: field(form, "name"), means: field(form, "means") }); |
src/web/pages/client_cloud.ts +6 −6
| @@ -50,10 +50,10 @@ export function clientCloudsPage(ctx: Ctx): Response { | ||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function clientCloudsBody(ctx: Ctx): Response { |
| 53 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 53 | 54 | const user = ctx.auth.user; |
| 54 | if (!user) return signInFirst(ctx); | |
| 55 | 55 | const mine = myClientClouds(ctx.app, user); |
| 56 | if (mine.length === 0 && !adminPage(ctx, "client_cloud", user.isAdmin)) return notFoundPage(ctx); | |
| 56 | if (mine.length === 0 && !adminPage(ctx)) return notFoundPage(ctx); | |
| 57 | 57 | return sealed( |
| 58 | 58 | page({ |
| 59 | 59 | ctx, |
| @@ -80,7 +80,7 @@ function clientCloudsBody(ctx: Ctx): Response { | ||
| 80 | 80 | |
| 81 | 81 | // POST /client-clouds |
| 82 | 82 | export async function clientCloudAttach(ctx: Ctx): Promise<Response> { |
| 83 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 83 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 84 | 84 | const form = await readForm(ctx, "admin"); |
| 85 | 85 | if (form instanceof Response) return form; |
| 86 | 86 | const r = await attachClientCloud(ctx.app, ctx.auth.user, { |
| @@ -113,7 +113,7 @@ function seenCard(v: ClientCloudView): Html { | ||
| 113 | 113 | |
| 114 | 114 | // GET /client-clouds/:id |
| 115 | 115 | export async function clientCloudPage(ctx: Ctx): Promise<Response> { |
| 116 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 116 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 117 | 117 | const r = await lookAtClientCloud(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| 118 | 118 | if (!r.ok) return notFoundPage(ctx); |
| 119 | 119 | const v = r.value; |
| @@ -143,7 +143,7 @@ export async function clientCloudPage(ctx: Ctx): Promise<Response> { | ||
| 143 | 143 | |
| 144 | 144 | // POST /client-clouds/:id/grant |
| 145 | 145 | export async function clientCloudGrant(ctx: Ctx): Promise<Response> { |
| 146 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 146 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 147 | 147 | const form = await readForm(ctx, "admin"); |
| 148 | 148 | if (form instanceof Response) return form; |
| 149 | 149 | const id = ctx.params.id ?? ""; |
| @@ -154,7 +154,7 @@ export async function clientCloudGrant(ctx: Ctx): Promise<Response> { | ||
| 154 | 154 | |
| 155 | 155 | // POST /client-clouds/:id/end |
| 156 | 156 | export async function clientCloudEnd(ctx: Ctx): Promise<Response> { |
| 157 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 157 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 158 | 158 | const form = await readForm(ctx, "admin"); |
| 159 | 159 | if (form instanceof Response) return form; |
| 160 | 160 | const id = ctx.params.id ?? ""; |
src/web/pages/cloud.ts +2 −2
| @@ -52,8 +52,8 @@ import { accountSections } from "./origins.ts"; | ||
| 52 | 52 | const BACK = "/settings/cloud"; |
| 53 | 53 | |
| 54 | 54 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 55 | if (!signedInPage(ctx, "cloud")) return signInFirst(ctx); | |
| 56 | if (!adminPage(ctx, "cloud", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 55 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 56 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 57 | 57 | return undefined; |
| 58 | 58 | } |
| 59 | 59 |
src/web/pages/cockpit.ts +2 −1
| @@ -17,6 +17,7 @@ import { html, type Html } from "../html.ts"; | ||
| 17 | 17 | import { page } from "../layout.ts"; |
| 18 | 18 | import { meter } from "../ui.ts"; |
| 19 | 19 | import { cockpitFor, type Cockpit, type CockpitAction, type CockpitCard, type CockpitWave } from "../studio/cockpit.ts"; |
| 20 | import { signedInPage } from "../../http/page_may.ts"; | |
| 20 | 21 | |
| 21 | 22 | /** The events that can move a region. */ |
| 22 | 23 | const LIVE = "run.*,issue.*,pull.*,release.*"; |
| @@ -91,8 +92,8 @@ export function cockpitBody(c: Cockpit, kiosk: boolean): Html { | ||
| 91 | 92 | // GET /cockpit and GET /board?kiosk=1 — signed in. |
| 92 | 93 | export function cockpitPage(ctx: Ctx, kioskMode = ctx.url.searchParams.has("kiosk")): Response { |
| 93 | 94 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 95 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 94 | 96 | const user = ctx.auth.user; |
| 95 | if (!user) return signInFirst(ctx); | |
| 96 | 97 | const c = timePhase(ctx.request, "cockpit", () => cockpitFor(ctx.app, user, { kiosk: kioskMode })); |
| 97 | 98 | return timePhase(ctx.request, "render", () => |
| 98 | 99 | page({ |
src/web/pages/config.ts +2 −2
| @@ -68,7 +68,7 @@ async function commitsDirectly(ctx: Ctx, scope: RepoScope, ref: string): Promise | ||
| 68 | 68 | function configContext(ctx: Ctx, ref: string, path: string): RepoScope | Response { |
| 69 | 69 | const repo = loadRepo(ctx); |
| 70 | 70 | if (!repo) return notFoundPage(ctx); |
| 71 | if (!signedInPage(ctx, "config")) return signInFirst(ctx); | |
| 71 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 72 | 72 | if (!isSafeRef(ref) || !isSafeTreePath(path) || !isFormConfig(path)) return notFoundPage(ctx); |
| 73 | 73 | const scope = localScope(ctx, repo); |
| 74 | 74 | // A mirror you cannot push to proposes through its origin: the source editor's card. |
| @@ -265,7 +265,7 @@ export async function configSubmit(ctx: Ctx): Promise<Response> { | ||
| 265 | 265 | // Who may write is settled before the body is read: a private repository |
| 266 | 266 | // answers a stranger 404, as every page about it does. |
| 267 | 267 | if (!loadRepo(ctx)) return notFoundPage(ctx); |
| 268 | if (!signedInPage(ctx, "config")) return signInFirst(ctx); | |
| 268 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 269 | 269 | const form = await readForm(ctx, "rw"); |
| 270 | 270 | if (form instanceof Response) return form; |
| 271 | 271 | const ref = formValue(form, "ref"); |
src/web/pages/confirms.ts +3 −2
| @@ -19,6 +19,7 @@ import { html, type Html } from "../html.ts"; | ||
| 19 | 19 | import { flashTo, page } from "../layout.ts"; |
| 20 | 20 | import { btn, icon, messageText, row, time } from "../ui.ts"; |
| 21 | 21 | import { accountSections } from "./origins.ts"; |
| 22 | import { signedInPage } from "../../http/page_may.ts"; | |
| 22 | 23 | |
| 23 | 24 | const BACK = "/settings/confirms"; |
| 24 | 25 | |
| @@ -61,15 +62,15 @@ function confirmsPage(ctx: Ctx, shown?: Html): Response { | ||
| 61 | 62 | |
| 62 | 63 | // GET /settings/confirms |
| 63 | 64 | export function confirmsList(ctx: Ctx): Response { |
| 64 | if (ctx.auth.user === undefined) return signInFirst(ctx); | |
| 65 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 65 | 66 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 66 | 67 | return timePhase(ctx.request, "render", () => confirmsPage(ctx)); |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | // POST /settings/confirms/:id — the person's yes. |
| 70 | 71 | export async function confirmYes(ctx: Ctx): Promise<Response> { |
| 72 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 71 | 73 | const user = ctx.auth.user; |
| 72 | if (user === undefined) return signInFirst(ctx); | |
| 73 | 74 | // A browser's own session, as the API's door: never a token or a password. |
| 74 | 75 | if (ctx.auth.via !== "session") return forbiddenPage(ctx, "Answer this from your own signed-in browser."); |
| 75 | 76 | const form = await readForm(ctx); |
src/web/pages/conflicts.ts +2 −1
| @@ -36,6 +36,7 @@ import { flashTo, page } from "../layout.ts"; | ||
| 36 | 36 | import { renderMarkdown } from "../markdown.ts"; |
| 37 | 37 | import { btn } from "../ui.ts"; |
| 38 | 38 | import { changeHead, changeTabs, pullContext } from "../studio/change.ts"; |
| 39 | import { signedInPage } from "../../http/page_may.ts"; | |
| 39 | 40 | |
| 40 | 41 | /** More blocks or longer words than this are not a hand's work. */ |
| 41 | 42 | export const MAX_BLOCKS = 500; |
| @@ -280,7 +281,7 @@ export async function conflictsFinish(ctx: Ctx): Promise<Response> { | ||
| 280 | 281 | const found = pullContext(ctx); |
| 281 | 282 | if (found instanceof Response) return found; |
| 282 | 283 | const { repo, pull } = found; |
| 283 | if (!ctx.auth.user || !canWrite(ctx.app.db, repo, ctx.auth.user)) | |
| 284 | if (!signedInPage(ctx) || !canWrite(ctx.app.db, repo, ctx.auth.user)) | |
| 284 | 285 | return forbiddenPage(ctx, "Only someone who can write to this repository can do this."); |
| 285 | 286 | const form = await readForm(ctx, "rw"); |
| 286 | 287 | if (form instanceof Response) return form; |
src/web/pages/connections.ts +6 −6
| @@ -34,7 +34,7 @@ import { field, readForm } from "../form.ts"; | ||
| 34 | 34 | import { html, type Html } from "../html.ts"; |
| 35 | 35 | import { flashTo } from "../layout.ts"; |
| 36 | 36 | import { badge, btn, confirmAction, field as formField, row, rowList, selectField } from "../ui.ts"; |
| 37 | import { adminPage } from "../../http/page_may.ts"; | |
| 37 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 38 | 38 | |
| 39 | 39 | const BACK = "/settings/model"; |
| 40 | 40 | |
| @@ -138,8 +138,8 @@ function addForm(user: User): Html { | ||
| 138 | 138 | |
| 139 | 139 | // POST /settings/model/connections |
| 140 | 140 | export async function connectionAdd(ctx: Ctx): Promise<Response> { |
| 141 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 141 | 142 | const user = ctx.auth.user; |
| 142 | if (user === undefined) return notFoundPage(ctx); | |
| 143 | 143 | const form = await readForm(ctx, "admin"); |
| 144 | 144 | if (form instanceof Response) return form; |
| 145 | 145 | const preset = CONNECTION_PRESETS.find((p) => p.id === field(form, "preset")); |
| @@ -171,8 +171,8 @@ export async function connectionAdd(ctx: Ctx): Promise<Response> { | ||
| 171 | 171 | |
| 172 | 172 | // POST /settings/model/connections/:id |
| 173 | 173 | export async function connectionEdit(ctx: Ctx): Promise<Response> { |
| 174 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 174 | 175 | const user = ctx.auth.user; |
| 175 | if (user === undefined) return notFoundPage(ctx); | |
| 176 | 176 | const form = await readForm(ctx, "admin"); |
| 177 | 177 | if (form instanceof Response) return form; |
| 178 | 178 | // A field the form did not send keeps what it is; the empty one it did send is the person's. |
| @@ -208,12 +208,12 @@ export async function connectionEdit(ctx: Ctx): Promise<Response> { | ||
| 208 | 208 | |
| 209 | 209 | // POST /settings/model/connections/:id/test |
| 210 | 210 | export async function connectionRetest(ctx: Ctx): Promise<Response> { |
| 211 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 211 | 212 | const user = ctx.auth.user; |
| 212 | if (user === undefined) return notFoundPage(ctx); | |
| 213 | 213 | const form = await readForm(ctx, "admin"); |
| 214 | 214 | if (form instanceof Response) return form; |
| 215 | 215 | const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? ""); |
| 216 | if (c === undefined || (c.scope === "forge" && !adminPage(ctx, "connections", user.isAdmin))) | |
| 216 | if (c === undefined || (c.scope === "forge" && !adminPage(ctx))) | |
| 217 | 217 | return notFoundPage(ctx); |
| 218 | 218 | const test = await retestConnection(ctx.app, user, c.id); |
| 219 | 219 | if (test === "busy") return flashTo(ctx, BACK, { tone: "danger", message: CONNECTION_REFUSED["busy"]! }); |
| @@ -231,8 +231,8 @@ export async function connectionRetest(ctx: Ctx): Promise<Response> { | ||
| 231 | 231 | |
| 232 | 232 | // POST /settings/model/connections/:id/remove (from the confirm page, with its name typed) |
| 233 | 233 | export async function connectionRemove(ctx: Ctx): Promise<Response> { |
| 234 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 234 | 235 | const user = ctx.auth.user; |
| 235 | if (user === undefined) return notFoundPage(ctx); | |
| 236 | 236 | const form = await readForm(ctx, "admin"); |
| 237 | 237 | if (form instanceof Response) return form; |
| 238 | 238 | const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? ""); |
src/web/pages/crew-settings.ts +1 −1
| @@ -30,7 +30,7 @@ export async function crewSubscriptionsSave(ctx: Ctx): Promise<Response> { | ||
| 30 | 30 | const gate = await adminForm(ctx); |
| 31 | 31 | if (gate instanceof Response) return gate; |
| 32 | 32 | const { repo, form } = gate; |
| 33 | if (!adminPage(ctx, "crew-settings", ctx.auth.user?.isAdmin === true)) return repoNotFound(ctx); | |
| 33 | if (!adminPage(ctx)) return repoNotFound(ctx); | |
| 34 | 34 | const crew = listCrew(ctx.app, ctx.auth.user, repo); |
| 35 | 35 | saveGrants(ctx, form, repo.id, crew.ok ? crew.value : []); |
| 36 | 36 | return flashTo(ctx, `${repoBase(repo)}/settings#crew`, { |
src/web/pages/crew.ts +2 −2
| @@ -97,8 +97,8 @@ import { forgeCeiling } from "../../flow/ceiling.ts"; | ||
| 97 | 97 | |
| 98 | 98 | /** The admin, or the response that turns everyone else away. */ |
| 99 | 99 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 100 | if (!signedInPage(ctx, "crew")) return signInFirst(ctx); | |
| 101 | if (!adminPage(ctx, "crew", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 100 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 101 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 102 | 102 | return undefined; |
| 103 | 103 | } |
| 104 | 104 |
src/web/pages/data.ts +5 −5
| @@ -21,7 +21,7 @@ import { page } from "../layout.ts"; | ||
| 21 | 21 | import { btn } from "../ui.ts"; |
| 22 | 22 | import { localScope } from "../scope.ts"; |
| 23 | 23 | import { dataBody, type DataView } from "./data_view.ts"; |
| 24 | import { adminPage } from "../../http/page_may.ts"; | |
| 24 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 25 | 25 | |
| 26 | 26 | const PURPOSE = "Every SQLite file you may read; secrets are masked."; |
| 27 | 27 | |
| @@ -48,8 +48,8 @@ function refuse(ctx: Ctx): Response { | ||
| 48 | 48 | // GET /data[?source=<id>[&table=<name>…][&sql=…]] |
| 49 | 49 | export async function dataPage(ctx: Ctx): Promise<Response> { |
| 50 | 50 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 51 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 51 | 52 | const viewer = ctx.auth.user; |
| 52 | if (!viewer) return signInFirst(ctx); | |
| 53 | 53 | const { db, config } = ctx.app; |
| 54 | 54 | if (!maySeeData(db, viewer)) return refuse(ctx); |
| 55 | 55 | const sources = listSources(db, config.dataDir, viewer); |
| @@ -60,9 +60,9 @@ export async function dataPage(ctx: Ctx): Promise<Response> { | ||
| 60 | 60 | // GET /admin/data — the forge's own database (the admin gate has already refused non-admins). |
| 61 | 61 | export async function adminDataPage(ctx: Ctx): Promise<Response> { |
| 62 | 62 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 63 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 63 | 64 | const viewer = ctx.auth.user; |
| 64 | if (!viewer) return signInFirst(ctx); | |
| 65 | if (!adminPage(ctx, "data", viewer.isAdmin)) return refuse(ctx); | |
| 65 | if (!adminPage(ctx)) return refuse(ctx); | |
| 66 | 66 | const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.kind === "forge"); |
| 67 | 67 | 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." })); |
| 68 | 68 | } |
| @@ -72,7 +72,7 @@ export async function appDataPage(ctx: Ctx): Promise<Response> { | ||
| 72 | 72 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 73 | 73 | const repo = loadRepo(ctx); |
| 74 | 74 | const record = repo && getAppByRepo(ctx.app.db, repo.id); |
| 75 | if (!repo || !record || !ctx.auth.user || !canWrite(ctx.app.db, repo, ctx.auth.user)) return refuse(ctx); | |
| 75 | if (!repo || !record || !signedInPage(ctx) || !canWrite(ctx.app.db, repo, ctx.auth.user)) return refuse(ctx); | |
| 76 | 76 | const viewer = ctx.auth.user; |
| 77 | 77 | const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.id.startsWith(`app:${record.id}:`)); |
| 78 | 78 | const scope = localScope(ctx, repo); |
src/web/pages/dataset.ts +2 −2
| @@ -24,8 +24,8 @@ const usd = (n: number): string => `$${n.toFixed(2)}`; | ||
| 24 | 24 | export function datasetPage(ctx: Ctx): Response { |
| 25 | 25 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 26 | 26 | const rendering = performance.now(); |
| 27 | if (!signedInPage(ctx, "dataset")) return signInFirst(ctx); | |
| 28 | if (!adminPage(ctx, "dataset", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 27 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 28 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 29 | 29 | const stats = datasetStats(ctx.app.db); |
| 30 | 30 | const last = lastExport(ctx.app); |
| 31 | 31 | const a = answers(ctx.app.db); |
src/web/pages/displays.ts +2 −1
| @@ -13,6 +13,7 @@ import { pageHead, repoBase, signInFirst } from "../chrome.ts"; | ||
| 13 | 13 | import { html } from "../html.ts"; |
| 14 | 14 | import { page } from "../layout.ts"; |
| 15 | 15 | import { emptyList } from "../empty_words.ts"; |
| 16 | import { signedInPage } from "../../http/page_may.ts"; | |
| 16 | 17 | |
| 17 | 18 | const LAYOUT_WORD = { shelf: "Shelf", grid: "Grid", graph: "Graph" } as const; |
| 18 | 19 | |
| @@ -21,7 +22,7 @@ export { LIST_WAIT_MS, listWait }; | ||
| 21 | 22 | // GET /displays — every display the viewer may read; a stranger signs in first. |
| 22 | 23 | export async function displaysPage(ctx: Ctx): Promise<Response> { |
| 23 | 24 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 24 | if (ctx.auth.user === undefined) return signInFirst(ctx); | |
| 25 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 25 | 26 | const { rows, complete } = await timePhaseAsync(ctx.request, "displays", () => listedDisplaysWithin(ctx.app, ctx.auth.user, listWait.ms)); |
| 26 | 27 | return timePhase(ctx.request, "render", () => |
| 27 | 28 | page({ |
src/web/pages/economics.ts +3 −3
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | * Anyone else gets the not-found page. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 16 | import { signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 17 | 17 | import { sshOn } from "../../settings/ssh.ts"; |
| 18 | 18 | import { emptyNote } from "../empty_words.ts"; |
| 19 | 19 | import { ECONOMICS_WORDS, changeEconomics, readEconomics } from "../../actions/economics.ts"; |
| @@ -33,7 +33,7 @@ const PATH = "/settings/economics"; | ||
| 33 | 33 | // GET /settings/economics |
| 34 | 34 | export function economicsPage(ctx: Ctx): Response { |
| 35 | 35 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 36 | if (!signedInPage(ctx, "economics")) return signInFirst(ctx); | |
| 36 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 37 | 37 | const read = timePhase(ctx.request, "economics", () => readEconomics(ctx.app, ctx.auth.user)); |
| 38 | 38 | if (!read.ok) return notFoundPage(ctx); |
| 39 | 39 | const rendering = performance.now(); |
| @@ -176,7 +176,7 @@ export function economicsPage(ctx: Ctx): Response { | ||
| 176 | 176 | // POST /settings/economics |
| 177 | 177 | export async function economicsSet(ctx: Ctx): Promise<Response> { |
| 178 | 178 | // Checked before the body is read: a non-admin learns nothing of the door. |
| 179 | if (!adminPage(ctx, "economics", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 179 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 180 | 180 | const form = await readForm(ctx, "admin"); |
| 181 | 181 | if (form instanceof Response) return form; |
| 182 | 182 | // A field the posted form does not carry is left undefined: kept as it stands. |
src/web/pages/edit.ts +4 −4
| @@ -652,7 +652,7 @@ const isMarkdownPath = (path: string): boolean => | ||
| 652 | 652 | function editContext(ctx: Ctx): { scope: RepoScope; ref: string } | Response { |
| 653 | 653 | const repo = loadRepo(ctx); |
| 654 | 654 | if (!repo) return notFoundPage(ctx); |
| 655 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 655 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 656 | 656 | const scope = localScope(ctx, repo); |
| 657 | 657 | // A reader may not change it; a fork is how they propose. Someone who cannot read never got here. |
| 658 | 658 | if (!scope.caps.write) return cannotChangePage(ctx, scope, repo); |
| @@ -964,7 +964,7 @@ export async function runContribute( | ||
| 964 | 964 | export async function contributeSubmit(ctx: Ctx): Promise<Response> { |
| 965 | 965 | const repo = loadRepo(ctx); |
| 966 | 966 | if (!repo) return notFoundPage(ctx); |
| 967 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 967 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 968 | 968 | const form = await readForm(ctx, "rw"); |
| 969 | 969 | if (form instanceof Response) return form; |
| 970 | 970 | const scope = localScope(ctx, repo); |
| @@ -1106,7 +1106,7 @@ async function dxfSubmit(ctx: Ctx, scope: RepoScope, repo: Repo, form: Form): Pr | ||
| 1106 | 1106 | export async function editSubmit(ctx: Ctx): Promise<Response> { |
| 1107 | 1107 | const repo = loadRepo(ctx); |
| 1108 | 1108 | if (!repo) return notFoundPage(ctx); |
| 1109 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 1109 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1110 | 1110 | const form = await readForm(ctx, "rw"); |
| 1111 | 1111 | if (form instanceof Response) return form; |
| 1112 | 1112 | const scope = localScope(ctx, repo); |
| @@ -1297,7 +1297,7 @@ export async function deleteFilePage(ctx: Ctx): Promise<Response> { | ||
| 1297 | 1297 | export async function deleteFileSubmit(ctx: Ctx): Promise<Response> { |
| 1298 | 1298 | const repo = loadRepo(ctx); |
| 1299 | 1299 | if (!repo) return notFoundPage(ctx); |
| 1300 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 1300 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 1301 | 1301 | const form = await readForm(ctx, "rw"); |
| 1302 | 1302 | if (form instanceof Response) return form; |
| 1303 | 1303 | const scope = localScope(ctx, repo); |
src/web/pages/everyday.ts +12 −12
| @@ -40,7 +40,7 @@ import { signOutHere } from "../../actions/signins.ts"; | ||
| 40 | 40 | import { sessionCookie } from "./site.ts"; |
| 41 | 41 | import { safeNext, withReturn } from "../return_to.ts"; |
| 42 | 42 | import { EMAIL_TAKEN_MESSAGE, EMAIL_WANTED, USERNAME_TAKEN } from "../../actions/signup_words.ts"; |
| 43 | import { adminPage } from "../../http/page_may.ts"; | |
| 43 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 44 | 44 | |
| 45 | 45 | const USERNAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/; |
| 46 | 46 | |
| @@ -53,10 +53,10 @@ function suggestedName(ctx: Ctx, admin: User): string { | ||
| 53 | 53 | // GET /settings/everyday — the step on its own page: why, a username, one passkey button, and "Keep |
| 54 | 54 | // using admin". |
| 55 | 55 | export function everydayPage(ctx: Ctx): Response { |
| 56 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 56 | 57 | const user = ctx.auth.user; |
| 57 | if (!user) return signInFirst(ctx); | |
| 58 | 58 | // Nothing to ask: not an admin, has one already, or is one. |
| 59 | if (!adminPage(ctx, "everyday", user.isAdmin) || user.kind !== "user" || everydayOf(ctx.app.db, user) !== undefined || adminOf(ctx.app.db, user) !== undefined) return redirect("/settings"); | |
| 59 | if (!adminPage(ctx) || user.kind !== "user" || everydayOf(ctx.app.db, user) !== undefined || adminOf(ctx.app.db, user) !== undefined) return redirect("/settings"); | |
| 60 | 60 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 61 | 61 | return timePhase(ctx.request, "render", () => page({ |
| 62 | 62 | ctx, |
| @@ -164,10 +164,10 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> { | ||
| 164 | 164 | const refuse = (status: number, message: string) => |
| 165 | 165 | json({ error: "refused", message }, status); |
| 166 | 166 | if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE); |
| 167 | if (!signedInPage(ctx)) return refuse(401, "Sign in first."); | |
| 167 | 168 | const admin = ctx.auth.user; |
| 168 | if (!admin) return refuse(401, "Sign in first."); | |
| 169 | 169 | if (ctx.auth.via !== "session") return refuse(403, "Passkeys are made from a signed-in browser."); |
| 170 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return refuse(403, NOT_ADMIN_HERE); | |
| 170 | if (!adminPage(ctx)) return refuse(403, NOT_ADMIN_HERE); | |
| 171 | 171 | if (everydayOf(ctx.app.db, admin) !== undefined) |
| 172 | 172 | return refuse(409, "You already have an everyday account."); |
| 173 | 173 | const data = await boundedBody(ctx.request, STRANGER_MAX); |
| @@ -181,11 +181,11 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> { | ||
| 181 | 181 | |
| 182 | 182 | // POST /settings/everyday — make the everyday account, link it, sign in as it. |
| 183 | 183 | export async function everydayCreate(ctx: Ctx): Promise<Response> { |
| 184 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 184 | 185 | const admin = ctx.auth.user; |
| 185 | if (!admin) return signInFirst(ctx); | |
| 186 | 186 | const form = await readForm(ctx, "admin"); |
| 187 | 187 | if (form instanceof Response) return form; |
| 188 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 188 | if (!adminPage(ctx)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 189 | 189 | const existing = everydayOf(ctx.app.db, admin); |
| 190 | 190 | if (existing !== undefined) |
| 191 | 191 | return flashTo(ctx, "/settings", { |
| @@ -249,11 +249,11 @@ export async function everydayCreate(ctx: Ctx): Promise<Response> { | ||
| 249 | 249 | |
| 250 | 250 | // POST /settings/everyday/keep — the admin keeps working as admin, on purpose. |
| 251 | 251 | export async function everydayKeep(ctx: Ctx): Promise<Response> { |
| 252 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 252 | 253 | const admin = ctx.auth.user; |
| 253 | if (!admin) return signInFirst(ctx); | |
| 254 | 254 | const form = await readForm(ctx, "admin"); |
| 255 | 255 | if (form instanceof Response) return form; |
| 256 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 256 | if (!adminPage(ctx)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 257 | 257 | keepAdmin(ctx.app.db, admin); |
| 258 | 258 | return flashTo(ctx, "/", { |
| 259 | 259 | message: |
| @@ -264,8 +264,8 @@ export async function everydayKeep(ctx: Ctx): Promise<Response> { | ||
| 264 | 264 | // POST /settings/everyday/switch — leave the admin account for the everyday |
| 265 | 265 | // one: this session ends, and sign-in says as whom to come back. |
| 266 | 266 | export async function everydaySwitch(ctx: Ctx): Promise<Response> { |
| 267 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 267 | 268 | const admin = ctx.auth.user; |
| 268 | if (!admin) return signInFirst(ctx); | |
| 269 | 269 | const form = await readForm(ctx, "admin"); |
| 270 | 270 | if (form instanceof Response) return form; |
| 271 | 271 | const daily = admin.isAdmin ? everydayOf(ctx.app.db, admin) : undefined; |
| @@ -287,8 +287,8 @@ export async function everydaySwitch(ctx: Ctx): Promise<Response> { | ||
| 287 | 287 | * is the other choice, staying as the everyday account. |
| 288 | 288 | */ |
| 289 | 289 | export function everydayRefusedPage(ctx: Ctx, admin: User): Response { |
| 290 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 290 | 291 | const daily = ctx.auth.user; |
| 291 | if (daily === undefined) return signInFirst(ctx); | |
| 292 | 292 | const [who, way] = everydayRefusal(daily, admin); |
| 293 | 293 | const back = ctx.request.method === "GET" ? safeNext(ctx.url.pathname + ctx.url.search) : undefined; |
| 294 | 294 | return page( |
| @@ -314,8 +314,8 @@ export function everydayRefusedPage(ctx: Ctx, admin: User): Response { | ||
| 314 | 314 | // POST /settings/everyday/to-admin — leave the everyday account for its |
| 315 | 315 | // admin: this session ends, and sign-in says as whom to come back. |
| 316 | 316 | export async function everydayToAdmin(ctx: Ctx): Promise<Response> { |
| 317 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 317 | 318 | const daily = ctx.auth.user; |
| 318 | if (!daily) return signInFirst(ctx); | |
| 319 | 319 | const form = await readForm(ctx); |
| 320 | 320 | if (form instanceof Response) return form; |
| 321 | 321 | const admin = adminOf(ctx.app.db, daily); |
src/web/pages/features.ts +3 −3
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | * Anyone else is told the forge's 404, as every admin page does. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | import { signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 10 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 11 | 11 | import { upstreamBlob } from "../../core/upstream.ts"; |
| 12 | 12 | import { |
| @@ -40,8 +40,8 @@ import { badge, btn, empty, row, time } from "../ui.ts"; | ||
| 40 | 40 | import { accountSections } from "./origins.ts"; |
| 41 | 41 | |
| 42 | 42 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 43 | if (!signedInPage(ctx, "features")) return signInFirst(ctx); | |
| 44 | if (!adminPage(ctx, "features", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 43 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 44 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 45 | 45 | return undefined; |
| 46 | 46 | } |
| 47 | 47 |
src/web/pages/first.ts +1 −1
| @@ -9,7 +9,7 @@ import { flashOrJson } from "../layout.ts"; | ||
| 9 | 9 | export async function firstSubmit(ctx: Ctx): Promise<Response> { |
| 10 | 10 | const repo = loadRepo(ctx); |
| 11 | 11 | if (!repo) return notFoundPage(ctx); |
| 12 | if (!signedInPage(ctx, "first")) return signInFirst(ctx); | |
| 12 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 13 | 13 | const form = await readForm(ctx, "rw"); |
| 14 | 14 | if (form instanceof Response) return form; |
| 15 | 15 | const dest = backTo(form, `${repoBase(repo)}/map`); |
src/web/pages/flags.ts +2 −1
| @@ -19,12 +19,13 @@ import { html } from "../html.ts"; | ||
| 19 | 19 | import { flashTo, page } from "../layout.ts"; |
| 20 | 20 | import { btn, empty, icon, row } from "../ui.ts"; |
| 21 | 21 | import { accountSections } from "./origins.ts"; |
| 22 | import { signedInPage } from "../../http/page_may.ts"; | |
| 22 | 23 | |
| 23 | 24 | export { useFlagRegistry }; |
| 24 | 25 | |
| 25 | 26 | function denied(ctx: Ctx): Response | undefined { |
| 27 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 26 | 28 | const user = ctx.auth.user; |
| 27 | if (!user) return signInFirst(ctx); | |
| 28 | 29 | if (mayManageFlags(user)) return undefined; |
| 29 | 30 | return page( |
| 30 | 31 | { |
src/web/pages/fleet-graph.ts +4 −3
| @@ -25,6 +25,7 @@ import { | ||
| 25 | 25 | import { html } from "../html.ts"; |
| 26 | 26 | import { fragment, page } from "../layout.ts"; |
| 27 | 27 | import { btn, field } from "../ui.ts"; |
| 28 | import { signedInPage } from "../../http/page_may.ts"; | |
| 28 | 29 | |
| 29 | 30 | /** The selection from the URL, or the refusal's words. */ |
| 30 | 31 | function selection(ctx: Ctx) { |
| @@ -34,8 +35,8 @@ function selection(ctx: Ctx) { | ||
| 34 | 35 | /** GET /fleet/graph */ |
| 35 | 36 | export function fleetGraphPage(ctx: Ctx): Response { |
| 36 | 37 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 38 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 37 | 39 | const user = ctx.auth.user; |
| 38 | if (!user) return signInFirst(ctx); | |
| 39 | 40 | const asked = selection(ctx); |
| 40 | 41 | const graph = asked.ok |
| 41 | 42 | ? timePhase(ctx.request, "graph", () => |
| @@ -101,8 +102,8 @@ export function fleetGraphPage(ctx: Ctx): Response { | ||
| 101 | 102 | |
| 102 | 103 | /** GET /fleet/graph/live — the section alone, for the redraw. */ |
| 103 | 104 | export function fleetGraphLive(ctx: Ctx): Response { |
| 105 | if (!signedInPage(ctx)) return fragment(html``, { status: 404 }); | |
| 104 | 106 | const user = ctx.auth.user; |
| 105 | if (!user) return fragment(html``, { status: 404 }); | |
| 106 | 107 | const asked = selection(ctx); |
| 107 | 108 | if (!asked.ok) return fragment(html``, { status: 422 }); |
| 108 | 109 | return fragment(fleetGraphSection(readFleetGraph(ctx.app, user, asked.value)), { |
| @@ -138,8 +139,8 @@ export function fleetGraphCsvText(graph: FleetGraph): string { | ||
| 138 | 139 | |
| 139 | 140 | /** GET /fleet/graph.csv */ |
| 140 | 141 | export function fleetGraphCsv(ctx: Ctx): Response { |
| 142 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 141 | 143 | const user = ctx.auth.user; |
| 142 | if (!user) return signInFirst(ctx); | |
| 143 | 144 | const asked = selection(ctx); |
| 144 | 145 | if (!asked.ok) |
| 145 | 146 | return new Response(`${asked.error}\n`, { |
src/web/pages/fleet-ops.ts +3 −3
| @@ -26,7 +26,7 @@ import { canAct, renderFleet } from "./fleet.ts"; | ||
| 26 | 26 | |
| 27 | 27 | /** POST /fleet */ |
| 28 | 28 | export async function fleetAct(ctx: Ctx): Promise<Response> { |
| 29 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 29 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 30 | 30 | if (!canAct(ctx)) return notFoundPage(ctx); |
| 31 | 31 | const form = await readForm(ctx, "rw"); |
| 32 | 32 | if (form instanceof Response) return form; |
| @@ -91,7 +91,7 @@ function refusal( | ||
| 91 | 91 | |
| 92 | 92 | /** GET /fleet/ops/:id */ |
| 93 | 93 | export function fleetReceipt(ctx: Ctx): Response { |
| 94 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 94 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 95 | 95 | const found = getFleetOp(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| 96 | 96 | if (!found.ok) return notFoundPage(ctx); |
| 97 | 97 | const op = found.value; |
| @@ -108,7 +108,7 @@ export function fleetReceipt(ctx: Ctx): Response { | ||
| 108 | 108 | |
| 109 | 109 | /** POST /fleet/ops/:id/undo */ |
| 110 | 110 | export async function fleetUndo(ctx: Ctx): Promise<Response> { |
| 111 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 111 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 112 | 112 | if (!canAct(ctx)) return notFoundPage(ctx); |
| 113 | 113 | const form = await readForm(ctx, "rw"); |
| 114 | 114 | if (form instanceof Response) return form; |
src/web/pages/flow.ts +6 −6
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | * `tui/screens/valves.ts`, on the same `readPipes` and the same actions. |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 17 | import { signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 18 | 18 | import { retryBackup } from "../../actions/backup_retry.ts"; |
| 19 | 19 | import { alarmBackup, type BackupAlarm } from "../../flow/alarm_backup.ts"; |
| 20 | 20 | import { acceptSuggestion, turnValveFor, type ValveError } from "../../actions/valves.ts"; |
| @@ -159,9 +159,9 @@ export async function flowPage(ctx: Ctx): Promise<Response> { | ||
| 159 | 159 | const waiting = ctx.url.search === "?wait=1"; |
| 160 | 160 | if (ctx.url.search !== "" && !waiting) return new Response(null, { status: 301, headers: { location: `/boards${ctx.url.search}` } }); |
| 161 | 161 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 162 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 162 | 163 | const user = ctx.auth.user; |
| 163 | if (user === undefined) return signInFirst(ctx); | |
| 164 | if (!adminPage(ctx, "flow", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 164 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 165 | 165 | // What a "Reading…" page asks: it answers when the worker has the picture, and draws nothing. |
| 166 | 166 | if (waiting) { |
| 167 | 167 | return waitAnswer(await flowPicture(ctx.app, user.id, LONG_WAIT_MS)); |
| @@ -242,7 +242,7 @@ function done(ctx: Ctx, result: ReturnType<typeof turnValveFor>): Response { | ||
| 242 | 242 | |
| 243 | 243 | // POST /flow/valve |
| 244 | 244 | export async function valveSet(ctx: Ctx): Promise<Response> { |
| 245 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 245 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 246 | 246 | const form = await readForm(ctx, "admin"); |
| 247 | 247 | if (form instanceof Response) return form; |
| 248 | 248 | return done(ctx, turnValveFor(ctx.app, ctx.auth.user, field(form, "repo"), field(form, "level"))); |
| @@ -250,7 +250,7 @@ export async function valveSet(ctx: Ctx): Promise<Response> { | ||
| 250 | 250 | |
| 251 | 251 | // POST /flow/suggestion |
| 252 | 252 | export async function suggestionTake(ctx: Ctx): Promise<Response> { |
| 253 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 253 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 254 | 254 | const form = await readForm(ctx, "admin"); |
| 255 | 255 | if (form instanceof Response) return form; |
| 256 | 256 | return done(ctx, acceptSuggestion(ctx.app, ctx.auth.user, field(form, "repo"))); |
| @@ -258,7 +258,7 @@ export async function suggestionTake(ctx: Ctx): Promise<Response> { | ||
| 258 | 258 | |
| 259 | 259 | // POST /flow/backup/retry: one snapshot now, through the service's own queue, so two never run at once. |
| 260 | 260 | export async function backupRetry(ctx: Ctx): Promise<Response> { |
| 261 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 261 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 262 | 262 | const form = await readForm(ctx, "admin"); |
| 263 | 263 | if (form instanceof Response) return form; |
| 264 | 264 | const retried = await retryBackup(ctx.app, ctx.auth.user); |
src/web/pages/flows-all.ts +2 −3
| @@ -15,7 +15,7 @@ import { html } from "../html.ts"; | ||
| 15 | 15 | import { page } from "../layout.ts"; |
| 16 | 16 | import { accountSections } from "./origins.ts"; |
| 17 | 17 | import { badge, btn, listCard, row, time, type Tone } from "../ui.ts"; |
| 18 | import { adminPage } from "../../http/page_may.ts"; | |
| 18 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 19 | 19 | |
| 20 | 20 | /** Lines drawn at once; the count above says how many matched. */ |
| 21 | 21 | const SHOWN = 500; |
| @@ -25,8 +25,7 @@ const TONE: Record<Health, Tone> = { ok: "default", behind: "attn", diverged: "d | ||
| 25 | 25 | // GET /admin/flows?kind=&stale=1 |
| 26 | 26 | export function allFlowsPage(ctx: Ctx): Response { |
| 27 | 27 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 28 | const user = ctx.auth.user; | |
| 29 | if (!adminPage(ctx, "flows", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx); | |
| 28 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 30 | 29 | const q = new URL(ctx.request.url).searchParams; |
| 31 | 30 | const kind = parseKind(q.get("kind")); |
| 32 | 31 | const stale = q.get("stale") === "1"; |
src/web/pages/following.ts +1 −1
| @@ -603,7 +603,7 @@ export function followingCard( | ||
| 603 | 603 | export async function followingSubmit(ctx: Ctx): Promise<Response> { |
| 604 | 604 | const repo = loadRepo(ctx); |
| 605 | 605 | if (!repo) return notFoundPage(ctx); |
| 606 | if (!signedInPage(ctx, "following")) return signInFirst(ctx); | |
| 606 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 607 | 607 | const form = await readForm(ctx, "rw"); |
| 608 | 608 | if (form instanceof Response) return form; |
| 609 | 609 | const base = repoBase(repo); |
src/web/pages/forge-it.ts +2 −1
| @@ -11,13 +11,14 @@ import { forgeIt } from "../../spawn/forge_it.ts"; | ||
| 11 | 11 | import { loadRepo, notFoundPage, signInFirst } from "../chrome.ts"; |
| 12 | 12 | import { readForm } from "../form.ts"; |
| 13 | 13 | import { flashTo, redirect } from "../layout.ts"; |
| 14 | import { signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | |
| 15 | 16 | // POST /:owner/:name/forge |
| 16 | 17 | export async function forgeItSubmit(ctx: Ctx): Promise<Response> { |
| 17 | 18 | const repo = loadRepo(ctx); |
| 18 | 19 | if (!repo) return notFoundPage(ctx); |
| 20 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 19 | 21 | const user = ctx.auth.user; |
| 20 | if (!user) return signInFirst(ctx); | |
| 21 | 22 | const form = await readForm(ctx, "admin"); |
| 22 | 23 | if (form instanceof Response) return form; |
| 23 | 24 | const back = `/${repo.ownerName}/${repo.name}`; |
src/web/pages/forge-template-setting.ts +2 −2
| @@ -14,11 +14,11 @@ import { html, type Html } from "../html.ts"; | ||
| 14 | 14 | import { flashTo } from "../layout.ts"; |
| 15 | 15 | import { repoBase } from "../chrome.ts"; |
| 16 | 16 | import { btn, card, field as inputField } from "../ui.ts"; |
| 17 | import { adminPage } from "../../http/page_may.ts"; | |
| 17 | 18 | |
| 18 | 19 | /** The control, or nothing for anyone but a site admin. */ |
| 19 | 20 | export function forgeTemplateSetting(ctx: Ctx, repo: Repo): Html | null { |
| 20 | const user = ctx.auth.user; | |
| 21 | if (user === undefined || !user.isAdmin || user.kind !== "user") return null; | |
| 21 | if (!adminPage(ctx) || ctx.auth.user.kind !== "user") return null; | |
| 22 | 22 | const note = offeredNotes(ctx.app.db).get(`${repo.ownerName}/${repo.name}`); |
| 23 | 23 | return card( |
| 24 | 24 | html`<form method="post" action="${repoBase(repo)}/settings/app/forge-template"> |
src/web/pages/forge_machine.ts +2 −3
| @@ -29,8 +29,7 @@ const choose = (name: string, machines: readonly string[], recover: boolean) => | ||
| 29 | 29 | </form>`; |
| 30 | 30 | |
| 31 | 31 | export async function forgeMachineForm(ctx: Ctx): Promise<Response> { |
| 32 | const user = ctx.auth.user; | |
| 33 | if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx); | |
| 32 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 34 | 33 | const name = ctx.params["name"] ?? ""; |
| 35 | 34 | const to = ctx.url.searchParams.get("to") ?? ""; |
| 36 | 35 | const recover = ctx.url.searchParams.get("recover") === "1"; |
| @@ -57,8 +56,8 @@ export async function forgeMachineForm(ctx: Ctx): Promise<Response> { | ||
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | export async function forgeMachineSubmit(ctx: Ctx): Promise<Response> { |
| 59 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 60 | 60 | const user = ctx.auth.user; |
| 61 | if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx); | |
| 62 | 61 | const form = await readForm(ctx, "admin"); |
| 63 | 62 | if (form instanceof Response) return form; |
| 64 | 63 | const name = ctx.params["name"] ?? ""; |
src/web/pages/forge_move_in.ts +3 −3
| @@ -16,7 +16,7 @@ import { html, type Html } from "../html.ts"; | ||
| 16 | 16 | import { page } from "../layout.ts"; |
| 17 | 17 | import { btn, field } from "../ui.ts"; |
| 18 | 18 | import { statusRow } from "./security.ts"; |
| 19 | import { adminPage } from "../../http/page_may.ts"; | |
| 19 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 20 | 20 | |
| 21 | 21 | const wrap = (title: string, body: Html) => |
| 22 | 22 | html`<div class="narrow-wide" data-forges>${pageHead(title)}<section class="settings-block">${body}<p class="mt">${btn("Back to your forges", { href: "/forges", size: "sm" })}</p></section></div>`; |
| @@ -28,7 +28,7 @@ const done = (response: Response): Response => { | ||
| 28 | 28 | |
| 29 | 29 | export function forgeMoveInForm(ctx: Ctx): Response { |
| 30 | 30 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 31 | if (!adminPage(ctx, "forge_move_in", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 31 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 32 | 32 | const rendering = performance.now(); |
| 33 | 33 | const cost = moveInCost(); |
| 34 | 34 | const body = html`<dl class="status-rows" data-preview>${cost.rows.map(([label, value]) => statusRow(label, html`${value}`))}</dl> |
| @@ -46,7 +46,7 @@ export function forgeMoveInForm(ctx: Ctx): Response { | ||
| 46 | 46 | |
| 47 | 47 | export async function forgeMoveInSubmit(ctx: Ctx): Promise<Response> { |
| 48 | 48 | const user = ctx.auth.user; |
| 49 | if (!adminPage(ctx, "forge_move_in", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx); | |
| 49 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 50 | 50 | const form = await readForm(ctx, "admin", BODY_CAPS.moveIn.bytes); |
| 51 | 51 | if (form instanceof Response) return form; |
| 52 | 52 | const name = String(form.get("name") ?? "").trim().toLowerCase(); |
src/web/pages/forge_upgrade.ts +2 −2
| @@ -24,7 +24,7 @@ const wrap = (name: string, body: Html) => | ||
| 24 | 24 | |
| 25 | 25 | export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> { |
| 26 | 26 | const user = ctx.auth.user; |
| 27 | if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx); | |
| 27 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 28 | 28 | const name = ctx.params["name"] ?? ""; |
| 29 | 29 | const plan = ctx.url.searchParams.get("plan") ?? ""; |
| 30 | 30 | const to = ctx.url.searchParams.get("to") ?? ""; |
| @@ -53,7 +53,7 @@ export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> { | ||
| 53 | 53 | |
| 54 | 54 | export async function forgeUpgradeSubmit(ctx: Ctx): Promise<Response> { |
| 55 | 55 | const user = ctx.auth.user; |
| 56 | if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx); | |
| 56 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 57 | 57 | const form = await readForm(ctx, "admin"); |
| 58 | 58 | if (form instanceof Response) return form; |
| 59 | 59 | const name = ctx.params["name"] ?? ""; |
src/web/pages/forges.ts +17 −22
| @@ -49,7 +49,7 @@ import { claimedWords, isForgeSort, keepWords, SORT_WORDS, sortForges, type Forg | ||
| 49 | 49 | import { CHILD_NAME } from "../../spawn/placement.ts"; |
| 50 | 50 | import { forgesMemory, memoryOverLine } from "../../spawn/memory_fit.ts"; |
| 51 | 51 | import { NO_KEY_HELD } from "../../crew/no_key.ts"; |
| 52 | import { adminPage } from "../../http/page_may.ts"; | |
| 52 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | /** "3 apps running", or which one is not and why. */ |
| @@ -262,7 +262,7 @@ function refusedLink(ctx: Ctx): Html | null { | ||
| 262 | 262 | // GET /forges/export.csv — the client list as a download, behind the page's own gate (a missing |
| 263 | 263 | // page to anyone else). |
| 264 | 264 | export async function forgesCsv(ctx: Ctx): Promise<Response> { |
| 265 | if (!adminPage(ctx, "forges", ctx.auth.user?.isAdmin === true)) return notFoundPage(ctx); | |
| 265 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 266 | 266 | const rows = sortForges(await servedRows(ctx.app), "attention"); |
| 267 | 267 | return new Response(clientsCsv(rows), { |
| 268 | 268 | headers: { |
| @@ -276,8 +276,8 @@ export async function forgesCsv(ctx: Ctx): Promise<Response> { | ||
| 276 | 276 | |
| 277 | 277 | // GET /forges — an admin's only. |
| 278 | 278 | export async function forgesPage(ctx: Ctx): Promise<Response> { |
| 279 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 279 | 280 | const user = ctx.auth.user; |
| 280 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 281 | 281 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 282 | 282 | const asked = ctx.url.searchParams.get("sort"); |
| 283 | 283 | const sort: ForgeSort = isForgeSort(asked) ? asked : "attention"; |
| @@ -362,8 +362,8 @@ export async function forgesPage(ctx: Ctx): Promise<Response> { | ||
| 362 | 362 | // has no /forges list (#12105). Nothing is minted until it is pressed; whether this |
| 363 | 363 | // account may is the door's answer, not this page's. |
| 364 | 364 | export async function forgeLinkForm(ctx: Ctx): Promise<Response> { |
| 365 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 365 | 366 | const user = ctx.auth.user; |
| 366 | if (user === undefined) return notFoundPage(ctx); | |
| 367 | 367 | const name = ctx.params["name"] ?? ""; |
| 368 | 368 | const seen = await previewDoor(ctx, user, name); |
| 369 | 369 | const says = String(seen.body["says"] ?? seen.body["message"]); |
| @@ -390,8 +390,7 @@ export async function forgeLinkForm(ctx: Ctx): Promise<Response> { | ||
| 390 | 390 | // GET /forges/:name/revoke-link — what ending the link does in one line and the one button that |
| 391 | 391 | // does it; nothing changes until it is pressed (#14518). |
| 392 | 392 | export async function forgeRevokeConfirm(ctx: Ctx): Promise<Response> { |
| 393 | const user = ctx.auth.user; | |
| 394 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 393 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 395 | 394 | const name = ctx.params["name"] ?? ""; |
| 396 | 395 | if (!CHILD_NAME.test(name)) return notFoundPage(ctx); |
| 397 | 396 | const response = page({ |
| @@ -443,8 +442,7 @@ async function namedForges(ctx: Ctx, wanted: readonly string[]): Promise<string[ | ||
| 443 | 442 | // GET /forges/archive?name=a&name=b — what archiving does, for one or several, and the one button |
| 444 | 443 | // that does it. |
| 445 | 444 | export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> { |
| 446 | const user = ctx.auth.user; | |
| 447 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 445 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 448 | 446 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 449 | 447 | const names = await namedForges(ctx, ctx.url.searchParams.getAll("name")); |
| 450 | 448 | const rows = (await servedRows(ctx.app)).filter((r) => names.includes(r.name)); |
| @@ -477,8 +475,8 @@ export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> { | ||
| 477 | 475 | |
| 478 | 476 | // POST /forges/archive — archive each named forge, one after another; the receipt says each result. |
| 479 | 477 | export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> { |
| 478 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 480 | 479 | const user = ctx.auth.user; |
| 481 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 482 | 480 | const form = await readForm(ctx, "admin"); |
| 483 | 481 | if (form instanceof Response) return form; |
| 484 | 482 | const names = await namedForges(ctx, form.getAll("name").filter((v): v is string => typeof v === "string")); |
| @@ -489,8 +487,8 @@ export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> { | ||
| 489 | 487 | |
| 490 | 488 | // POST /forges/:name/restore — bring an archived forge back under its name. |
| 491 | 489 | export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> { |
| 490 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 492 | 491 | const user = ctx.auth.user; |
| 493 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 494 | 492 | const form = await readForm(ctx, "admin"); |
| 495 | 493 | if (form instanceof Response) return form; |
| 496 | 494 | const done = await restoreForge(ctx.app, ctx.params["name"] ?? "", { actorId: user.id }); |
| @@ -501,8 +499,8 @@ export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> { | ||
| 501 | 499 | // old one stops working. Shown once, in this answer only. The account that sent the |
| 502 | 500 | // forge may ask, as an admin may (#12105): `reissueClaim` says which. |
| 503 | 501 | export async function forgeLinkSubmit(ctx: Ctx): Promise<Response> { |
| 502 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 504 | 503 | const user = ctx.auth.user; |
| 505 | if (user === undefined) return notFoundPage(ctx); | |
| 506 | 504 | const form = await readForm(ctx, "rw"); |
| 507 | 505 | if (form instanceof Response) return form; |
| 508 | 506 | const name = ctx.params["name"] ?? ""; |
| @@ -554,8 +552,8 @@ function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null { | ||
| 554 | 552 | // minute; then the row, with a receipt. |
| 555 | 553 | function linkChange(act: "revoke" | "undo") { |
| 556 | 554 | return async (ctx: Ctx): Promise<Response> => { |
| 555 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 557 | 556 | const user = ctx.auth.user; |
| 558 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 559 | 557 | const form = await readForm(ctx, "admin"); |
| 560 | 558 | if (form instanceof Response) return form; |
| 561 | 559 | const name = ctx.params["name"] ?? ""; |
| @@ -571,8 +569,7 @@ export const forgeLinkUndo = linkChange("undo"); | ||
| 571 | 569 | // POST /forges/:name/stop and /remove — the owner's hands on a hosted forge. |
| 572 | 570 | function manageSubmit(act: (app: Ctx["app"], name: string) => Promise<Managed>, title: string) { |
| 573 | 571 | return async (ctx: Ctx): Promise<Response> => { |
| 574 | const user = ctx.auth.user; | |
| 575 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 572 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 576 | 573 | const form = await readForm(ctx, "admin"); |
| 577 | 574 | if (form instanceof Response) return form; |
| 578 | 575 | const done = await act(ctx.app, ctx.params["name"] ?? ""); |
| @@ -599,8 +596,8 @@ export const forgeStopSubmit = manageSubmit(stopForge, "Forge stopped"); | ||
| 599 | 596 | // POST /forges/:name/sandbox — move a forge out of this forge's own process into a sandbox of its |
| 600 | 597 | // own (`spawn/move_cell.ts`). |
| 601 | 598 | export async function forgeSandboxSubmit(ctx: Ctx): Promise<Response> { |
| 599 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 602 | 600 | const user = ctx.auth.user; |
| 603 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 604 | 601 | const form = await readForm(ctx, "admin"); |
| 605 | 602 | if (form instanceof Response) return form; |
| 606 | 603 | const name = ctx.params["name"] ?? ""; |
| @@ -627,8 +624,7 @@ export const forgeRemoveSubmit = manageSubmit(removeForge, "Forge removed"); | ||
| 627 | 624 | |
| 628 | 625 | // GET /forges/:name/remove — what removing would delete, and the one button that does it. |
| 629 | 626 | export async function forgeRemoveConfirm(ctx: Ctx): Promise<Response> { |
| 630 | const user = ctx.auth.user; | |
| 631 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 627 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 632 | 628 | const name = ctx.params["name"] ?? ""; |
| 633 | 629 | const child = (await listChildren(ctx.app)).find((c) => c.name === name); |
| 634 | 630 | if (child === undefined) return notFoundPage(ctx); |
| @@ -702,8 +698,7 @@ async function ownCodeSection(ctx: Ctx): Promise<Html | null> { | ||
| 702 | 698 | // POST /forges/:name/own-code — the owner's switch: `on` is "on" or "off"; then back to the list, |
| 703 | 699 | // with a receipt. |
| 704 | 700 | export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> { |
| 705 | const user = ctx.auth.user; | |
| 706 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 701 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 707 | 702 | const form = await readForm(ctx, "admin"); |
| 708 | 703 | if (form instanceof Response) return form; |
| 709 | 704 | const want = form.get("on"); |
| @@ -716,8 +711,8 @@ export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> { | ||
| 716 | 711 | |
| 717 | 712 | // POST /forges/:name/size — raise a forge to a larger size (xlarge); a receipt on the list. |
| 718 | 713 | export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> { |
| 714 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 719 | 715 | const user = ctx.auth.user; |
| 720 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 721 | 716 | const form = await readForm(ctx, "admin"); |
| 722 | 717 | if (form instanceof Response) return form; |
| 723 | 718 | const name = ctx.params["name"] ?? ""; |
| @@ -731,8 +726,8 @@ export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> { | ||
| 731 | 726 | once. Who may is the action's answer (`actions/forge_recovery.ts`). */ |
| 732 | 727 | // GET — the preview; nothing is minted. |
| 733 | 728 | export async function forgeRecoveryForm(ctx: Ctx): Promise<Response> { |
| 729 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 734 | 730 | const user = ctx.auth.user; |
| 735 | if (user === undefined) return notFoundPage(ctx); | |
| 736 | 731 | const name = ctx.params["name"] ?? ""; |
| 737 | 732 | const seen = await previewRecoveryDoor(ctx, user, name); |
| 738 | 733 | const says = String(seen.body["says"] ?? seen.body["message"]); |
| @@ -758,8 +753,8 @@ export async function forgeRecoveryForm(ctx: Ctx): Promise<Response> { | ||
| 758 | 753 | |
| 759 | 754 | // POST — mint it; the link is in this answer only. |
| 760 | 755 | export async function forgeRecoverySubmit(ctx: Ctx): Promise<Response> { |
| 756 | if (!signedInPage(ctx)) return notFoundPage(ctx); | |
| 761 | 757 | const user = ctx.auth.user; |
| 762 | if (user === undefined) return notFoundPage(ctx); | |
| 763 | 758 | const form = await readForm(ctx, "rw"); |
| 764 | 759 | if (form instanceof Response) return form; |
| 765 | 760 | const name = ctx.params["name"] ?? ""; |
src/web/pages/fork-flows.ts +2 −1
| @@ -9,11 +9,12 @@ import { emptyList } from "../empty_words.ts"; | ||
| 9 | 9 | import { html } from "../html.ts"; |
| 10 | 10 | import { page } from "../layout.ts"; |
| 11 | 11 | import { listCard, row, time } from "../ui.ts"; |
| 12 | import { signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | |
| 13 | 14 | export function forkFlowsPage(ctx: Ctx): Response { |
| 14 | 15 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 16 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 15 | 17 | const user = ctx.auth.user; |
| 16 | if (user === undefined) return signInFirst(ctx); | |
| 17 | 18 | const reading = performance.now(); |
| 18 | 19 | const f = forkFlows(ctx.app, user); |
| 19 | 20 | const empty = f.follows.length + f.sent.length + f.offered.length === 0; |
src/web/pages/games.ts +4 −4
| @@ -168,7 +168,7 @@ export async function gameServersSubmit(ctx: Ctx): Promise<Response> { | ||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | export function boxOf(ctx: Ctx, need: Role, service = ""): { box: GameBox; role: Role } | Response { |
| 171 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 171 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 172 | 172 | const box = boxNamed(ctx.app.db, ctx.params.box ?? ""); |
| 173 | 173 | if (box === undefined) return notFoundPage(ctx); |
| 174 | 174 | // Seeing the box's page needs a grant on any of it; acting on it, the role there. |
| @@ -189,7 +189,7 @@ const startBox = (): Html => html`<form method="post" action="/talk" class="mt"> | ||
| 189 | 189 | // GET /games |
| 190 | 190 | export function gamesPage(ctx: Ctx): Response { |
| 191 | 191 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 192 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 192 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 193 | 193 | const user = ctx.auth.user; |
| 194 | 194 | const boxes = listBoxes(ctx.app.db).filter((b) => seesBox(ctx.app.db, user, b.id)); |
| 195 | 195 | return timePhase(ctx.request, "render", () => page({ |
| @@ -217,7 +217,7 @@ export function gamesPage(ctx: Ctx): Response { | ||
| 217 | 217 | // POST /settings/minecraft/code: a one-time code (ten minutes) the person types in game as !forge |
| 218 | 218 | // link <code>. |
| 219 | 219 | export async function gameLinkCode(ctx: Ctx): Promise<Response> { |
| 220 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 220 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 221 | 221 | const form = await readForm(ctx, "rw"); |
| 222 | 222 | if (form instanceof Response) return form; |
| 223 | 223 | const code = newLinkCode(ctx.app, ctx.auth.user); |
| @@ -227,7 +227,7 @@ export async function gameLinkCode(ctx: Ctx): Promise<Response> { | ||
| 227 | 227 | |
| 228 | 228 | // POST /settings/minecraft/unlink: forget one of the person's linked names. |
| 229 | 229 | export async function gameLinkRemove(ctx: Ctx): Promise<Response> { |
| 230 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 230 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 231 | 231 | const form = await readForm(ctx, "rw"); |
| 232 | 232 | if (form instanceof Response) return form; |
| 233 | 233 | unlink(ctx.app, ctx.auth.user.id, field(form, "box"), field(form, "player")); |
src/web/pages/games_client_pack.ts +2 −1
| @@ -15,6 +15,7 @@ import { pageHead } from "../chrome.ts"; | ||
| 15 | 15 | import { flashTo, page } from "../layout.ts"; |
| 16 | 16 | import { btn } from "../ui.ts"; |
| 17 | 17 | import { boxOf } from "./games.ts"; |
| 18 | import { signedInPage } from "../../http/page_may.ts"; | |
| 18 | 19 | |
| 19 | 20 | // POST /games/:box/:service/pack/link: a link for the service's pack, 30 days, shown once. |
| 20 | 21 | export async function gamePackLink(ctx: Ctx): Promise<Response> { |
| @@ -70,7 +71,7 @@ export async function gamePackLinked(ctx: Ctx): Promise<Response> { | ||
| 70 | 71 | const box = link === undefined ? undefined : boxById(ctx.app.db, link.boxId); |
| 71 | 72 | if (link === undefined || box === undefined) return new Response("not found", { status: 404 }); |
| 72 | 73 | const headers = new Headers({ location: rawOf(ctx), "cache-control": "private, no-store" }); |
| 73 | if (ctx.auth.user === undefined) { | |
| 74 | if (!signedInPage(ctx)) { | |
| 74 | 75 | const client = clientBucket(ctx.request); |
| 75 | 76 | const admitted = admitVisitor(ctx.app.db, () => loadKey(ctx.app.config.dataDir), { |
| 76 | 77 | headers: ctx.request.headers, |
src/web/pages/gate.ts +2 −2
| @@ -72,7 +72,7 @@ export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null { | ||
| 72 | 72 | export async function liftHoldSubmit(ctx: Ctx): Promise<Response> { |
| 73 | 73 | const found = threadContext(ctx, "issue"); |
| 74 | 74 | if (found instanceof Response) return found; |
| 75 | if (!signedInPage(ctx, "gate")) return signInFirst(ctx); | |
| 75 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 76 | 76 | const form = await readForm(ctx, "rw"); |
| 77 | 77 | if (form instanceof Response) return form; |
| 78 | 78 | const repo = loadRepo(ctx) ?? found.repo; |
| @@ -223,7 +223,7 @@ export function heldPage(ctx: Ctx): Response { | ||
| 223 | 223 | export async function heldApply(ctx: Ctx): Promise<Response> { |
| 224 | 224 | const repo = loadRepo(ctx); |
| 225 | 225 | if (!repo) return notFoundPage(ctx); |
| 226 | if (!signedInPage(ctx, "gate")) return signInFirst(ctx); | |
| 226 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 227 | 227 | const form = await readForm(ctx, "rw"); |
| 228 | 228 | if (form instanceof Response) return form; |
| 229 | 229 | const dest = `${repoBase(repo)}/held`; |
src/web/pages/gifts.ts +1 −1
| @@ -52,7 +52,7 @@ export function giftsBlock(ctx: Ctx, shown?: Shown, refusal?: string): Html | nu | ||
| 52 | 52 | |
| 53 | 53 | // POST /settings/gifts |
| 54 | 54 | export async function giftMake(ctx: Ctx): Promise<Response> { |
| 55 | if (!signedInPage(ctx, "gifts")) return signInFirst(ctx); | |
| 55 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 56 | 56 | const form = await readForm(ctx); |
| 57 | 57 | if (form instanceof Response) return form; |
| 58 | 58 | const made = giveGift(ctx.app, ctx.auth.user, publicOrigin(ctx.app.config.url, ctx.url.origin)); |
src/web/pages/global-map.ts +2 −1
| @@ -45,6 +45,7 @@ import { | ||
| 45 | 45 | type Marks, |
| 46 | 46 | type Word, |
| 47 | 47 | } from "./map.ts"; |
| 48 | import { signedInPage } from "../../http/page_may.ts"; | |
| 48 | 49 | |
| 49 | 50 | export interface Lane { |
| 50 | 51 | readonly repo: Repo; |
| @@ -298,8 +299,8 @@ export function nextThings(lanes: readonly Lane[], n = NEXT_COUNT): Html { | ||
| 298 | 299 | |
| 299 | 300 | /** GET /map — every app the viewer can see, one lane each. */ |
| 300 | 301 | export function globalMapPage(ctx: Ctx): Response { |
| 302 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 301 | 303 | const viewer = ctx.auth.user; |
| 302 | if (!viewer) return signInFirst(ctx); | |
| 303 | 304 | const { request } = ctx; |
| 304 | 305 | notePhase(request, "session", takeSessionTime(request)); |
| 305 | 306 | const spent: Spent = { layoutMs: 0 }; |
src/web/pages/grants.ts +2 −2
| @@ -76,7 +76,7 @@ function grantsView(grants: readonly OAuthGrant[], reused: readonly ReusedGrant[ | ||
| 76 | 76 | |
| 77 | 77 | // GET /settings/grants |
| 78 | 78 | export function grantsPage(ctx: Ctx): Response { |
| 79 | if (!signedInPage(ctx, "grants")) return signInFirst(ctx); | |
| 79 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 80 | 80 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 81 | 81 | const grants = timePhase(ctx.request, "grants", () => myOAuthGrants(ctx.app, ctx.auth.user)); |
| 82 | 82 | const reused = myReusedGrants(ctx.app, ctx.auth.user); |
| @@ -87,7 +87,7 @@ export function grantsPage(ctx: Ctx): Response { | ||
| 87 | 87 | |
| 88 | 88 | // POST /settings/grants/:id/revoke |
| 89 | 89 | export async function grantRevoke(ctx: Ctx): Promise<Response> { |
| 90 | if (!signedInPage(ctx, "grants")) return signInFirst(ctx); | |
| 90 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 91 | 91 | const form = await readForm(ctx, "admin"); |
| 92 | 92 | if (form instanceof Response) return form; |
| 93 | 93 | const revoked = revokeOAuthGrant(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
src/web/pages/home_flow.ts +6 −5
| @@ -81,6 +81,7 @@ import { parkedSection } from "../parked_lines.ts"; | ||
| 81 | 81 | import { parkedFor } from "../../flow/parked_read.ts"; |
| 82 | 82 | import { firstWeekBlock } from "../first_week.ts"; |
| 83 | 83 | import { idleFor, type IdleReason } from "../../crew/idle_reason.ts"; |
| 84 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 84 | 85 | |
| 85 | 86 | /** |
| 86 | 87 | * The events that can move work between lanes, per lane. A burst of them is one fetch of the lane. |
| @@ -438,8 +439,8 @@ function viewSwitch(view: "lanes" | "table", only: string | null): Html { | ||
| 438 | 439 | // redirects here. |
| 439 | 440 | export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited<ReturnType<typeof spawnedForge>> }): Promise<Response> { |
| 440 | 441 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 442 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 441 | 443 | const user = ctx.auth.user; |
| 442 | if (user === undefined) return signInFirst(ctx); | |
| 443 | 444 | const { view, asked } = viewOf(ctx); |
| 444 | 445 | const only = filterOf(ctx.url); |
| 445 | 446 | const mine = waitsOf(ctx.url); |
| @@ -454,7 +455,7 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 454 | 455 | // A spawned forge's owner is a client: the forge-wide figures are not theirs to see, whole home |
| 455 | 456 | // or lean. |
| 456 | 457 | const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app)); |
| 457 | const wide = user.isAdmin && spawned === undefined; | |
| 458 | const wide = adminPage(ctx) && spawned === undefined; | |
| 458 | 459 | const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now); |
| 459 | 460 | const need = needLine(brokenOf(picture, wide, ctx.app.config.dataDir, now), new Set(asksToAnswer(ctx.app, user).map((a) => a.username)).size); |
| 460 | 461 | // What the old home also carried and is not a lane: the box that tells the crew (with Notes and |
| @@ -597,15 +598,15 @@ export async function liveLaneFragment(ctx: Ctx): Promise<Response> { | ||
| 597 | 598 | // GET /live/strip — an admin's figures, alone; no one else has a strip. |
| 598 | 599 | export async function liveStripFragment(ctx: Ctx): Promise<Response> { |
| 599 | 600 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 600 | const user = ctx.auth.user; | |
| 601 | if (user === undefined) { | |
| 601 | if (!signedInPage(ctx)) { | |
| 602 | 602 | notePhase(ctx.request, "render", 0); |
| 603 | 603 | return fragment(html``, { status: 404 }); |
| 604 | 604 | } |
| 605 | const user = ctx.auth.user; | |
| 605 | 606 | const now = Date.now(); |
| 606 | 607 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now)); |
| 607 | 608 | const rendering = performance.now(); |
| 608 | const wide = user.isAdmin && (await spawnedForge(ctx.app)) === undefined; | |
| 609 | const wide = adminPage(ctx) && (await spawnedForge(ctx.app)) === undefined; | |
| 609 | 610 | const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) }); |
| 610 | 611 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 611 | 612 | return res; |
src/web/pages/hosted-forges.ts +2 −2
| @@ -120,8 +120,8 @@ export function forgeReachRows( | ||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 123 | if (!signedInPage(ctx, "hosted-forges")) return signInFirst(ctx); | |
| 124 | if (!adminPage(ctx, "hosted-forges", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 123 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 124 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 125 | 125 | return undefined; |
| 126 | 126 | } |
| 127 | 127 |
src/web/pages/identities.ts +2 −2
| @@ -67,7 +67,7 @@ const card = (c: Connection): Html => { | ||
| 67 | 67 | // GET /settings/identities |
| 68 | 68 | export function identitiesPage(ctx: Ctx): Response { |
| 69 | 69 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 70 | if (!signedInPage(ctx, "identities")) return signInFirst(ctx); | |
| 70 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 71 | 71 | const list = connectionsOf(ctx.app, ctx.auth.user); |
| 72 | 72 | const body = html`<section class="settings-block"> |
| 73 | 73 | <h2>Proven identities</h2> |
| @@ -100,7 +100,7 @@ const said = (ctx: Ctx, message: string, ok: boolean): Response => | ||
| 100 | 100 | |
| 101 | 101 | /** Read the form as the signed-in account, same-origin; the acts below share it. */ |
| 102 | 102 | async function acting(ctx: Ctx): Promise<{ form: import("../form.ts").Form } | Response> { |
| 103 | if (!signedInPage(ctx, "identities")) return signInFirst(ctx); | |
| 103 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 104 | 104 | const form = await readForm(ctx, "admin"); |
| 105 | 105 | return form instanceof Response ? form : { form }; |
| 106 | 106 | } |
src/web/pages/inventory.ts +1 −1
| @@ -63,7 +63,7 @@ function tally(items: readonly InventoryItem[]): string { | ||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | export async function inventoryPage(ctx: Ctx): Promise<Response> { |
| 66 | if (!signedInPage(ctx, "inventory")) return signInFirst(ctx); | |
| 66 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 67 | 67 | const user = ctx.auth.user; |
| 68 | 68 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 69 | 69 | const origins = listUserOrigins(ctx.app, user); |
src/web/pages/issues.ts +7 −7
| @@ -149,7 +149,7 @@ export function newIssuePage(ctx: Ctx): Response { | ||
| 149 | 149 | if (!repo) return timePhase(request, "render", () => notFoundPage(ctx)); |
| 150 | 150 | // `?sealed=1`: the repository page's "report it sealed" link. |
| 151 | 151 | const sealed = ctx.url.searchParams.get("sealed") === "1"; |
| 152 | if (!ctx.auth.user) { | |
| 152 | if (!signedInPage(ctx)) { | |
| 153 | 153 | const open = timePhase(request, "access", () => canRead(ctx.app.db, repo, undefined)); |
| 154 | 154 | return timePhase(request, "render", () => |
| 155 | 155 | open ? accountOrReport(ctx, repo, sealed) : signInFirst(ctx), |
| @@ -215,8 +215,8 @@ function accountOrReport(ctx: Ctx, repo: Repo, sealed: boolean): Response { | ||
| 215 | 215 | * repositories the viewer may write. Each carries `from` along. |
| 216 | 216 | */ |
| 217 | 217 | export function newIssueAnywhere(ctx: Ctx): Response { |
| 218 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 218 | 219 | const user = ctx.auth.user; |
| 219 | if (user === undefined) return signInFirst(ctx); | |
| 220 | 220 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 221 | 221 | const from = cleanFrom(ctx.url.searchParams.get("from")); |
| 222 | 222 | const query = from === undefined ? "" : `?from=${encodeURIComponent(from)}`; |
| @@ -250,7 +250,7 @@ export function newIssueAnywhere(ctx: Ctx): Response { | ||
| 250 | 250 | export async function newIssueSubmit(ctx: Ctx): Promise<Response> { |
| 251 | 251 | const repo = loadRepo(ctx); |
| 252 | 252 | if (!repo) return notFoundPage(ctx); |
| 253 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 253 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 254 | 254 | const form = await readForm(ctx, "rw"); |
| 255 | 255 | if (form instanceof Response) return form; |
| 256 | 256 | |
| @@ -298,7 +298,7 @@ export function issueThreadFragment(ctx: Ctx): Response { | ||
| 298 | 298 | export async function issueSealSubmit(ctx: Ctx): Promise<Response> { |
| 299 | 299 | const found = threadContext(ctx, "issue"); |
| 300 | 300 | if (found instanceof Response) return found; |
| 301 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 301 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 302 | 302 | const form = await readForm(ctx, "rw"); |
| 303 | 303 | if (form instanceof Response) return form; |
| 304 | 304 | const sealed = field(form, "sealed") === "1"; |
| @@ -323,7 +323,7 @@ export async function issueSealSubmit(ctx: Ctx): Promise<Response> { | ||
| 323 | 323 | export async function issuePrivateSubmit(ctx: Ctx): Promise<Response> { |
| 324 | 324 | const found = threadContext(ctx, "issue"); |
| 325 | 325 | if (found instanceof Response) return found; |
| 326 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 326 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 327 | 327 | const form = await readForm(ctx, "rw"); |
| 328 | 328 | if (form instanceof Response) return form; |
| 329 | 329 | const made = await privateRepoForSealed(ctx.app, ctx.auth.user, found.repo, found.issue); |
| @@ -357,7 +357,7 @@ const BACK = new Map<string, { to: string; said: (n: number) => string }>([ | ||
| 357 | 357 | export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { |
| 358 | 358 | const found = threadContext(ctx, "issue"); |
| 359 | 359 | if (found instanceof Response) return found; |
| 360 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 360 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 361 | 361 | const form = await readForm(ctx, "rw"); |
| 362 | 362 | if (form instanceof Response) return form; |
| 363 | 363 | |
| @@ -414,7 +414,7 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 414 | 414 | export async function issueQuestionSubmit(ctx: Ctx): Promise<Response> { |
| 415 | 415 | const found = threadContext(ctx, "issue"); |
| 416 | 416 | if (found instanceof Response) return found; |
| 417 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 417 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 418 | 418 | const form = await readForm(ctx, "rw"); |
| 419 | 419 | if (form instanceof Response) return form; |
| 420 | 420 | const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`; |
src/web/pages/iterations.ts +1 −1
| @@ -584,7 +584,7 @@ const NOTE_ERRORS: Record<string, string> = { | ||
| 584 | 584 | export async function noteSubmit(ctx: Ctx): Promise<Response> { |
| 585 | 585 | const repo = loadRepo(ctx); |
| 586 | 586 | if (!repo) return notFoundPage(ctx); |
| 587 | if (!signedInPage(ctx, "iterations")) return signInFirst(ctx); | |
| 587 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 588 | 588 | const form = await readForm(ctx, "rw"); |
| 589 | 589 | if (form instanceof Response) return form; |
| 590 | 590 | const to = backTo(form, `${repoBase(repo)}/iterations`); |
src/web/pages/knobs.ts +2 −2
| @@ -51,8 +51,8 @@ export function knobsCard(ctx: Ctx): Html { | ||
| 51 | 51 | |
| 52 | 52 | // POST /settings/crew/knobs |
| 53 | 53 | export async function knobSet(ctx: Ctx): Promise<Response> { |
| 54 | if (!signedInPage(ctx, "knobs")) return signInFirst(ctx); | |
| 55 | if (!adminPage(ctx, "knobs", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 54 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 55 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 56 | 56 | const form = await readForm(ctx, "admin"); |
| 57 | 57 | if (form instanceof Response) return form; |
| 58 | 58 | const knob = field(form, "knob"); |
src/web/pages/limb.ts +3 −3
| @@ -153,7 +153,7 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 153 | 153 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 154 | 154 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); |
| 155 | 155 | if (!repo) return notFoundPage(ctx); |
| 156 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 156 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 157 | 157 | const number = Number(ctx.params.number); |
| 158 | 158 | const action = ctx.url.searchParams.get("action"); |
| 159 | 159 | if (action === "replan") return replanPreviewPage(ctx, repo, number); |
| @@ -350,7 +350,7 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 350 | 350 | export async function limbSubmit(ctx: Ctx): Promise<Response> { |
| 351 | 351 | const repo = loadRepo(ctx); |
| 352 | 352 | if (!repo) return notFoundPage(ctx); |
| 353 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 353 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 354 | 354 | const form = await readForm(ctx, "admin"); |
| 355 | 355 | if (form instanceof Response) return form; |
| 356 | 356 | const number = Number(ctx.params.number); |
| @@ -440,7 +440,7 @@ export function limbReceiptPage(ctx: Ctx): Response { | ||
| 440 | 440 | export async function limbUndo(ctx: Ctx): Promise<Response> { |
| 441 | 441 | const repo = loadRepo(ctx); |
| 442 | 442 | if (!repo) return notFoundPage(ctx); |
| 443 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 443 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 444 | 444 | const form = await readForm(ctx, "admin"); |
| 445 | 445 | if (form instanceof Response) return form; |
| 446 | 446 | const number = Number(ctx.params.number); |
src/web/pages/maintenance.ts +8 −8
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * once the forge is back, when and what was verified. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 7 | import { adminPage, signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 8 | 8 | import { json } from "../../http/respond.ts"; |
| 9 | 9 | import { emptyNote } from "../empty_words.ts"; |
| 10 | 10 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -42,8 +42,8 @@ import { diskLine } from "../../maintenance/disk_line.ts"; | ||
| 42 | 42 | import { readDisk } from "../../kernel/disk_reading.ts"; |
| 43 | 43 | |
| 44 | 44 | function admin(ctx: Ctx): Response | undefined { |
| 45 | if (!signedInPage(ctx, "maintenance")) return signInFirst(ctx); | |
| 46 | if (!adminPage(ctx, "maintenance", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 45 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 46 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 47 | 47 | return undefined; |
| 48 | 48 | } |
| 49 | 49 | |
| @@ -342,9 +342,9 @@ function quietedRows(withActions: boolean, rows: readonly Quieted[]): Html { | ||
| 342 | 342 | |
| 343 | 343 | /** Who may press: a forge admin who is a person, the gate the finding cards' buttons have. */ |
| 344 | 344 | function mayQuiet(ctx: Ctx): Response | undefined { |
| 345 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 345 | 346 | const user = ctx.auth.user; |
| 346 | if (user === undefined) return signInFirst(ctx); | |
| 347 | if (!adminPage(ctx, "maintenance", user.isAdmin)) return notFoundPage(ctx); | |
| 347 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 348 | 348 | if (user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a person may quiet a finding." }); |
| 349 | 349 | return undefined; |
| 350 | 350 | } |
| @@ -410,7 +410,7 @@ export function stalePullsSection(ctx: Ctx, withActions: boolean): Html { | ||
| 410 | 410 | */ |
| 411 | 411 | export async function staleAction(ctx: Ctx): Promise<Response> { |
| 412 | 412 | const user = ctx.auth.user; |
| 413 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 413 | if (!personAdminPage(ctx)) | |
| 414 | 414 | return flashTo(ctx, "/maintenance", { tone: "danger", message: STALE_WORDS.forbidden }); |
| 415 | 415 | const form = await readForm(ctx, "admin"); |
| 416 | 416 | if (form instanceof Response) return form; |
| @@ -442,7 +442,7 @@ function mergedRows(withActions: boolean, found: readonly MergedBranch[]): Html | ||
| 442 | 442 | */ |
| 443 | 443 | export async function mergedAction(ctx: Ctx): Promise<Response> { |
| 444 | 444 | const user = ctx.auth.user; |
| 445 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 445 | if (!personAdminPage(ctx)) | |
| 446 | 446 | return flashTo(ctx, "/maintenance", { tone: "danger", message: MERGED_WORDS.forbidden }); |
| 447 | 447 | const form = await readForm(ctx, "admin"); |
| 448 | 448 | if (form instanceof Response) return form; |
| @@ -475,7 +475,7 @@ function previewRows(withActions: boolean, found: readonly PreviewDir[]): Html { | ||
| 475 | 475 | */ |
| 476 | 476 | export async function previewAction(ctx: Ctx): Promise<Response> { |
| 477 | 477 | const user = ctx.auth.user; |
| 478 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 478 | if (!personAdminPage(ctx)) | |
| 479 | 479 | return flashTo(ctx, "/maintenance", { tone: "danger", message: PREVIEW_WORDS.forbidden }); |
| 480 | 480 | const form = await readForm(ctx, "admin"); |
| 481 | 481 | if (form instanceof Response) return form; |
src/web/pages/maintenance_budgets.ts +2 −1
| @@ -13,6 +13,7 @@ import { field as formField, readForm } from "../form.ts"; | ||
| 13 | 13 | import { html, type Html } from "../html.ts"; |
| 14 | 14 | import { flashTo } from "../layout.ts"; |
| 15 | 15 | import { btn, field as formControl } from "../ui.ts"; |
| 16 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 16 | 17 | |
| 17 | 18 | /** Every duty's budget row, in `names` order: two reads for all of them, not three a duty. */ |
| 18 | 19 | export function budgetRows(app: App, names: readonly string[], now = new Date()): Html[] { |
| @@ -40,8 +41,8 @@ function budgetOfRow(d: Duty, b: Budget, u: { runs: number; dollars: number }): | ||
| 40 | 41 | |
| 41 | 42 | /** POST /maintenance/budget: an admin moves one duty's budgets; a blank value goes back to the duty's own. */ |
| 42 | 43 | export async function maintenanceBudget(ctx: Ctx): Promise<Response> { |
| 44 | if (!personAdminPage(ctx)) return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a forge admin who is a person sets a budget." }); | |
| 43 | 45 | const user = ctx.auth.user; |
| 44 | if (user === undefined || !user.isAdmin || user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a forge admin who is a person sets a budget." }); | |
| 45 | 46 | const form = await readForm(ctx, "admin"); |
| 46 | 47 | if (form instanceof Response) return form; |
| 47 | 48 | const duty = duties().find((d) => d.name === formField(form, "duty")); |
src/web/pages/migrate.ts +3 −3
| @@ -710,7 +710,7 @@ async function show( | ||
| 710 | 710 | // GET /migrate |
| 711 | 711 | export async function migratePage(ctx: Ctx): Promise<Response> { |
| 712 | 712 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 713 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 713 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 714 | 714 | const q = ctx.url.searchParams; |
| 715 | 715 | const origins = await timePhaseAsync(ctx.request, "origins", () => |
| 716 | 716 | originChoices(ctx), |
| @@ -759,7 +759,7 @@ export async function migratePage(ctx: Ctx): Promise<Response> { | ||
| 759 | 759 | |
| 760 | 760 | // POST /migrate |
| 761 | 761 | export async function migrateSubmit(ctx: Ctx): Promise<Response> { |
| 762 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 762 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 763 | 763 | const form = await readForm(ctx, "rw"); |
| 764 | 764 | if (form instanceof Response) return form; |
| 765 | 765 | const values: MigrateValues = { |
| @@ -944,7 +944,7 @@ const migrateJobJs = /* js */ ` | ||
| 944 | 944 | |
| 945 | 945 | export function migrationJobPage(ctx: Ctx): Response { |
| 946 | 946 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 947 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 947 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 948 | 948 | const user = ctx.auth.user; |
| 949 | 949 | const found = timePhase(ctx.request, "job", () => |
| 950 | 950 | migrationJobFor(user, ctx.params.job ?? ""), |
src/web/pages/milestones.ts +1 −1
| @@ -697,7 +697,7 @@ export async function milestonePage( | ||
| 697 | 697 | export async function milestoneWatch(ctx: Ctx): Promise<Response> { |
| 698 | 698 | const repo = loadRepo(ctx); |
| 699 | 699 | if (!repo) return notFoundPage(ctx); |
| 700 | if (!signedInPage(ctx, "milestones")) return signInFirst(ctx); | |
| 700 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 701 | 701 | const form = await readForm(ctx, "rw"); |
| 702 | 702 | if (form instanceof Response) return form; |
| 703 | 703 | const number = Number(ctx.params.number); |
src/web/pages/model.ts +4 −4
| @@ -153,8 +153,8 @@ export function grantCard(ctx: Ctx, user: User, at: string): Html { | ||
| 153 | 153 | |
| 154 | 154 | // POST /settings/accounts/:username/model |
| 155 | 155 | export async function grantAct(ctx: Ctx): Promise<Response> { |
| 156 | if (!signedInPage(ctx, "model")) return signInFirst(ctx); | |
| 157 | if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 156 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 157 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 158 | 158 | const form = await readForm(ctx, "admin"); |
| 159 | 159 | if (form instanceof Response) return form; |
| 160 | 160 | const username = ctx.params.username ?? ""; |
| @@ -182,8 +182,8 @@ export async function grantAct(ctx: Ctx): Promise<Response> { | ||
| 182 | 182 | |
| 183 | 183 | // POST /settings/accounts/:username/ceiling |
| 184 | 184 | export async function ceilingAct(ctx: Ctx): Promise<Response> { |
| 185 | if (!signedInPage(ctx, "model")) return signInFirst(ctx); | |
| 186 | if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 185 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 186 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 187 | 187 | const form = await readForm(ctx, "admin"); |
| 188 | 188 | if (form instanceof Response) return form; |
| 189 | 189 | const username = ctx.params.username ?? ""; |
src/web/pages/my-repos.ts +2 −1
| @@ -11,12 +11,13 @@ import { html } from "../html.ts"; | ||
| 11 | 11 | import { page } from "../layout.ts"; |
| 12 | 12 | import { emptyList } from "../empty_words.ts"; |
| 13 | 13 | import { btn, listCard, row } from "../ui.ts"; |
| 14 | import { signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | |
| 15 | 16 | // GET /repos |
| 16 | 17 | export function myReposPage(ctx: Ctx): Response { |
| 17 | 18 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 19 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 18 | 20 | const user = ctx.auth.user; |
| 19 | if (user === undefined) return signInFirst(ctx); | |
| 20 | 21 | const reading = performance.now(); |
| 21 | 22 | const repos = listReposWritableTo(ctx.app.db, user, { limit: 200, withoutArchived: true }); |
| 22 | 23 | const body = |
src/web/pages/new-forge.ts +2 −1
| @@ -59,6 +59,7 @@ import { cloudsOffered, NO_CHARGE, otherPlaces, placeWords, roomWords, whereFiel | ||
| 59 | 59 | import { catalogPlan } from "../../spawn/cloud_placement.ts"; |
| 60 | 60 | import { TAB_FORGE_OFFER, TAB_FORGE_PAGE } from "../tabforge/words.ts"; |
| 61 | 61 | import { CEILING_PAGE } from "../../cloud/ceiling.ts"; |
| 62 | import { adminPage } from "../../http/page_may.ts"; | |
| 62 | 63 | |
| 63 | 64 | interface Values { |
| 64 | 65 | readonly name: string; |
| @@ -666,7 +667,7 @@ export async function newForgePage(ctx: Ctx): Promise<Response> { | ||
| 666 | 667 | if (user && user.kind !== "user") return notFoundPage(ctx); |
| 667 | 668 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 668 | 669 | // Only an admin is offered clouds, so only an admin's visit reads the providers. |
| 669 | if (user?.isAdmin === true) await refreshForPage(ctx.app); | |
| 670 | if (adminPage(ctx)) await refreshForPage(ctx.app); | |
| 670 | 671 | const reads = await readsFor(ctx, user); |
| 671 | 672 | const rendering = performance.now(); |
| 672 | 673 | // A code in the address moves to a cookie and out of the address (the log and history never hold |
src/web/pages/next.ts +2 −2
| @@ -221,7 +221,7 @@ function cutMark(fit: number, top: boolean, byPace: boolean): Html { | ||
| 221 | 221 | /** One row, for an admin, to the page that sets the cap, while under a fifth is left (#13529). */ |
| 222 | 222 | function walletRow(ctx: Ctx, repo: Repo, base: string): Html | null { |
| 223 | 223 | const cap = monthCap(ctx.app.db, repo.id); |
| 224 | if (cap === undefined || !ctx.auth.user || !canAdmin(ctx.app.db, repo, ctx.auth.user)) return null; | |
| 224 | if (cap === undefined || !signedInPage(ctx) || !canAdmin(ctx.app.db, repo, ctx.auth.user)) return null; | |
| 225 | 225 | if (lowWallet(ctx.app.db, repo.id, new Date(), cap) === undefined) return null; |
| 226 | 226 | return listCard([row({ id: "wallet-row", href: `${base}/wallet`, title: html`Raise the monthly cap`, nav: true })]); |
| 227 | 227 | } |
| @@ -377,7 +377,7 @@ export function nextPage(ctx: Ctx): Response { | ||
| 377 | 377 | export async function nextSubmit(ctx: Ctx): Promise<Response> { |
| 378 | 378 | const repo: Repo | undefined = loadRepo(ctx); |
| 379 | 379 | if (!repo) return notFoundPage(ctx); |
| 380 | if (!signedInPage(ctx, "next")) return signInFirst(ctx); | |
| 380 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 381 | 381 | const form = await readForm(ctx, "rw"); |
| 382 | 382 | if (form instanceof Response) return form; |
| 383 | 383 | const dest = backTo(form, `${repoBase(repo)}/next`); |
src/web/pages/next_all.ts +2 −1
| @@ -11,11 +11,12 @@ import { pageHead, repoBase, signInFirst } from "../chrome.ts"; | ||
| 11 | 11 | import { html } from "../html.ts"; |
| 12 | 12 | import { page } from "../layout.ts"; |
| 13 | 13 | import { listCard, row } from "../ui.ts"; |
| 14 | import { signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | |
| 15 | 16 | export function nextAllPage(ctx: Ctx): Response { |
| 16 | 17 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 18 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 17 | 19 | const user = ctx.auth.user; |
| 18 | if (user === undefined) return signInFirst(ctx); | |
| 19 | 20 | const asked = ctx.url.searchParams.getAll("repo"); |
| 20 | 21 | const narrowed = onlyNames(asked).length > 0; |
| 21 | 22 | const groups = timePhase(ctx.request, "ranking", () => nextAll(ctx.app, user, asked)); |
src/web/pages/next_batch.ts +1 −1
| @@ -56,7 +56,7 @@ export function batchButtons(live: readonly number[]): Html { | ||
| 56 | 56 | export async function nextBatch(ctx: Ctx): Promise<Response> { |
| 57 | 57 | const repo = loadRepo(ctx); |
| 58 | 58 | if (!repo) return notFoundPage(ctx); |
| 59 | if (!signedInPage(ctx, "next_batch")) return signInFirst(ctx); | |
| 59 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 60 | 60 | const form = await readForm(ctx, "rw"); |
| 61 | 61 | if (form instanceof Response) return form; |
| 62 | 62 | const dest = backTo(form, `${repoBase(repo)}/next`); |
src/web/pages/notes.ts +4 −3
| @@ -23,6 +23,7 @@ import { flashTo, page } from "../layout.ts"; | ||
| 23 | 23 | import { btn, listCard, row, time } from "../ui.ts"; |
| 24 | 24 | import { cut } from "../../actions/ask_state_words.ts"; |
| 25 | 25 | import { emptyLine } from "../empty_words.ts"; |
| 26 | import { signedInPage } from "../../http/page_may.ts"; | |
| 26 | 27 | |
| 27 | 28 | const HERE = "/notes"; |
| 28 | 29 | const SHOWN = 100; |
| @@ -53,8 +54,8 @@ export const NOTES_CSS = /* css */ ` | ||
| 53 | 54 | // GET /notes |
| 54 | 55 | export async function notesView(ctx: Ctx): Promise<Response> { |
| 55 | 56 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 57 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 56 | 58 | const user = ctx.auth.user; |
| 57 | if (user === undefined) return signInFirst(ctx); | |
| 58 | 59 | const notes = timePhase(ctx.request, "notes", () => thoughtStream(ctx.app.db, user, { limit: SHOWN })); |
| 59 | 60 | // The release that carried a pull is known only for the forge's own repository. |
| 60 | 61 | const own = publicForgeRepo(ctx.app); |
| @@ -96,8 +97,8 @@ export async function notesView(ctx: Ctx): Promise<Response> { | ||
| 96 | 97 | |
| 97 | 98 | // POST /notes |
| 98 | 99 | export async function notesSave(ctx: Ctx): Promise<Response> { |
| 100 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 99 | 101 | const user = ctx.auth.user; |
| 100 | if (user === undefined) return signInFirst(ctx); | |
| 101 | 102 | const form = await readForm(ctx, "rw"); |
| 102 | 103 | if (form instanceof Response) return form; |
| 103 | 104 | const text = form.get("text"); |
| @@ -113,8 +114,8 @@ const OVERRULED = { accepted: "Built after all.", declined: "Declined." } as con | ||
| 113 | 114 | |
| 114 | 115 | // POST /notes/:id/overrule |
| 115 | 116 | export async function notesOverrule(ctx: Ctx): Promise<Response> { |
| 117 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 116 | 118 | const user = ctx.auth.user; |
| 117 | if (user === undefined) return signInFirst(ctx); | |
| 118 | 119 | const form = await readForm(ctx, "rw"); |
| 119 | 120 | if (form instanceof Response) return form; |
| 120 | 121 | const done = overruleNote(ctx.app, user, ctx.params["id"] ?? "", form.get("do")); |
src/web/pages/now.ts +2 −1
| @@ -12,12 +12,13 @@ import { notFoundPage, signInFirst } from "../chrome.ts"; | ||
| 12 | 12 | import { html } from "../html.ts"; |
| 13 | 13 | import { page } from "../layout.ts"; |
| 14 | 14 | import { row, time } from "../ui.ts"; |
| 15 | import { signedInPage } from "../../http/page_may.ts"; | |
| 15 | 16 | |
| 16 | 17 | // GET /now/:stage |
| 17 | 18 | export function nowPage(ctx: Ctx): Response { |
| 18 | 19 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 20 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 19 | 21 | const user = ctx.auth.user; |
| 20 | if (user === undefined) return signInFirst(ctx); | |
| 21 | 22 | const stage = NOW_STAGES.find((s) => s === ctx.params["stage"]); |
| 22 | 23 | if (stage === undefined || !mayReadNow(user)) return notFoundPage(ctx); |
| 23 | 24 | const reading = performance.now(); |
src/web/pages/oauth.ts +3 −2
| @@ -22,6 +22,7 @@ import { field, readForm } from "../form.ts"; | ||
| 22 | 22 | import { html, type Html } from "../html.ts"; |
| 23 | 23 | import { page, redirect } from "../layout.ts"; |
| 24 | 24 | import { btn, field as formField } from "../ui.ts"; |
| 25 | import { signedInPage } from "../../http/page_may.ts"; | |
| 25 | 26 | |
| 26 | 27 | const PARAMS = [ |
| 27 | 28 | "client_id", |
| @@ -182,7 +183,7 @@ const fromQuery = (ctx: Ctx): Params => | ||
| 182 | 183 | ) as Params; |
| 183 | 184 | |
| 184 | 185 | export function authorizePage(ctx: Ctx): Response { |
| 185 | if (ctx.auth.user === undefined || ctx.auth.via === "token") | |
| 186 | if (!signedInPage(ctx) || ctx.auth.via === "token") | |
| 186 | 187 | return guard( |
| 187 | 188 | redirect( |
| 188 | 189 | `/signin?next=${encodeURIComponent(ctx.url.pathname + ctx.url.search)}`, |
| @@ -206,7 +207,7 @@ export function authorizePage(ctx: Ctx): Response { | ||
| 206 | 207 | export async function authorizeSubmit(ctx: Ctx): Promise<Response> { |
| 207 | 208 | const form = await readForm(ctx); |
| 208 | 209 | if (form instanceof Response) return form; |
| 209 | if (ctx.auth.user === undefined || ctx.auth.via === "token") | |
| 210 | if (!signedInPage(ctx) || ctx.auth.via === "token") | |
| 210 | 211 | return forbiddenPage(ctx, SIGN_IN_TO_DO); |
| 211 | 212 | const request = parseAuthRequest(ctx.app.db, (n) => field(form, n)); |
| 212 | 213 | if (!request.ok) return refused(ctx, request.error); |
src/web/pages/offer-receipt.ts +1 −1
| @@ -12,7 +12,7 @@ import { html } from "../html.ts"; | ||
| 12 | 12 | import { page } from "../layout.ts"; |
| 13 | 13 | |
| 14 | 14 | export function offerReceiptPage(ctx: Ctx): Response { |
| 15 | if (!signedInPage(ctx, "offer-receipt")) return signInFirst(ctx); | |
| 15 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 16 | 16 | const r = readForkOffer(ctx.app.db, ctx.auth.user, ctx.params.id ?? ""); |
| 17 | 17 | if (r === undefined) return notFoundPage(ctx); |
| 18 | 18 | const [owner = "", name = ""] = r.upstream.split("/"); |
src/web/pages/offer-upstream.ts +5 −5
| @@ -52,7 +52,7 @@ export function offerCommitButton( | ||
| 52 | 52 | repo: Repo, |
| 53 | 53 | oid: string, |
| 54 | 54 | ): Html | null { |
| 55 | if (repo.forkParentId === null || ctx.auth.user === undefined) return null; | |
| 55 | if (repo.forkParentId === null || !signedInPage(ctx)) return null; | |
| 56 | 56 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return null; |
| 57 | 57 | return html`<form method="post" action="${repoBase(repo)}/commit/${oid}/offer" class="mt"> |
| 58 | 58 | ${btn("Offer upstream", { size: "sm", icon: "merge" })} |
| @@ -63,7 +63,7 @@ export function offerCommitButton( | ||
| 63 | 63 | export async function offerCommitPost(ctx: Ctx): Promise<Response> { |
| 64 | 64 | const repo = loadRepo(ctx); |
| 65 | 65 | if (!repo) return notFoundPage(ctx); |
| 66 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 66 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 67 | 67 | const form = await readForm(ctx, "rw"); |
| 68 | 68 | if (form instanceof Response) return form; |
| 69 | 69 | const rev = ctx.params.oid ?? ""; |
| @@ -88,7 +88,7 @@ export async function offerCommitPost(ctx: Ctx): Promise<Response> { | ||
| 88 | 88 | export async function offerWithdrawPost(ctx: Ctx): Promise<Response> { |
| 89 | 89 | const fork = loadRepo(ctx); |
| 90 | 90 | if (!fork) return notFoundPage(ctx); |
| 91 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 91 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 92 | 92 | const form = await readForm(ctx, "rw"); |
| 93 | 93 | if (form instanceof Response) return form; |
| 94 | 94 | const number = Number(ctx.params.number); |
| @@ -107,7 +107,7 @@ export async function offerWithdrawPost(ctx: Ctx): Promise<Response> { | ||
| 107 | 107 | * offer applies. |
| 108 | 108 | */ |
| 109 | 109 | export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null { |
| 110 | if (repo.forkParentId === null || ctx.auth.user === undefined) return null; | |
| 110 | if (repo.forkParentId === null || !signedInPage(ctx)) return null; | |
| 111 | 111 | const preview = previewOfferPull(ctx.app, ctx.auth.user, repo, pull.number); |
| 112 | 112 | if (!preview.ok) return null; |
| 113 | 113 | const p = preview.value; |
| @@ -128,7 +128,7 @@ export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null { | ||
| 128 | 128 | export async function offerPullPost(ctx: Ctx): Promise<Response> { |
| 129 | 129 | const repo = loadRepo(ctx); |
| 130 | 130 | if (!repo) return notFoundPage(ctx); |
| 131 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 131 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 132 | 132 | const form = await readForm(ctx, "rw"); |
| 133 | 133 | if (form instanceof Response) return form; |
| 134 | 134 | const number = Number(ctx.params.number); |
src/web/pages/og.ts +2 −1
| @@ -51,6 +51,7 @@ import { templateIdOfRef, templateRow } from "../../spawn/template_list.ts"; | ||
| 51 | 51 | import { marksFor } from "./map.ts"; |
| 52 | 52 | import { Busy, pngCache, type PngCache } from "../og/png-cache.ts"; |
| 53 | 53 | import { drawer } from "../og/raster.ts"; |
| 54 | import { signedInPage } from "../../http/page_may.ts"; | |
| 54 | 55 | |
| 55 | 56 | /** What an anonymous reader may see of a repository, or nothing. */ |
| 56 | 57 | function publicRepo(ctx: Ctx, repo: Repo | undefined): Repo | undefined { |
| @@ -351,7 +352,7 @@ function repoCard(ctx: Ctx, ref: string): CardInput | undefined { | ||
| 351 | 352 | |
| 352 | 353 | /** Whether this response is for the signed-in viewer alone, not for a shared cache. */ |
| 353 | 354 | function personal(ctx: Ctx, kind: OgKind, ref: string): boolean { |
| 354 | if (kind !== "repo" || ctx.auth.user === undefined) return false; | |
| 355 | if (kind !== "repo" || !signedInPage(ctx)) return false; | |
| 355 | 356 | const [owner, name] = ref.split("~"); |
| 356 | 357 | if (!owner || !name || !isSafeName(owner) || !isSafeName(name)) return false; |
| 357 | 358 | const repo = getRepo(ctx.app.db, owner, name); |
src/web/pages/org.ts +2 −2
| @@ -497,7 +497,7 @@ function orgSecrets(ctx: Ctx, name: string): Html | null { | ||
| 497 | 497 | // POST /:owner/-/subscriptions |
| 498 | 498 | export async function orgSubscriptionsSave(ctx: Ctx): Promise<Response> { |
| 499 | 499 | const org = requireOrgAdmin(ctx); |
| 500 | if (!org || ctx.auth.user === undefined || !adminPage(ctx, "org", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 500 | if (!org || !adminPage(ctx)) return notFoundPage(ctx); | |
| 501 | 501 | const form = await readForm(ctx, "admin"); |
| 502 | 502 | if (form instanceof Response) return form; |
| 503 | 503 | saveGrants(ctx, form, org.id, agentsOnForge(ctx)); |
| @@ -552,7 +552,7 @@ export function newOrgPage(ctx: Ctx): Response { | ||
| 552 | 552 | |
| 553 | 553 | // POST /organizations/new |
| 554 | 554 | export async function newOrgSubmit(ctx: Ctx): Promise<Response> { |
| 555 | if (!signedInPage(ctx, "org")) return signInFirst(ctx); | |
| 555 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 556 | 556 | const form = await readForm(ctx, "rw"); |
| 557 | 557 | if (form instanceof Response) return form; |
| 558 | 558 | const name = field(form, "name"); |
src/web/pages/origin-reach.ts +3 −3
| @@ -113,8 +113,8 @@ function askRow(a: HostAsk): Html { | ||
| 113 | 113 | * person has neither. |
| 114 | 114 | */ |
| 115 | 115 | export function reachBlock(ctx: Ctx, blocked?: Blocked): Html | null { |
| 116 | if (!signedInPage(ctx)) return null; | |
| 116 | 117 | const user = ctx.auth.user; |
| 117 | if (user === undefined) return null; | |
| 118 | 118 | const asks = asksOfUser(ctx.app.db, user.id); |
| 119 | 119 | const open = asks.filter((a) => a.state !== "offered"); |
| 120 | 120 | const named = blocked?.ask?.body["host"]; |
| @@ -183,7 +183,7 @@ export const reachJs = /* js */ ` | ||
| 183 | 183 | |
| 184 | 184 | // POST /settings/origins/reach — the button: ask the host to allow `host`. |
| 185 | 185 | export async function originReachAsk(ctx: Ctx): Promise<Response> { |
| 186 | if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx); | |
| 186 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 187 | 187 | const form = await readForm(ctx, "rw"); |
| 188 | 188 | if (form instanceof Response) return form; |
| 189 | 189 | const host = field(form, "host").trim(); |
| @@ -209,7 +209,7 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> { | ||
| 209 | 209 | |
| 210 | 210 | // POST /settings/origins/reach/dismiss — take one's own answered ask off the page. |
| 211 | 211 | export async function originReachDismiss(ctx: Ctx): Promise<Response> { |
| 212 | if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx); | |
| 212 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 213 | 213 | const form = await readForm(ctx, "rw"); |
| 214 | 214 | if (form instanceof Response) return form; |
| 215 | 215 | dismissAsk(ctx.app, ctx.auth.user, field(form, "host")); |
src/web/pages/origins.ts +1 −1
| @@ -248,7 +248,7 @@ export const callbackUri = (ctx: Ctx): string => | ||
| 248 | 248 | * enumerate whose GitHub is connected, let alone spend it. |
| 249 | 249 | */ |
| 250 | 250 | export function accountOnly(ctx: Ctx): Response | undefined { |
| 251 | if (!signedInPage(ctx, "origins")) return signInFirst(ctx); | |
| 251 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 252 | 252 | if (ctx.auth.via === "session" || ctx.auth.via === "password") |
| 253 | 253 | return undefined; |
| 254 | 254 | if (ctx.auth.scope === "admin") return undefined; |
src/web/pages/packs-settings.ts +3 −3
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | * the change is on /packs at once. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | import { signedInPage, personAdminPage } from "../../http/page_may.ts"; | |
| 10 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 11 | 11 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 12 | 12 | import { refreshCatalogQuietly } from "../../packs/catalog.ts"; |
| @@ -21,8 +21,8 @@ import { btn, field as uiField, row } from "../ui.ts"; | ||
| 21 | 21 | import { accountSections } from "./origins.ts"; |
| 22 | 22 | |
| 23 | 23 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 24 | if (!signedInPage(ctx, "packs-settings")) return signInFirst(ctx); | |
| 25 | if (!adminPage(ctx, "packs-settings", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 24 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 25 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 26 | 26 | return undefined; |
| 27 | 27 | } |
| 28 | 28 |
src/web/pages/packs.ts +2 −2
| @@ -20,7 +20,7 @@ import { btn, copyField, field as uiField, row, timeAgo } from "../ui.ts"; | ||
| 20 | 20 | import { listReposVisibleTo } from "../../core/repos.ts"; |
| 21 | 21 | import { changeRepos, editPack, getPack, history, listPacks, mayCurate, resolveRepos, slugOf, type CuratedPack, type PackRepo } from "../../packs/curated.ts"; |
| 22 | 22 | import { field, readForm } from "../form.ts"; |
| 23 | import { adminPage } from "../../http/page_may.ts"; | |
| 23 | import { personAdminPage } from "../../http/page_may.ts"; | |
| 24 | 24 | |
| 25 | 25 | const plural = (n: number, one: string): string => `${n} ${one}${n === 1 ? "" : "s"}`; |
| 26 | 26 | |
| @@ -226,7 +226,7 @@ export async function packPage(ctx: Ctx): Promise<Response> { | ||
| 226 | 226 | |
| 227 | 227 | // POST /packs/mirror (admin) |
| 228 | 228 | export async function packsMirror(ctx: Ctx): Promise<Response> { |
| 229 | if (!adminPage(ctx, "packs", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 229 | if (!personAdminPage(ctx)) return notFoundPage(ctx); | |
| 230 | 230 | const form = await readForm(ctx, "admin"); |
| 231 | 231 | if (form instanceof Response) return form; |
| 232 | 232 | const done = await mirrorPacks(ctx.app, ctx.auth.user); |
src/web/pages/passkeys.ts +3 −3
| @@ -63,7 +63,7 @@ const refuse = (status: number, message: string) => | ||
| 63 | 63 | /** A signed-in browser, on a same-origin request; else the refusal to send. */ |
| 64 | 64 | function sessionOnly(ctx: Ctx): Response | undefined { |
| 65 | 65 | if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE); |
| 66 | if (!signedInPage(ctx, "passkeys")) return refuse(401, "Sign in first."); | |
| 66 | if (!signedInPage(ctx)) return refuse(401, "Sign in first."); | |
| 67 | 67 | // A browser the platform edge signed in is a signed-in browser too: adding a |
| 68 | 68 | // passkey there is how an account comes to sign in without the edge (#9432). |
| 69 | 69 | if (ctx.auth.via !== "session" && ctx.auth.via !== "edge") |
| @@ -74,7 +74,7 @@ function sessionOnly(ctx: Ctx): Response | undefined { | ||
| 74 | 74 | // GET /settings/passkeys |
| 75 | 75 | export function passkeysPage(ctx: Ctx): Response { |
| 76 | 76 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 77 | if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx); | |
| 77 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 78 | 78 | const user = ctx.auth.user; |
| 79 | 79 | const keys = timePhase(ctx.request, "passkeys", () => listPasskeys(ctx.app.db, user.id)); |
| 80 | 80 | const rendering = performance.now(); |
| @@ -165,7 +165,7 @@ export async function passkeyAdd(ctx: Ctx): Promise<Response> { | ||
| 165 | 165 | |
| 166 | 166 | // POST /settings/passkeys/:id/delete |
| 167 | 167 | export async function passkeyDelete(ctx: Ctx): Promise<Response> { |
| 168 | if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx); | |
| 168 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 169 | 169 | const form = await readForm(ctx, "admin"); |
| 170 | 170 | if (form instanceof Response) return form; |
| 171 | 171 | const gone = removeOwnPasskey(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
src/web/pages/payments.ts +3 −2
| @@ -15,6 +15,7 @@ import { toCsv } from "../../text/csv_write.ts"; | ||
| 15 | 15 | import { securityFloor } from "../../http/respond.ts"; |
| 16 | 16 | import { EXPORT_PATH, EXPORT_WORDS } from "../../core/account_export.ts"; |
| 17 | 17 | import { paymentsFor, PAYMENTS_CAP, type PaymentLine } from "../../actions/forge_bill.ts"; |
| 18 | import { signedInPage } from "../../http/page_may.ts"; | |
| 18 | 19 | |
| 19 | 20 | const STATUS_WORDS = { paid: "Paid", refunded: "Refunded", failed: "Failed" } as const; |
| 20 | 21 | |
| @@ -75,8 +76,8 @@ export function paymentsCsvText(app: App, user: User | undefined, cap = PAYMENTS | ||
| 75 | 76 | // GET /settings/payments.csv: the page's rows, same order, up to `cap`; one build per person per |
| 76 | 77 | // CSV_GAP_MS. |
| 77 | 78 | export function paymentsCsv(ctx: Ctx, cap = PAYMENTS_CSV_CAP): Response { |
| 79 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 78 | 80 | const user = ctx.auth.user; |
| 79 | if (user === undefined) return signInFirst(ctx); | |
| 80 | 81 | const now = Date.now(); |
| 81 | 82 | const lastCsv = lastCsvOf(ctx.app); |
| 82 | 83 | if (now - (lastCsv.get(user.id) ?? 0) < CSV_GAP_MS) { |
| @@ -107,7 +108,7 @@ export const exportRow = (): Html => | ||
| 107 | 108 | |
| 108 | 109 | // GET /settings/payments |
| 109 | 110 | export function paymentsPage(ctx: Ctx): Response { |
| 110 | if (ctx.auth.user === undefined) return signInFirst(ctx); | |
| 111 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 111 | 112 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 112 | 113 | const rendering = performance.now(); |
| 113 | 114 | const { rows, more } = paymentsFor(ctx.app, ctx.auth.user); |
src/web/pages/people.ts +4 −4
| @@ -46,8 +46,8 @@ export function appsMade(ctx: Ctx): Map<string, string[]> { | ||
| 46 | 46 | |
| 47 | 47 | // GET /settings/people |
| 48 | 48 | export function peoplePage(ctx: Ctx): Response { |
| 49 | if (!signedInPage(ctx, "people")) return signInFirst(ctx); | |
| 50 | if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 49 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 50 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 51 | 51 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 52 | 52 | const only = wordFilter(ctx.url.searchParams.get("role")); |
| 53 | 53 | const rows = timePhase(ctx.request, "people", () => peopleByActivity(ctx.app.db, only)); |
| @@ -126,8 +126,8 @@ export function peoplePage(ctx: Ctx): Response { | ||
| 126 | 126 | |
| 127 | 127 | // POST /settings/people/:username/role |
| 128 | 128 | export async function roleAct(ctx: Ctx): Promise<Response> { |
| 129 | if (!signedInPage(ctx, "people")) return signInFirst(ctx); | |
| 130 | if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 129 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 130 | if (!adminPage(ctx)) return notFoundPage(ctx); | |
| 131 | 131 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 132 | 132 | const form = await readForm(ctx, "admin"); |
| 133 | 133 | if (form instanceof Response) return form; |
src/web/pages/proven_identities.ts +1 −1
| @@ -56,7 +56,7 @@ export function identitiesBlock(ctx: Ctx): Html { | ||
| 56 | 56 | // again. Only from the confirm page (`/-/confirm`), with the address typed back: the terminal asks |
| 57 | 57 | // first too. |
| 58 | 58 | export async function emailRemove(ctx: Ctx): Promise<Response> { |
| 59 | if (!signedInPage(ctx, "proven_identities")) return signInFirst(ctx); | |
| 59 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 60 | 60 | const form = await readForm(ctx, "rw"); |
| 61 | 61 | if (form instanceof Response) return form; |
| 62 | 62 | if (field(form, "confirm") !== ctx.auth.user.email) |
src/web/pages/pull-guest.ts +1 −1
| @@ -74,7 +74,7 @@ export async function guestWalls(ctx: Ctx, repo: Repo, pull: Pull, baseOid: stri | ||
| 74 | 74 | export async function pullApproveGuestSubmit(ctx: Ctx): Promise<Response> { |
| 75 | 75 | const found = pullContext(ctx); |
| 76 | 76 | if (found instanceof Response) return found; |
| 77 | if (!signedInPage(ctx, "pull-guest")) return signInFirst(ctx); | |
| 77 | if (!signedInPage(ctx)) return signInFirst(ctx); | |
| 78 | 78 | const form = await readForm(ctx, "rw"); |
| 79 | 79 | if (form instanceof Response) return form; |
| 80 | 80 | const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`; |
45 more files not shown.
new above
offline