Public: anyone can read this; the crew can change it.
Access 3, web pages: every page that gates on isAdmin or sign-in also asks may(), counted beside the old check #18400
Merged 2h 35m ago, live in production
scout/forge:scout/18395-access-3-web-pages-every-page-that-gates → main 0 commits fork 2 threads · 2 unresolved
111 files
changed +589
−296
- docs/features/may.md
- src/core/access_disagreement.ts
- src/http/may_beside.ts
- src/http/mcp/tool_may.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/audit.ts
- src/web/pages/backups.ts
- src/web/pages/billing.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/client_cloud.ts
- src/web/pages/cloud.ts
- src/web/pages/config.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/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/fleet-ops.ts
- src/web/pages/flow.ts
- src/web/pages/flows-all.ts
- src/web/pages/following.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/games.ts
- src/web/pages/gate.ts
- src/web/pages/gifts.ts
- src/web/pages/grants.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/migrate.ts
- src/web/pages/milestones.ts
- src/web/pages/model.ts
- src/web/pages/next.ts
- src/web/pages/next_batch.ts
- src/web/pages/offer-receipt.ts
- src/web/pages/offer-upstream.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/people.ts
- src/web/pages/proven_identities.ts
- src/web/pages/pull-guest.ts
- src/web/pages/pull.ts
- src/web/pages/pulls.ts
- src/web/pages/repo.ts
- src/web/pages/reports.ts
- src/web/pages/resilience.ts
- src/web/pages/runners.ts
- src/web/pages/runs.ts
- src/web/pages/scrapes.ts
- src/web/pages/secrets.ts
- src/web/pages/security.ts
- src/web/pages/security_controls.ts
- src/web/pages/series.ts
- src/web/pages/site.ts
- src/web/pages/sources.ts
- src/web/pages/spend-tab.ts
- src/web/pages/subscriptions.ts
- src/web/pages/system.ts
- src/web/pages/teams.ts
- src/web/pages/telemetry.ts
- src/web/pages/thread.ts
- src/web/pages/traffic.ts
- src/web/pages/trusted.ts
- src/web/pages/variants.ts
- src/web/pages/visitor_bring.ts
- src/web/pages/visitors.ts
- src/web/pages/week.ts
docs/features/may.md +8
| @@ -44,3 +44,11 @@ the evidence that moving the door changed nobody's access. | ||
| 44 | 44 | something asks `forge.write` with the credential you send, so an `ro` token is told it may only read |
| 45 | 45 | (`src/http/mcp/tool_may.ts`). The old scope floor is worked out beside it, and where the two part the count's door is |
| 46 | 46 | `mcp <tool>`. The terminal's "What I can do" lists `forge.write` with the rest. |
| 47 | ||
| 48 | **The web pages ask it.** A page only the admin sees asks `forge.administer`, and a page that needs you signed in asks | |
| 49 | by what the request does: `forge.read` to open it (GET), `forge.write` to change something (POST), both with the | |
| 50 | credential you send (`src/http/page_may.ts`). An `ro` token that opens its own page is no parting; one that posts is. | |
| 51 | An anonymous visit to a signed-in page parts on `forge.read`, which is open to all: that row says the page needs more | |
| 52 | than reading. The page's old check (`isAdmin`, an account | |
| 53 | behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is | |
| 54 | `web <page>`, the page's module. Nothing you can open on the web changes while the count is read. |
src/core/access_disagreement.ts +8 −2
| @@ -5,12 +5,16 @@ | ||
| 5 | 5 | * principal and what `may` said. No account, token or repository is written, so the table can be |
| 6 | 6 | * read by anyone who keeps the forge without learning who asked. |
| 7 | 7 | * |
| 8 | * The count is telemetry, written `quietly`: it records how the forge is asked, not anything a | |
| 9 | * page shows, so it must not move the write clock and turn a cached page's validator (#18395). | |
| 10 | * | |
| 8 | 11 | * Read it with `SELECT * FROM access_disagreement ORDER BY seen DESC` (docs/ROLES.md). |
| 9 | 12 | */ |
| 10 | 13 | |
| 11 | 14 | import type { Database } from "bun:sqlite"; |
| 12 | 15 | import type { Action } from "./may.ts"; |
| 13 | 16 | import type { PrincipalKind } from "./principal.ts"; |
| 17 | import { quietly } from "./write_clock.ts"; | |
| 14 | 18 | |
| 15 | 19 | /** Count one disagreement: `may` said `said`, the old check said the opposite. */ |
| 16 | 20 | export function noteDisagreement( |
| @@ -20,9 +24,11 @@ export function noteDisagreement( | ||
| 20 | 24 | principal: PrincipalKind, |
| 21 | 25 | said: boolean, |
| 22 | 26 | ): void { |
| 23 | db.query( | |
| 27 | quietly(db, () => | |
| 28 | db.query( | |
| 24 | 29 | `INSERT INTO access_disagreement (door, action, principal, may, seen, last_at) |
| 25 | 30 | VALUES (?1, ?2, ?3, ?4, 1, ?5) |
| 26 | 31 | ON CONFLICT (door, action, principal, may) DO UPDATE SET seen = seen + 1, last_at = excluded.last_at`, |
| 27 | ).run(door, action, principal, said ? 1 : 0, new Date().toISOString()); | |
| 32 | ).run(door, action, principal, said ? 1 : 0, new Date().toISOString()), | |
| 33 | ); | |
| 28 | 34 | } |
src/http/may_beside.ts added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | /** | |
| 2 | * `may` asked beside the check it is replacing (#18091, #18092, #18395): the principal the | |
| 3 | * request carries is asked `action`, and where its answer parts from `old` one row is counted in | |
| 4 | * `access_disagreement` under `door` (`core/access_disagreement.ts`). Returns what `may` said; a | |
| 5 | * door still in shadow returns its old answer itself. | |
| 6 | */ | |
| 7 | ||
| 8 | import { noteDisagreement } from "../core/access_disagreement.ts"; | |
| 9 | import { type Action, holds } from "../core/may.ts"; | |
| 10 | import { principalOf } from "../core/principal.ts"; | |
| 11 | import type { Ctx } from "./context.ts"; | |
| 12 | ||
| 13 | export function mayBeside(ctx: Ctx, door: string, action: Action, old: boolean): boolean { | |
| 14 | const asking = principalOf(ctx.auth); | |
| 15 | const said = holds(ctx.app.db, asking, action); | |
| 16 | if (said !== old) noteDisagreement(ctx.app.db, door, action, asking.kind, said); | |
| 17 | return said; | |
| 18 | } |
src/http/mcp/tool_may.ts +3 −6
| @@ -14,20 +14,17 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | import type { Database } from "bun:sqlite"; |
| 17 | import { noteDisagreement } from "../../core/access_disagreement.ts"; | |
| 18 | 17 | import { holds } from "../../core/may.ts"; |
| 19 | import { principalOf, principalOfUser } from "../../core/principal.ts"; | |
| 18 | import { principalOfUser } from "../../core/principal.ts"; | |
| 20 | 19 | import { scopeAllows } from "../../core/tokens.ts"; |
| 21 | 20 | import type { User } from "../../core/users.ts"; |
| 22 | 21 | import type { Ctx } from "../context.ts"; |
| 22 | import { mayBeside } from "../may_beside.ts"; | |
| 23 | 23 | |
| 24 | 24 | /** Is this account the forge's admin? What `adminOnly` and `listedTo: "admin"` ask. */ |
| 25 | 25 | export const adminAccount = (db: Database, user: User): boolean => holds(db, principalOfUser(user), "forge.administer"); |
| 26 | 26 | |
| 27 | 27 | /** May this call change something? What a tool's `writes` asks; `door` names it in the count. */ |
| 28 | 28 | export function mayToolWrite(ctx: Ctx, door: string): boolean { |
| 29 | const asking = principalOf(ctx.auth); | |
| 30 | const said = holds(ctx.app.db, asking, "forge.write"); | |
| 31 | if (said !== scopeAllows(ctx.auth.scope ?? "ro", "rw")) noteDisagreement(ctx.app.db, `mcp ${door}`, "forge.write", asking.kind, said); | |
| 32 | return said; | |
| 29 | return mayBeside(ctx, `mcp ${door}`, "forge.write", scopeAllows(ctx.auth.scope ?? "ro", "rw")); | |
| 33 | 30 | } |
src/http/page_may.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | /** | |
| 2 | * The web pages ask `may` in shadow (#18395), as the repository routes (`http/repo_may.ts`) and | |
| 3 | * the MCP tools (`http/mcp/tool_may.ts`) did before them: a page's old gate (`isAdmin`, a signed-in | |
| 4 | * account) still decides, `may(principal, action)` is worked out beside it, and where the two part | |
| 5 | * one row is counted in `access_disagreement` (door `web <page>`, the action, the kind of | |
| 6 | * principal; no account, token or repository). Nobody's access changes here. | |
| 7 | * | |
| 8 | * - `adminPage`: a page only the forge's admin sees asks `forge.administer`. | |
| 9 | * - `signedInPage`: a page that needs an account asks by what the request does. A read (GET, HEAD) | |
| 10 | * asks `forge.read`, so an `ro` token that reads its own page is no parting; a write asks | |
| 11 | * `forge.write`, which an `ro` token is refused. An anonymous read parts on `forge.read` | |
| 12 | * (open to all) from the sign-in gate (accounts only): that is a real difference, and the row | |
| 13 | * says so. | |
| 14 | */ | |
| 15 | ||
| 16 | import type { Action } from "../core/may.ts"; | |
| 17 | import type { User } from "../core/users.ts"; | |
| 18 | import type { Ctx } from "./context.ts"; | |
| 19 | import { mayBeside } from "./may_beside.ts"; | |
| 20 | ||
| 21 | /** Ask `may` beside the old answer, count a parting, and return the old answer. */ | |
| 22 | function shadow(ctx: Ctx, page: string, action: Action, old: boolean): boolean { | |
| 23 | mayBeside(ctx, `web ${page}`, action, old); | |
| 24 | return old; | |
| 25 | } | |
| 26 | ||
| 27 | /** The admin gate of `page`: `old` is the inline check's answer, and still the one that counts. */ | |
| 28 | export const adminPage = (ctx: Ctx, page: string, old: boolean): boolean => shadow(ctx, page, "forge.administer", old); | |
| 29 | ||
| 30 | /** A request with an account behind it. */ | |
| 31 | export type SignedIn = Ctx & { auth: Ctx["auth"] & { user: User } }; | |
| 32 | ||
| 33 | /** What a request to a page does, as `may` names it: reading, or a change. */ | |
| 34 | export const pageAction = (method: string): Action => (method === "GET" || method === "HEAD" ? "forge.read" : "forge.write"); | |
| 35 | ||
| 36 | /** The sign-in gate of `page`: is there an account? Asked of `may` beside it. */ | |
| 37 | export const signedInPage = (ctx: Ctx, page: string): ctx is SignedIn => | |
| 38 | shadow(ctx, page, pageAction(ctx.request.method), ctx.auth.user !== undefined); |
src/web/pages/access.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * never an address — stands for the caller. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { sshOn } from "../../settings/ssh.ts"; |
| 9 | 10 | import { listAccess } from "../../actions/access_log.ts"; |
| 10 | 11 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| @@ -18,7 +19,7 @@ import { accountSections } from "./origins.ts"; | ||
| 18 | 19 | // GET /settings/access |
| 19 | 20 | export function accessPage(ctx: Ctx): Response { |
| 20 | 21 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 21 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 22 | if (!signedInPage(ctx, "access")) return signInFirst(ctx); | |
| 22 | 23 | const user = ctx.auth.user; |
| 23 | 24 | const ua = ctx.url.searchParams.get("ua")?.slice(0, 100) ?? ""; |
| 24 | 25 | const path = ctx.url.searchParams.get("path")?.slice(0, 200) ?? ""; |
src/web/pages/account.ts +25 −24
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * has been read once. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | import { UPSTREAM_REPO } from "../../core/upstream.ts"; |
| 13 | 14 | import { emptyNote } from "../empty_words.ts"; |
| 14 | 15 | import { resendVerification } from "../../actions/verify.ts"; |
| @@ -255,7 +256,7 @@ function dotfilesView(ctx: Ctx, error?: string): Html { | ||
| 255 | 256 | |
| 256 | 257 | // POST /settings/dotfiles |
| 257 | 258 | export async function dotfilesUpdate(ctx: Ctx): Promise<Response> { |
| 258 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 259 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 259 | 260 | const form = await readForm(ctx, "admin"); |
| 260 | 261 | if (form instanceof Response) return form; |
| 261 | 262 | const saved = setDotfilesRepo(ctx.app.db, ctx.auth.user, field(form, "repo")); |
| @@ -315,7 +316,7 @@ function parentLinkView(ctx: Ctx): Html { | ||
| 315 | 316 | |
| 316 | 317 | // POST /settings/parent/unlink |
| 317 | 318 | export async function parentUnlink(ctx: Ctx): Promise<Response> { |
| 318 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 319 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 319 | 320 | const form = await readForm(ctx, "admin"); |
| 320 | 321 | if (form instanceof Response) return form; |
| 321 | 322 | const issuer = parentIssuerOf(ctx.app.config); |
| @@ -328,7 +329,7 @@ export async function parentUnlink(ctx: Ctx): Promise<Response> { | ||
| 328 | 329 | |
| 329 | 330 | // POST /settings/edge/link |
| 330 | 331 | export async function edgeLink(ctx: Ctx): Promise<Response> { |
| 331 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 332 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 332 | 333 | const form = await readForm(ctx, "admin"); |
| 333 | 334 | if (form instanceof Response) return form; |
| 334 | 335 | const login = edgeIdentity(ctx.request, activeEdgeToken(ctx.app)); |
| @@ -352,7 +353,7 @@ export async function edgeLink(ctx: Ctx): Promise<Response> { | ||
| 352 | 353 | |
| 353 | 354 | // POST /settings/edge/unlink |
| 354 | 355 | export async function edgeUnlink(ctx: Ctx): Promise<Response> { |
| 355 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 356 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 356 | 357 | const form = await readForm(ctx, "admin"); |
| 357 | 358 | if (form instanceof Response) return form; |
| 358 | 359 | if (unlinkEdgeLogin(ctx.app.db, ctx.auth.user.id)) |
| @@ -383,7 +384,7 @@ function unverifiedNotice(ctx: Ctx): Html { | ||
| 383 | 384 | |
| 384 | 385 | // POST /settings/email/verify |
| 385 | 386 | export async function resendVerifyLink(ctx: Ctx): Promise<Response> { |
| 386 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 387 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 387 | 388 | const form = await readForm(ctx); |
| 388 | 389 | if (form instanceof Response) return form; |
| 389 | 390 | const sent = await resendVerification(ctx.app, ctx.auth.user); |
| @@ -595,7 +596,7 @@ export function appearancePage(ctx: Ctx): Response { | ||
| 595 | 596 | |
| 596 | 597 | // GET /settings/shells |
| 597 | 598 | export function shellsPage(ctx: Ctx): Response { |
| 598 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 599 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 599 | 600 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 600 | 601 | const body = html`${dotfilesView(ctx)}${shellsView(ctx, ctx.auth.user)}`; |
| 601 | 602 | return timePhase(ctx.request, "render", () => accountShell(ctx, "shells", "Shells", body)); |
| @@ -603,7 +604,7 @@ export function shellsPage(ctx: Ctx): Response { | ||
| 603 | 604 | |
| 604 | 605 | // POST /settings/shells/:id/stop |
| 605 | 606 | export async function shellStop(ctx: Ctx): Promise<Response> { |
| 606 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 607 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 607 | 608 | const form = await readForm(ctx, "admin"); |
| 608 | 609 | if (form instanceof Response) return form; |
| 609 | 610 | const id = ctx.params.id ?? ""; |
| @@ -613,7 +614,7 @@ export async function shellStop(ctx: Ctx): Promise<Response> { | ||
| 613 | 614 | |
| 614 | 615 | // POST /settings/shells/stop-idle |
| 615 | 616 | export async function shellsStopIdle(ctx: Ctx): Promise<Response> { |
| 616 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 617 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 617 | 618 | const form = await readForm(ctx, "admin"); |
| 618 | 619 | if (form instanceof Response) return form; |
| 619 | 620 | return flashTo(ctx, "/settings/shells", { message: stoppedIdleSays(stopIdleShells(ctx.app, ctx.auth.user.id)) }); |
| @@ -632,7 +633,7 @@ function hostedBackupRow(dataDir: string): Html | null { | ||
| 632 | 633 | |
| 633 | 634 | // GET /settings |
| 634 | 635 | export function accountPage(ctx: Ctx): Response { |
| 635 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 636 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 636 | 637 | const user = ctx.auth.user; |
| 637 | 638 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 638 | 639 | // Read in the order the page lays them out; each phase is named for what it reads. |
| @@ -664,7 +665,7 @@ export function accountPage(ctx: Ctx): Response { | ||
| 664 | 665 | |
| 665 | 666 | // POST /settings/notify |
| 666 | 667 | export async function notifyUpdate(ctx: Ctx): Promise<Response> { |
| 667 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 668 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 668 | 669 | const form = await readForm(ctx, "admin"); |
| 669 | 670 | if (form instanceof Response) return form; |
| 670 | 671 | const saved = setNotifyUrl(ctx.app.db, ctx.auth.user.id, field(form, "url")); |
| @@ -689,7 +690,7 @@ export async function notifyUpdate(ctx: Ctx): Promise<Response> { | ||
| 689 | 690 | |
| 690 | 691 | // POST /settings/focus |
| 691 | 692 | export async function focusUpdate(ctx: Ctx): Promise<Response> { |
| 692 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 693 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 693 | 694 | if (ctx.auth.user.kind !== "user") return forbiddenPage(ctx, "A focus is a person's, not an agent's."); |
| 694 | 695 | const form = await readForm(ctx, "admin"); |
| 695 | 696 | if (form instanceof Response) return form; |
| @@ -704,7 +705,7 @@ export async function focusUpdate(ctx: Ctx): Promise<Response> { | ||
| 704 | 705 | |
| 705 | 706 | // POST /settings |
| 706 | 707 | export async function accountUpdate(ctx: Ctx): Promise<Response> { |
| 707 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 708 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 708 | 709 | const form = await readForm(ctx, "admin"); |
| 709 | 710 | if (form instanceof Response) return form; |
| 710 | 711 | const displayName = field(form, "displayName").trim(); |
| @@ -785,7 +786,7 @@ function passwordView(error?: { | ||
| 785 | 786 | |
| 786 | 787 | // GET /settings/password |
| 787 | 788 | export function passwordPage(ctx: Ctx): Response { |
| 788 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 789 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 789 | 790 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 790 | 791 | const standing = closeStanding(ctx.app.db, ctx.auth.user.id); |
| 791 | 792 | const body = html`${passwordView()}${closeView(ctx, standing)}`; |
| @@ -795,7 +796,7 @@ export function passwordPage(ctx: Ctx): Response { | ||
| 795 | 796 | |
| 796 | 797 | // POST /settings/password |
| 797 | 798 | export async function passwordUpdate(ctx: Ctx): Promise<Response> { |
| 798 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 799 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 799 | 800 | const form = await readForm(ctx, "admin"); |
| 800 | 801 | if (form instanceof Response) return form; |
| 801 | 802 | const current = field(form, "current"); |
| @@ -978,7 +979,7 @@ function tokensView(ctx: Ctx): Html { | ||
| 978 | 979 | |
| 979 | 980 | // GET /settings/tokens |
| 980 | 981 | export function tokensPage(ctx: Ctx): Response { |
| 981 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 982 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 982 | 983 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 983 | 984 | const body = tokensView(ctx); |
| 984 | 985 | return timePhase(ctx.request, "render", () => accountShell(ctx, "tokens", "Access codes", body)); |
| @@ -986,7 +987,7 @@ export function tokensPage(ctx: Ctx): Response { | ||
| 986 | 987 | |
| 987 | 988 | // POST /settings/tokens |
| 988 | 989 | export async function tokenCreate(ctx: Ctx): Promise<Response> { |
| 989 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 990 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 990 | 991 | // Minting a token must come from the account itself — a browser session, |
| 991 | 992 | // the platform edge's sign-in, or the password — never from another token |
| 992 | 993 | // (no privilege bootstrapping). readForm below refuses a cross-site post. |
| @@ -1023,7 +1024,7 @@ export async function tokenCreate(ctx: Ctx): Promise<Response> { | ||
| 1023 | 1024 | |
| 1024 | 1025 | // POST /settings/tokens/:id/delete |
| 1025 | 1026 | export async function tokenDelete(ctx: Ctx): Promise<Response> { |
| 1026 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1027 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1027 | 1028 | const form = await readForm(ctx, "admin"); |
| 1028 | 1029 | if (form instanceof Response) return form; |
| 1029 | 1030 | const revoked = deleteToken(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| @@ -1036,7 +1037,7 @@ export async function tokenDelete(ctx: Ctx): Promise<Response> { | ||
| 1036 | 1037 | |
| 1037 | 1038 | // POST /settings/sessions/:id/delete |
| 1038 | 1039 | export async function sessionDelete(ctx: Ctx): Promise<Response> { |
| 1039 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1040 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1040 | 1041 | const form = await readForm(ctx, "admin"); |
| 1041 | 1042 | if (form instanceof Response) return form; |
| 1042 | 1043 | const user = ctx.auth.user; |
| @@ -1055,7 +1056,7 @@ export async function sessionDelete(ctx: Ctx): Promise<Response> { | ||
| 1055 | 1056 | |
| 1056 | 1057 | // POST /settings/sessions/end-others |
| 1057 | 1058 | export async function sessionsOthersDelete(ctx: Ctx): Promise<Response> { |
| 1058 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1059 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1059 | 1060 | const form = await readForm(ctx, "admin"); |
| 1060 | 1061 | if (form instanceof Response) return form; |
| 1061 | 1062 | const done = signOutElsewhere(ctx.app, ctx.auth.user, cookieValue(ctx.request, "forge_session")); |
| @@ -1141,7 +1142,7 @@ function keysOff(ctx: Ctx): Response { | ||
| 1141 | 1142 | |
| 1142 | 1143 | // GET /settings/keys |
| 1143 | 1144 | export function keysPage(ctx: Ctx): Response { |
| 1144 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1145 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1145 | 1146 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1146 | 1147 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 1147 | 1148 | const body = keysView(ctx, { name: "", key: "" }); |
| @@ -1150,7 +1151,7 @@ export function keysPage(ctx: Ctx): Response { | ||
| 1150 | 1151 | |
| 1151 | 1152 | // POST /settings/keys |
| 1152 | 1153 | export async function keyCreate(ctx: Ctx): Promise<Response> { |
| 1153 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1154 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1154 | 1155 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1155 | 1156 | // A key outlives the token and opens the terminal, so an rw token is |
| 1156 | 1157 | // refused here as over the API and MCP (#14762); a session is admin. |
| @@ -1183,7 +1184,7 @@ export async function keyCreate(ctx: Ctx): Promise<Response> { | ||
| 1183 | 1184 | |
| 1184 | 1185 | // POST /settings/keys/:id/delete |
| 1185 | 1186 | export async function keyDelete(ctx: Ctx): Promise<Response> { |
| 1186 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1187 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1187 | 1188 | if (!sshOn(ctx.app.db)) return keysOff(ctx); |
| 1188 | 1189 | // A key outlives the token and opens the terminal, so an rw token is |
| 1189 | 1190 | // refused here as over the API and MCP (#14762); a session is admin. |
| @@ -1277,7 +1278,7 @@ function closeRefused(ctx: Ctx, said: CloseSaid): Response { | ||
| 1277 | 1278 | |
| 1278 | 1279 | // POST /settings/account/close |
| 1279 | 1280 | export async function accountClose(ctx: Ctx): Promise<Response> { |
| 1280 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1281 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1281 | 1282 | if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF); |
| 1282 | 1283 | const user = ctx.auth.user; |
| 1283 | 1284 | const form = await readForm(ctx, "admin"); |
| @@ -1303,7 +1304,7 @@ const CLOSE_ITSELF = "Closing an account, or keeping it, is asked from the accou | ||
| 1303 | 1304 | |
| 1304 | 1305 | // POST /settings/account/keep |
| 1305 | 1306 | export async function accountKeep(ctx: Ctx): Promise<Response> { |
| 1306 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1307 | if (!signedInPage(ctx, "account")) return signInFirst(ctx); | |
| 1307 | 1308 | if (!isAccountItself(ctx.app.db, ctx.auth)) return forbiddenPage(ctx, CLOSE_ITSELF); |
| 1308 | 1309 | const form = await readForm(ctx, "admin"); |
| 1309 | 1310 | if (form instanceof Response) return form; |
src/web/pages/accounts.ts +16 −15
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * only; anyone else gets the forge's one 404. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { sshOn } from "../../settings/ssh.ts"; |
| 9 | 10 | import { emptyNote } from "../empty_words.ts"; |
| 10 | 11 | import { |
| @@ -140,8 +141,8 @@ function wayBackForms(ctx: Ctx): Html | null { | ||
| 140 | 141 | |
| 141 | 142 | // POST /settings/accounts/:username/way-back — the link, shown once on the page. |
| 142 | 143 | export async function wayBackAct(ctx: Ctx): Promise<Response> { |
| 143 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 144 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 144 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 145 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 145 | 146 | const form = await readForm(ctx, "admin"); |
| 146 | 147 | if (form instanceof Response) return form; |
| 147 | 148 | const username = ctx.params.username ?? ""; |
| @@ -178,7 +179,7 @@ export function accountsPage(ctx: Ctx): Response { | ||
| 178 | 179 | |
| 179 | 180 | /** The page, with what an act needs said first (`notice`) when it did not finish. */ |
| 180 | 181 | function accountsView(ctx: Ctx, notice?: Html, status = 200): Response { |
| 181 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 182 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 182 | 183 | const user = ctx.auth.user; |
| 183 | 184 | const listed = timePhase(ctx.request, "accounts", () => |
| 184 | 185 | listAccounts(ctx.app, user), |
| @@ -339,8 +340,8 @@ function isOtherAdmin(ctx: Ctx, username: string): boolean { | ||
| 339 | 340 | |
| 340 | 341 | // GET /settings/accounts/:username — one person, on one screen, with what an admin may do |
| 341 | 342 | export function personSignInsPage(ctx: Ctx): Response { |
| 342 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 343 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 343 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 344 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 344 | 345 | const username = ctx.params.username ?? ""; |
| 345 | 346 | const named = getUserByName(ctx.app.db, username); |
| 346 | 347 | // An organization has no sign-ins: its page is its model grant and spend ceilings. |
| @@ -440,8 +441,8 @@ export function personSignInsPage(ctx: Ctx): Response { | ||
| 440 | 441 | // POST /settings/accounts/:username/(reset|end-sessions) |
| 441 | 442 | export function accessAct(act: "reset" | "end-sessions") { |
| 442 | 443 | return async (ctx: Ctx): Promise<Response> => { |
| 443 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 444 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 444 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 445 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 445 | 446 | const form = await readForm(ctx, "admin"); |
| 446 | 447 | if (form instanceof Response) return form; |
| 447 | 448 | const username = ctx.params.username ?? ""; |
| @@ -467,8 +468,8 @@ export function accessAct(act: "reset" | "end-sessions") { | ||
| 467 | 468 | // POST /settings/accounts/:username/(tokens|sessions)/:id/delete |
| 468 | 469 | export function signInAct(what: "token" | "session") { |
| 469 | 470 | return async (ctx: Ctx): Promise<Response> => { |
| 470 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 471 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 471 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 472 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 472 | 473 | const form = await readForm(ctx, "admin"); |
| 473 | 474 | if (form instanceof Response) return form; |
| 474 | 475 | const username = ctx.params.username ?? ""; |
| @@ -502,8 +503,8 @@ const DONE: Readonly<Record<Act, string>> = { | ||
| 502 | 503 | // POST /settings/accounts/:username/(suspend|unsuspend|remove) |
| 503 | 504 | export function accountAct(act: Act) { |
| 504 | 505 | return async (ctx: Ctx): Promise<Response> => { |
| 505 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 506 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 506 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 507 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 507 | 508 | const form = await readForm(ctx, "admin"); |
| 508 | 509 | if (form instanceof Response) return form; |
| 509 | 510 | const username = ctx.params.username ?? ""; |
| @@ -547,8 +548,8 @@ export function accountAct(act: Act) { | ||
| 547 | 548 | |
| 548 | 549 | // GET /settings/accounts/:username/retire — everything removal would take; removes nothing |
| 549 | 550 | export function retirePage(ctx: Ctx): Response { |
| 550 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 551 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 551 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 552 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 552 | 553 | const username = ctx.params.username ?? ""; |
| 553 | 554 | const plan = retirementPlan(ctx.app, ctx.auth.user, username); |
| 554 | 555 | if (!plan.ok) |
| @@ -605,8 +606,8 @@ export function retirePage(ctx: Ctx): Response { | ||
| 605 | 606 | |
| 606 | 607 | // POST /settings/accounts/:username/retire |
| 607 | 608 | export async function retireAct(ctx: Ctx): Promise<Response> { |
| 608 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 609 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 609 | if (!signedInPage(ctx, "accounts")) return signInFirst(ctx); | |
| 610 | if (!adminPage(ctx, "accounts", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 610 | 611 | const form = await readForm(ctx, "admin"); |
| 611 | 612 | if (form instanceof Response) return form; |
| 612 | 613 | const username = ctx.params.username ?? ""; |
src/web/pages/admin-limits.ts +8 −7
| @@ -29,6 +29,7 @@ import { btn, confirmAction, icon, row, time } from "../ui.ts"; | ||
| 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 | 33 | |
| 33 | 34 | // GET /admin/limits |
| 34 | 35 | export function limitsPage(ctx: Ctx): Response { |
| @@ -257,7 +258,7 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 257 | 258 | // POST /admin/limits |
| 258 | 259 | export async function limitsSet(ctx: Ctx): Promise<Response> { |
| 259 | 260 | // Checked before the body is read: a non-admin learns nothing of the door. |
| 260 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") | |
| 261 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 261 | 262 | return notFoundPage(ctx); |
| 262 | 263 | const form = await readForm(ctx, "admin"); |
| 263 | 264 | if (form instanceof Response) return form; |
| @@ -293,7 +294,7 @@ export async function limitsSet(ctx: Ctx): Promise<Response> { | ||
| 293 | 294 | |
| 294 | 295 | // POST /admin/quotas |
| 295 | 296 | export async function quotasSet(ctx: Ctx): Promise<Response> { |
| 296 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") | |
| 297 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 297 | 298 | return notFoundPage(ctx); |
| 298 | 299 | const form = await readForm(ctx, "admin"); |
| 299 | 300 | if (form instanceof Response) return form; |
| @@ -314,7 +315,7 @@ export async function quotasSet(ctx: Ctx): Promise<Response> { | ||
| 314 | 315 | |
| 315 | 316 | // POST /admin/signup |
| 316 | 317 | export async function signupSet(ctx: Ctx): Promise<Response> { |
| 317 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") | |
| 318 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 318 | 319 | return notFoundPage(ctx); |
| 319 | 320 | const form = await readForm(ctx, "admin"); |
| 320 | 321 | if (form instanceof Response) return form; |
| @@ -331,7 +332,7 @@ export async function signupSet(ctx: Ctx): Promise<Response> { | ||
| 331 | 332 | |
| 332 | 333 | // POST /admin/agent-start |
| 333 | 334 | export async function agentStartSet(ctx: Ctx): Promise<Response> { |
| 334 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 335 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 335 | 336 | const form = await readForm(ctx, "admin"); |
| 336 | 337 | if (form instanceof Response) return form; |
| 337 | 338 | const changed = changeAgentStart(ctx.app, ctx.auth.user, field(form, "agent_start")); |
| @@ -347,7 +348,7 @@ export async function agentStartSet(ctx: Ctx): Promise<Response> { | ||
| 347 | 348 | |
| 348 | 349 | // POST /admin/billing-links |
| 349 | 350 | export async function billingLinksSet(ctx: Ctx): Promise<Response> { |
| 350 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 351 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 351 | 352 | const form = await readForm(ctx, "admin"); |
| 352 | 353 | if (form instanceof Response) return form; |
| 353 | 354 | const changed = changeBillingLinks( |
| @@ -367,7 +368,7 @@ export async function billingLinksSet(ctx: Ctx): Promise<Response> { | ||
| 367 | 368 | |
| 368 | 369 | // POST /admin/invites |
| 369 | 370 | export async function inviteMint(ctx: Ctx): Promise<Response> { |
| 370 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") | |
| 371 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 371 | 372 | return notFoundPage(ctx); |
| 372 | 373 | const form = await readForm(ctx, "admin"); |
| 373 | 374 | if (form instanceof Response) return form; |
| @@ -389,7 +390,7 @@ export async function inviteMint(ctx: Ctx): Promise<Response> { | ||
| 389 | 390 | |
| 390 | 391 | // POST /admin/invites/:id/revoke |
| 391 | 392 | export async function inviteRevoke(ctx: Ctx): Promise<Response> { |
| 392 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") | |
| 393 | if (ctx.auth.user === undefined || !adminPage(ctx, "admin-limits", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) | |
| 393 | 394 | return notFoundPage(ctx); |
| 394 | 395 | const form = await readForm(ctx, "admin"); |
| 395 | 396 | if (form instanceof Response) return form; |
src/web/pages/advisories.ts +2 −1
| @@ -14,9 +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 | 18 | |
| 18 | 19 | const gate = (ctx: Ctx): Response | undefined => |
| 19 | !ctx.auth.user ? signInFirst(ctx) : ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx); | |
| 20 | !ctx.auth.user ? signInFirst(ctx) : adminPage(ctx, "advisories", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx); | |
| 20 | 21 | |
| 21 | 22 | const line = (a: Seen) => |
| 22 | 23 | row({ |
src/web/pages/app_templates.ts +2 −1
| @@ -15,11 +15,12 @@ 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 | 19 | |
| 19 | 20 | function denied(ctx: Ctx): Response | undefined { |
| 20 | 21 | const user = ctx.auth.user; |
| 21 | 22 | if (!user) return signInFirst(ctx); |
| 22 | if (user.isAdmin && user.kind === "user") return undefined; | |
| 23 | if (adminPage(ctx, "app_templates", user.isAdmin && user.kind === "user")) return undefined; | |
| 23 | 24 | return page( |
| 24 | 25 | { |
| 25 | 26 | ctx, |
src/web/pages/app_variants.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * values, retire it, make it main (docs/features/variants.md). |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { |
| 9 | 10 | makeMain, |
| 10 | 11 | registerVariant, |
| @@ -98,7 +99,7 @@ type Verb = (ctx: Ctx, repo: NonNullable<ReturnType<typeof loadRepo>>, form: For | ||
| 98 | 99 | async function mutate(ctx: Ctx, verb: Verb): Promise<Response> { |
| 99 | 100 | const repo = loadRepo(ctx); |
| 100 | 101 | if (!repo) return notFoundPage(ctx); |
| 101 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 102 | if (!signedInPage(ctx, "app_variants")) return signInFirst(ctx); | |
| 102 | 103 | const form = await readForm(ctx, "rw"); |
| 103 | 104 | if (form instanceof Response) return form; |
| 104 | 105 | return verb(ctx, repo, form); |
src/web/pages/apps.ts +5 −4
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | * 404 for everyone. |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | import { signedInPage } from "../../http/page_may.ts"; | |
| 15 | 16 | import { appsStanding } from "../studio/standing.ts"; |
| 16 | 17 | import { keyOf } from "../keymap.ts"; |
| 17 | 18 | import { stepsOf } from "../../core/review_steps.ts"; |
| @@ -437,7 +438,7 @@ function newAppForm( | ||
| 437 | 438 | |
| 438 | 439 | // GET /apps/new |
| 439 | 440 | export async function newAppPage(ctx: Ctx): Promise<Response> { |
| 440 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 441 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 441 | 442 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 442 | 443 | const picks = plannerOffered(ctx); |
| 443 | 444 | const offered = await timePhaseAsync(ctx.request, "templates", () => templateChoices(ctx.app, ctx.auth.user)); |
| @@ -461,7 +462,7 @@ export async function newAppPage(ctx: Ctx): Promise<Response> { | ||
| 461 | 462 | |
| 462 | 463 | // POST /apps/new |
| 463 | 464 | export async function newAppSubmit(ctx: Ctx): Promise<Response> { |
| 464 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 465 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 465 | 466 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 466 | 467 | const form = await readForm(ctx, "rw"); |
| 467 | 468 | if (form instanceof Response) return form; |
| @@ -813,7 +814,7 @@ function appsOpenResponse(ctx: Ctx): Response { | ||
| 813 | 814 | // up: a private app and a name nobody holds answer alike (#13678). |
| 814 | 815 | const target = resolveAppHostname(ctx.app, runtime.options.domain, host); |
| 815 | 816 | if (target === undefined) return notFoundPage(ctx); |
| 816 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 817 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 817 | 818 | if (target === "unknown") return notFoundPage(ctx); |
| 818 | 819 | const repo = getRepoById(ctx.app.db, target.app.repoId); |
| 819 | 820 | if (!repo) return notFoundPage(ctx); |
| @@ -864,7 +865,7 @@ async function envForm( | ||
| 864 | 865 | ): Promise<{ repo: Repo; env: string; user: User } | Response> { |
| 865 | 866 | const repo = loadRepo(ctx); |
| 866 | 867 | if (!repo) return notFoundPage(ctx); |
| 867 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 868 | if (!signedInPage(ctx, "apps")) return signInFirst(ctx); | |
| 868 | 869 | const form = await readForm(ctx, "rw"); |
| 869 | 870 | if (form instanceof Response) return form; |
| 870 | 871 | return { repo, env: ctx.params.env ?? "", user: ctx.auth.user }; |
src/web/pages/audit.ts +2 −1
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | * which are as public as the file in the repository. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | import { signedInPage } from "../../http/page_may.ts"; | |
| 16 | 17 | import { appsRuntime } from "../../apps/runtime_registry.ts"; |
| 17 | 18 | import { appsForRepos, getAppByRepo } from "../../core/apps.ts"; |
| 18 | 19 | import { canWrite, listReposVisibleTo, type Repo } from "../../core/repos.ts"; |
| @@ -384,7 +385,7 @@ export async function auditCsv(ctx: Ctx): Promise<Response> { | ||
| 384 | 385 | export async function auditProbeSubmit(ctx: Ctx): Promise<Response> { |
| 385 | 386 | const repo = loadRepo(ctx); |
| 386 | 387 | if (!repo) return notFoundPage(ctx); |
| 387 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 388 | if (!signedInPage(ctx, "audit")) return signInFirst(ctx); | |
| 388 | 389 | const form = await readForm(ctx, "rw"); |
| 389 | 390 | if (form instanceof Response) return form; |
| 390 | 391 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) |
src/web/pages/backups.ts +6 −5
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | * was /settings/resilience, which now sends here. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 16 | 17 | import { sshOn } from "../../settings/ssh.ts"; |
| 17 | 18 | import { |
| 18 | 19 | forgetDestination, |
| @@ -56,8 +57,8 @@ import { badge, btn, fileSize, icon, row, time } from "../ui.ts"; | ||
| 56 | 57 | import { accountSections } from "./origins.ts"; |
| 57 | 58 | |
| 58 | 59 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 59 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 60 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 60 | if (!signedInPage(ctx, "backups")) return signInFirst(ctx); | |
| 61 | if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 61 | 62 | return undefined; |
| 62 | 63 | } |
| 63 | 64 | |
| @@ -290,7 +291,7 @@ export async function backupsPage(ctx: Ctx): Promise<Response> { | ||
| 290 | 291 | |
| 291 | 292 | /** GET /settings/backups/live — the moving part alone, which the page refetches on an event. */ |
| 292 | 293 | export async function backupsLive(ctx: Ctx): Promise<Response> { |
| 293 | if (!ctx.auth.user?.isAdmin) return fragment(html``, { status: 404 }); | |
| 294 | if (!adminPage(ctx, "backups", ctx.auth.user?.isAdmin === true)) return fragment(html``, { status: 404 }); | |
| 294 | 295 | const svc = snapshotsOf(ctx.app); |
| 295 | 296 | if (svc === undefined || svc.store === undefined) return fragment(html``, { status: 404 }); |
| 296 | 297 | return fragment(await movingPart(ctx, svc, svc.store), { request: ctx.request }); |
| @@ -656,8 +657,8 @@ export function lanesCard(ctx: Ctx): Html | "" { | ||
| 656 | 657 | |
| 657 | 658 | /** POST /settings/backups/drill — restore the newest snapshot, keep what came of it. */ |
| 658 | 659 | export async function backupsDrill(ctx: Ctx): Promise<Response> { |
| 659 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 660 | if (!ctx.auth.user.isAdmin) | |
| 660 | if (!signedInPage(ctx, "backups")) return signInFirst(ctx); | |
| 661 | if (!adminPage(ctx, "backups", ctx.auth.user.isAdmin)) | |
| 661 | 662 | return new Response("Forbidden", { |
| 662 | 663 | status: 403, |
| 663 | 664 | headers: { "content-type": "text/plain; charset=utf-8" }, |
src/web/pages/billing.ts +13 −12
| @@ -5,6 +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 | 9 | import { sshOn } from "../../settings/ssh.ts"; |
| 9 | 10 | import { emptyNote } from "../empty_words.ts"; |
| 10 | 11 | import { ledBlock } from "./visitors.ts"; |
| @@ -160,7 +161,7 @@ function portalSection(ctx: Ctx, r: Refused | undefined): Html | null { | ||
| 160 | 161 | |
| 161 | 162 | // POST /settings/billing/portal |
| 162 | 163 | export async function billingSetPortal(ctx: Ctx): Promise<Response> { |
| 163 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 164 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 164 | 165 | const form = await readForm(ctx, "admin"); |
| 165 | 166 | if (form instanceof Response) return form; |
| 166 | 167 | const value = field(form, "portal_url"); |
| @@ -172,7 +173,7 @@ export async function billingSetPortal(ctx: Ctx): Promise<Response> { | ||
| 172 | 173 | |
| 173 | 174 | // POST /settings/billing/links |
| 174 | 175 | export async function billingSetLinks(ctx: Ctx): Promise<Response> { |
| 175 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 176 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 176 | 177 | const form = await readForm(ctx, "admin"); |
| 177 | 178 | if (form instanceof Response) return form; |
| 178 | 179 | const current = readBillingLinks(ctx.app, ctx.auth.user); |
| @@ -215,7 +216,7 @@ function lapseWords(l: Lapse): string { | ||
| 215 | 216 | // GET /settings/billing |
| 216 | 217 | export function billingPage(ctx: Ctx): Response { |
| 217 | 218 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 218 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 219 | if (!signedInPage(ctx, "billing")) return signInFirst(ctx); | |
| 219 | 220 | return billingView(ctx); |
| 220 | 221 | } |
| 221 | 222 | |
| @@ -312,7 +313,7 @@ function billingView(ctx: Ctx, shown?: Shown, status = 200, refusal?: Refused): | ||
| 312 | 313 | |
| 313 | 314 | // POST /settings/billing/codes |
| 314 | 315 | export async function billingMakeCode(ctx: Ctx): Promise<Response> { |
| 315 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 316 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 316 | 317 | const form = await readForm(ctx, "admin"); |
| 317 | 318 | if (form instanceof Response) return form; |
| 318 | 319 | const values = { kind: field(form, "kind"), plan: field(form, "plan"), uses: field(form, "uses"), note: field(form, "note"), expires: field(form, "expires") }; |
| @@ -323,7 +324,7 @@ export async function billingMakeCode(ctx: Ctx): Promise<Response> { | ||
| 323 | 324 | |
| 324 | 325 | // POST /settings/billing/codes/revoke |
| 325 | 326 | export async function billingRevokeCode(ctx: Ctx): Promise<Response> { |
| 326 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 327 | if (!adminPage(ctx, "billing", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 327 | 328 | const form = await readForm(ctx, "admin"); |
| 328 | 329 | if (form instanceof Response) return form; |
| 329 | 330 | const done = revoke(ctx.app, ctx.auth.user, field(form, "id")); |
| @@ -361,14 +362,14 @@ function changeView(ctx: Ctx, forge: string, plan: string, refused = false): Res | ||
| 361 | 362 | |
| 362 | 363 | // GET /settings/billing/change?forge=&plan= — the preview, before the confirm. |
| 363 | 364 | export function billingChange(ctx: Ctx): Response { |
| 364 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 365 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 365 | if (!signedInPage(ctx, "billing")) return signInFirst(ctx); | |
| 366 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 366 | 367 | return changeView(ctx, ctx.url.searchParams.get("forge") ?? "", ctx.url.searchParams.get("plan") ?? ""); |
| 367 | 368 | } |
| 368 | 369 | |
| 369 | 370 | // POST /settings/billing/grant — the confirm: it must carry what the preview showed. |
| 370 | 371 | export async function billingGrant(ctx: Ctx): Promise<Response> { |
| 371 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 372 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 372 | 373 | const form = await readForm(ctx, "admin"); |
| 373 | 374 | if (form instanceof Response) return form; |
| 374 | 375 | const forge = field(form, "forge"); |
| @@ -388,7 +389,7 @@ const back = (ctx: Ctx, r: { ok: true; message: string } | { ok: false; error: B | ||
| 388 | 389 | |
| 389 | 390 | // POST /settings/billing/stripe/connect |
| 390 | 391 | export async function stripeConnect(ctx: Ctx): Promise<Response> { |
| 391 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 392 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 392 | 393 | const form = await readForm(ctx, "admin"); |
| 393 | 394 | if (form instanceof Response) return form; |
| 394 | 395 | const r = await connectStripe(ctx.app, ctx.auth.user, field(form, "key"), field(form, "secret")); |
| @@ -397,7 +398,7 @@ export async function stripeConnect(ctx: Ctx): Promise<Response> { | ||
| 397 | 398 | |
| 398 | 399 | // POST /settings/billing/stripe/secret |
| 399 | 400 | export async function stripeSecret(ctx: Ctx): Promise<Response> { |
| 400 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 401 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 401 | 402 | const form = await readForm(ctx, "admin"); |
| 402 | 403 | if (form instanceof Response) return form; |
| 403 | 404 | const r = saveSigningSecret(ctx.app, ctx.auth.user, field(form, "secret")); |
| @@ -406,7 +407,7 @@ export async function stripeSecret(ctx: Ctx): Promise<Response> { | ||
| 406 | 407 | |
| 407 | 408 | // POST /settings/billing/stripe/disconnect |
| 408 | 409 | export async function stripeDisconnect(ctx: Ctx): Promise<Response> { |
| 409 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 410 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 410 | 411 | const form = await readForm(ctx, "admin"); |
| 411 | 412 | if (form instanceof Response) return form; |
| 412 | 413 | const r = await disconnectStripe(ctx.app, ctx.auth.user); |
| @@ -416,7 +417,7 @@ export async function stripeDisconnect(ctx: Ctx): Promise<Response> { | ||
| 416 | 417 | // POST /settings/billing/orders/retry — an admin who is a person retries a paid order whose forge |
| 417 | 418 | // was not made. |
| 418 | 419 | export async function orderRetry(ctx: Ctx): Promise<Response> { |
| 419 | if (!isPerson(ctx)) return notFoundPage(ctx); | |
| 420 | if (!adminPage(ctx, "billing", isPerson(ctx))) return notFoundPage(ctx); | |
| 420 | 421 | const form = await readForm(ctx, "admin"); |
| 421 | 422 | if (form instanceof Response) return form; |
| 422 | 423 | const r = await retryOrder(ctx.app, ctx.auth.user, field(form, "id")); |
src/web/pages/boards-index-stream.ts +2 −1
| @@ -15,6 +15,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 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 | 19 | |
| 19 | 20 | /** A burst of events is read once, this long after the first. */ |
| 20 | 21 | export const SETTLE_MS = 100; |
| @@ -28,7 +29,7 @@ export function readNumbers(app: App, now = Date.now()): Numbers { | ||
| 28 | 29 | |
| 29 | 30 | export function boardsIndexStream(ctx: Ctx): Response { |
| 30 | 31 | const u = ctx.auth.user; |
| 31 | if (u?.isAdmin !== true || u.kind === "agent") return notFoundPage(ctx); | |
| 32 | if (!adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent")) return notFoundPage(ctx); | |
| 32 | 33 | const { app } = ctx; |
| 33 | 34 | return eventStream(app, ctx.request, (emit, _close, ready) => { |
| 34 | 35 | let sent = readNumbers(app); |
src/web/pages/boards-stream.ts +2 −1
| @@ -12,11 +12,12 @@ 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 | 16 | |
| 16 | 17 | export async function boardStream(ctx: Ctx): Promise<Response> { |
| 17 | 18 | const u = ctx.auth.user; |
| 18 | 19 | const slug = ctx.params.slug ?? ""; |
| 19 | if (u?.isAdmin !== true || u.kind === "agent" || !isSlug(slug)) return notFoundPage(ctx); | |
| 20 | if (u === undefined || !adminPage(ctx, "boards-stream", u.isAdmin && u.kind !== "agent") || !isSlug(slug)) return notFoundPage(ctx); | |
| 20 | 21 | const view = readView(ctx.url.searchParams); |
| 21 | 22 | const picture = await boardPicture(ctx.app, slug, undefined, undefined, undefined, view.range ?? undefined); |
| 22 | 23 | if (picture === undefined || isFailed(picture) || picture.board === null) return notFoundPage(ctx); |
src/web/pages/boards-view.ts +2 −1
| @@ -38,6 +38,7 @@ import { boardMarks } from "../../boards/marks.ts"; | ||
| 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 | 42 | |
| 42 | 43 | const sizes = (max: number, word: string, now: number) => |
| 43 | 44 | [1, 2, 3].slice(0, max).map((n) => ({ value: String(n), label: `${String(n)} ${word}`, selected: n === now })); |
| @@ -91,7 +92,7 @@ function grid(app: App, slug: string, board: Board, panels: readonly PanelDrawn[ | ||
| 91 | 92 | |
| 92 | 93 | const denied = (ctx: Ctx) => { |
| 93 | 94 | const u = ctx.auth.user; |
| 94 | return u?.isAdmin !== true || u.kind === "agent"; | |
| 95 | return !adminPage(ctx, "boards", u?.isAdmin === true && u.kind !== "agent"); | |
| 95 | 96 | }; |
| 96 | 97 | |
| 97 | 98 | /** |
src/web/pages/boards.ts +3 −2
| @@ -24,6 +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 | 28 | |
| 28 | 29 | const AGGREGATES = ["count", "sum", "avg", "max"] as const; |
| 29 | 30 | const OPS = ["eq", "ne", "lt", "lte", "gt", "gte", "starts"] as const; |
| @@ -106,7 +107,7 @@ export function paramsOf(q: Record<string, unknown>, chart: Chart = "line"): Par | ||
| 106 | 107 | // GET /boards/data: a `?ask=` sentence is read by the rules only, so no link can spend the model. |
| 107 | 108 | export async function boardsPage(ctx: Ctx): Promise<Response> { |
| 108 | 109 | const user = ctx.auth.user; |
| 109 | if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx); | |
| 110 | if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 110 | 111 | return explorer(ctx, user, ctx.url.searchParams.get("ask"), false); |
| 111 | 112 | } |
| 112 | 113 | |
| @@ -114,7 +115,7 @@ export async function boardsPage(ctx: Ctx): Promise<Response> { | ||
| 114 | 115 | // asker's budget; `readForm` refuses a form another site sent (`crossOrigin`), as every mutation is. |
| 115 | 116 | export async function boardsAsk(ctx: Ctx): Promise<Response> { |
| 116 | 117 | const user = ctx.auth.user; |
| 117 | if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx); | |
| 118 | if (user === undefined || !adminPage(ctx, "boards", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 118 | 119 | const form = await readForm(ctx, "admin"); |
| 119 | 120 | if (form instanceof Response) return form; |
| 120 | 121 | const asked = form.get("ask"); |
src/web/pages/bottleneck.ts +2 −1
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * beside it. Numbers are `system/bottleneck.ts`'s, the same the MCP `system` tool |
| 5 | 5 | * (`kind: bottleneck`) reads. First paint is server-rendered; nothing polls. |
| 6 | 6 | */ |
| 7 | import { signedInPage } from "../../http/page_may.ts"; | |
| 7 | 8 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 8 | 9 | import { telemetryReader } from "../../actions/telemetry.ts"; |
| 9 | 10 | import type { Ctx } from "../../http/context.ts"; |
| @@ -31,7 +32,7 @@ function opRow(o: Op): Html { | ||
| 31 | 32 | |
| 32 | 33 | export async function bottleneckPage(ctx: Ctx): Promise<Response> { |
| 33 | 34 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 34 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 35 | if (!signedInPage(ctx, "bottleneck")) return signInFirst(ctx); | |
| 35 | 36 | const reader = telemetryReader(ctx.app, ctx.auth.user); |
| 36 | 37 | if (reader?.kind !== "owner") return notFoundPage(ctx); |
| 37 | 38 | const rendering = performance.now(); |
src/web/pages/branches.ts +3 −2
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | * are readable and nothing more, which is the whole rule of a live browse. |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | import { signedInPage } from "../../http/page_may.ts"; | |
| 18 | 19 | import { emptyList } from "../empty_words.ts"; |
| 19 | 20 | import { createBranchSaying, deleteBranch } from "../../actions/branches.ts"; |
| 20 | 21 | import type { Repo } from "../../core/repos.ts"; |
| @@ -420,7 +421,7 @@ export async function renderBranches( | ||
| 420 | 421 | export async function branchCreate(ctx: Ctx): Promise<Response> { |
| 421 | 422 | const repo = loadRepo(ctx); |
| 422 | 423 | if (!repo) return notFoundPage(ctx); |
| 423 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 424 | if (!signedInPage(ctx, "branches")) return signInFirst(ctx); | |
| 424 | 425 | const form = await readForm(ctx, "rw"); |
| 425 | 426 | if (form instanceof Response) return form; |
| 426 | 427 | |
| @@ -446,7 +447,7 @@ export async function branchCreate(ctx: Ctx): Promise<Response> { | ||
| 446 | 447 | export async function branchDelete(ctx: Ctx): Promise<Response> { |
| 447 | 448 | const repo = loadRepo(ctx); |
| 448 | 449 | if (!repo) return notFoundPage(ctx); |
| 449 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 450 | if (!signedInPage(ctx, "branches")) return signInFirst(ctx); | |
| 450 | 451 | const form = await readForm(ctx, "rw"); |
| 451 | 452 | if (form instanceof Response) return form; |
| 452 | 453 |
src/web/pages/builds.ts +5 −4
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * first pins hang from its parent repository's, which its objects share. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { deletePin, pinBuild } from "../../actions/builds.ts"; |
| 10 | 11 | import { previewBuild } from "../../actions/build_preview.ts"; |
| 11 | 12 | import { getAppByRepo } from "../../core/apps.ts"; |
| @@ -76,7 +77,7 @@ export async function buildsPage(ctx: Ctx): Promise<Response> { | ||
| 76 | 77 | export async function deletePinSubmit(ctx: Ctx): Promise<Response> { |
| 77 | 78 | const repo = loadRepo(ctx); |
| 78 | 79 | if (!repo) return notFoundPage(ctx); |
| 79 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 80 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 80 | 81 | const form = await readForm(ctx, "rw"); |
| 81 | 82 | if (form instanceof Response) return form; |
| 82 | 83 | const gone = await deletePin(ctx.app, ctx.auth.user, repo, ctx.params.label ?? ""); |
| @@ -153,7 +154,7 @@ export async function newBuildPage(ctx: Ctx): Promise<Response> { | ||
| 153 | 154 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 154 | 155 | const repo = loadRepo(ctx); |
| 155 | 156 | if (!repo) return notFoundPage(ctx); |
| 156 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 157 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 157 | 158 | if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx); |
| 158 | 159 | const base = repoBase(repo); |
| 159 | 160 | const dir = repoDir(ctx.app.reposRoot, repo.ownerName, repo.name); |
| @@ -222,7 +223,7 @@ const PIN_ERRORS: Record<string, string> = { | ||
| 222 | 223 | export async function pinBuildSubmit(ctx: Ctx): Promise<Response> { |
| 223 | 224 | const repo = loadRepo(ctx); |
| 224 | 225 | if (!repo) return notFoundPage(ctx); |
| 225 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 226 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 226 | 227 | const form = await readForm(ctx, "rw"); |
| 227 | 228 | if (form instanceof Response) return form; |
| 228 | 229 | const base = repoBase(repo); |
| @@ -257,7 +258,7 @@ const PREVIEW_ERRORS: Record<string, string> = { | ||
| 257 | 258 | export async function previewBuildSubmit(ctx: Ctx): Promise<Response> { |
| 258 | 259 | const repo = loadRepo(ctx); |
| 259 | 260 | if (!repo) return notFoundPage(ctx); |
| 260 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 261 | if (!signedInPage(ctx, "builds")) return signInFirst(ctx); | |
| 261 | 262 | const form = await readForm(ctx, "rw"); |
| 262 | 263 | if (form instanceof Response) return form; |
| 263 | 264 | const preview = await previewBuild(ctx.app, ctx.auth.user, repo, formValue(form, "sha")); |
src/web/pages/capacity.ts +3 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * and each one is listed below the settings: who, when, from what to what. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { CAPACITY_GROUPS, DERIVED_WORDS, REASON_WORDS, changeCapacity, checkCapacity, edgeOffDryRun, listCapacity, type CapacityRow } from "../../actions/capacity.ts"; |
| 10 | 11 | import { CAPACITY, REASON_MAX, belowCeiling, bootDefault, needsReason, type CapacityKey } from "../../core/capacity.ts"; |
| 11 | 12 | import { effectOf, loadLine } from "../../actions/capacity_effects.ts"; |
| @@ -26,8 +27,8 @@ import { lentLine } from "../../checks/lent_scope.ts"; | ||
| 26 | 27 | import { lentIn } from "../../checks/runner_jobs.ts"; |
| 27 | 28 | |
| 28 | 29 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 29 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 30 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 30 | if (!signedInPage(ctx, "capacity")) return signInFirst(ctx); | |
| 31 | if (!adminPage(ctx, "capacity", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 31 | 32 | return undefined; |
| 32 | 33 | } |
| 33 | 34 |
src/web/pages/chain.ts +6 −5
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * sever. A severed forge says so with the date and nothing is deleted. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { FAMILY_WORDS } from "../../actions/family_words.ts"; |
| 9 | 10 | import { emptyNote } from "../empty_words.ts"; |
| 10 | 11 | import { FOLLOW_MODE_REFUSALS, followModeSaid, setFollowMode, severForge, takeForgeCode, takeForgeWords } from "../../actions/follow.ts"; |
| @@ -183,7 +184,7 @@ export async function chainPage(ctx: Ctx): Promise<Response> { | ||
| 183 | 184 | export async function severSubmit(ctx: Ctx): Promise<Response> { |
| 184 | 185 | const repo = loadRepo(ctx); |
| 185 | 186 | if (!repo) return notFoundPage(ctx); |
| 186 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 187 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 187 | 188 | const form = await readForm(ctx, "rw"); |
| 188 | 189 | if (form instanceof Response) return form; |
| 189 | 190 | const to = `${repoBase(repo)}/following`; |
| @@ -202,7 +203,7 @@ export async function severSubmit(ctx: Ctx): Promise<Response> { | ||
| 202 | 203 | export async function checkSubmit(ctx: Ctx): Promise<Response> { |
| 203 | 204 | const repo = loadRepo(ctx); |
| 204 | 205 | if (!repo) return notFoundPage(ctx); |
| 205 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 206 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 206 | 207 | const form = await readForm(ctx, "rw"); |
| 207 | 208 | if (form instanceof Response) return form; |
| 208 | 209 | const to = `${repoBase(repo)}/following`; |
| @@ -217,7 +218,7 @@ export async function checkSubmit(ctx: Ctx): Promise<Response> { | ||
| 217 | 218 | export async function takeSubmit(ctx: Ctx): Promise<Response> { |
| 218 | 219 | const repo = loadRepo(ctx); |
| 219 | 220 | if (!repo) return notFoundPage(ctx); |
| 220 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 221 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 221 | 222 | const form = await readForm(ctx, "rw"); |
| 222 | 223 | if (form instanceof Response) return form; |
| 223 | 224 | const to = `${repoBase(repo)}/following`; |
| @@ -237,7 +238,7 @@ export async function takeSubmit(ctx: Ctx): Promise<Response> { | ||
| 237 | 238 | export async function modeSubmit(ctx: Ctx): Promise<Response> { |
| 238 | 239 | const repo = loadRepo(ctx); |
| 239 | 240 | if (!repo) return notFoundPage(ctx); |
| 240 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 241 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 241 | 242 | const form = await readForm(ctx, "rw"); |
| 242 | 243 | if (form instanceof Response) return form; |
| 243 | 244 | const to = `${repoBase(repo)}/following`; |
| @@ -253,7 +254,7 @@ export async function modeSubmit(ctx: Ctx): Promise<Response> { | ||
| 253 | 254 | export async function proposeParentSubmit(ctx: Ctx): Promise<Response> { |
| 254 | 255 | const repo = loadRepo(ctx); |
| 255 | 256 | if (!repo) return notFoundPage(ctx); |
| 256 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 257 | if (!signedInPage(ctx, "chain")) return signInFirst(ctx); | |
| 257 | 258 | const form = await readForm(ctx, "rw"); |
| 258 | 259 | if (form instanceof Response) return form; |
| 259 | 260 | const to = `${repoBase(repo)}/following`; |
src/web/pages/client_cloud.ts +6 −5
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * finds no such page. Nothing here is cached, indexed or linked from a public page. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { OFF_SWITCH, attachClientCloud, endClientCloudKey, grantClientCloud, lookAtClientCloud, myClientClouds, type ClientCloudView } from "../../actions/client_cloud.ts"; |
| 10 | 11 | import { CLIENT_PROVIDERS } from "../../cloud/client_read.ts"; |
| 11 | 12 | import { KEEP_DAYS, LABEL_MAX } from "../../core/client_cloud.ts"; |
| @@ -52,7 +53,7 @@ function clientCloudsBody(ctx: Ctx): Response { | ||
| 52 | 53 | const user = ctx.auth.user; |
| 53 | 54 | if (!user) return signInFirst(ctx); |
| 54 | 55 | const mine = myClientClouds(ctx.app, user); |
| 55 | if (mine.length === 0 && !user.isAdmin) return notFoundPage(ctx); | |
| 56 | if (mine.length === 0 && !adminPage(ctx, "client_cloud", user.isAdmin)) return notFoundPage(ctx); | |
| 56 | 57 | return sealed( |
| 57 | 58 | page({ |
| 58 | 59 | ctx, |
| @@ -79,7 +80,7 @@ function clientCloudsBody(ctx: Ctx): Response { | ||
| 79 | 80 | |
| 80 | 81 | // POST /client-clouds |
| 81 | 82 | export async function clientCloudAttach(ctx: Ctx): Promise<Response> { |
| 82 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 83 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 83 | 84 | const form = await readForm(ctx, "admin"); |
| 84 | 85 | if (form instanceof Response) return form; |
| 85 | 86 | const r = await attachClientCloud(ctx.app, ctx.auth.user, { |
| @@ -112,7 +113,7 @@ function seenCard(v: ClientCloudView): Html { | ||
| 112 | 113 | |
| 113 | 114 | // GET /client-clouds/:id |
| 114 | 115 | export async function clientCloudPage(ctx: Ctx): Promise<Response> { |
| 115 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 116 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 116 | 117 | const r = await lookAtClientCloud(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| 117 | 118 | if (!r.ok) return notFoundPage(ctx); |
| 118 | 119 | const v = r.value; |
| @@ -142,7 +143,7 @@ export async function clientCloudPage(ctx: Ctx): Promise<Response> { | ||
| 142 | 143 | |
| 143 | 144 | // POST /client-clouds/:id/grant |
| 144 | 145 | export async function clientCloudGrant(ctx: Ctx): Promise<Response> { |
| 145 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 146 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 146 | 147 | const form = await readForm(ctx, "admin"); |
| 147 | 148 | if (form instanceof Response) return form; |
| 148 | 149 | const id = ctx.params.id ?? ""; |
| @@ -153,7 +154,7 @@ export async function clientCloudGrant(ctx: Ctx): Promise<Response> { | ||
| 153 | 154 | |
| 154 | 155 | // POST /client-clouds/:id/end |
| 155 | 156 | export async function clientCloudEnd(ctx: Ctx): Promise<Response> { |
| 156 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 157 | if (!signedInPage(ctx, "client_cloud")) return signInFirst(ctx); | |
| 157 | 158 | const form = await readForm(ctx, "admin"); |
| 158 | 159 | if (form instanceof Response) return form; |
| 159 | 160 | const id = ctx.params.id ?? ""; |
src/web/pages/cloud.ts +3 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * event. "Write allowed" is off until someone turns it on here. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import type { Database } from "bun:sqlite"; |
| 10 | 11 | import { sshOn } from "../../settings/ssh.ts"; |
| 11 | 12 | import { |
| @@ -51,8 +52,8 @@ import { accountSections } from "./origins.ts"; | ||
| 51 | 52 | const BACK = "/settings/cloud"; |
| 52 | 53 | |
| 53 | 54 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 54 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 55 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 55 | if (!signedInPage(ctx, "cloud")) return signInFirst(ctx); | |
| 56 | if (!adminPage(ctx, "cloud", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 56 | 57 | return undefined; |
| 57 | 58 | } |
| 58 | 59 |
src/web/pages/config.ts +3 −2
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | * its line. |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | import { signedInPage } from "../../http/page_may.ts"; | |
| 23 | 24 | import type { Flash } from "../flash.ts"; |
| 24 | 25 | import { blockedFlash } from "../blocked.ts"; |
| 25 | 26 | import { FORK_NEEDS_MEMBER, notMemberBlocked } from "../../actions/blocked_words.ts"; |
| @@ -67,7 +68,7 @@ async function commitsDirectly(ctx: Ctx, scope: RepoScope, ref: string): Promise | ||
| 67 | 68 | function configContext(ctx: Ctx, ref: string, path: string): RepoScope | Response { |
| 68 | 69 | const repo = loadRepo(ctx); |
| 69 | 70 | if (!repo) return notFoundPage(ctx); |
| 70 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 71 | if (!signedInPage(ctx, "config")) return signInFirst(ctx); | |
| 71 | 72 | if (!isSafeRef(ref) || !isSafeTreePath(path) || !isFormConfig(path)) return notFoundPage(ctx); |
| 72 | 73 | const scope = localScope(ctx, repo); |
| 73 | 74 | // A mirror you cannot push to proposes through its origin: the source editor's card. |
| @@ -264,7 +265,7 @@ export async function configSubmit(ctx: Ctx): Promise<Response> { | ||
| 264 | 265 | // Who may write is settled before the body is read: a private repository |
| 265 | 266 | // answers a stranger 404, as every page about it does. |
| 266 | 267 | if (!loadRepo(ctx)) return notFoundPage(ctx); |
| 267 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 268 | if (!signedInPage(ctx, "config")) return signInFirst(ctx); | |
| 268 | 269 | const form = await readForm(ctx, "rw"); |
| 269 | 270 | if (form instanceof Response) return form; |
| 270 | 271 | const ref = formValue(form, "ref"); |
src/web/pages/connections.ts +2 −1
| @@ -34,6 +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 | 38 | |
| 38 | 39 | const BACK = "/settings/model"; |
| 39 | 40 | |
| @@ -212,7 +213,7 @@ export async function connectionRetest(ctx: Ctx): Promise<Response> { | ||
| 212 | 213 | const form = await readForm(ctx, "admin"); |
| 213 | 214 | if (form instanceof Response) return form; |
| 214 | 215 | const c = connectionFor(ctx.app.db, user.id, ctx.params["id"] ?? ""); |
| 215 | if (c === undefined || (c.scope === "forge" && !user.isAdmin)) | |
| 216 | if (c === undefined || (c.scope === "forge" && !adminPage(ctx, "connections", user.isAdmin))) | |
| 216 | 217 | return notFoundPage(ctx); |
| 217 | 218 | const test = await retestConnection(ctx.app, user, c.id); |
| 218 | 219 | if (test === "busy") return flashTo(ctx, BACK, { tone: "danger", message: CONNECTION_REFUSED["busy"]! }); |
src/web/pages/crew-settings.ts +2 −1
| @@ -16,6 +16,7 @@ import { field } from "../form.ts"; | ||
| 16 | 16 | import { flashTo, redirect } from "../layout.ts"; |
| 17 | 17 | import { adminForm } from "../admin_form.ts"; |
| 18 | 18 | import { saveGrants } from "./subscriptions.ts"; |
| 19 | import { adminPage } from "../../http/page_may.ts"; | |
| 19 | 20 | |
| 20 | 21 | // GET /:owner/:name/settings/crew |
| 21 | 22 | export function crewSettingsPage(ctx: Ctx): Response { |
| @@ -29,7 +30,7 @@ export async function crewSubscriptionsSave(ctx: Ctx): Promise<Response> { | ||
| 29 | 30 | const gate = await adminForm(ctx); |
| 30 | 31 | if (gate instanceof Response) return gate; |
| 31 | 32 | const { repo, form } = gate; |
| 32 | if (ctx.auth.user?.isAdmin !== true) return repoNotFound(ctx); | |
| 33 | if (!adminPage(ctx, "crew-settings", ctx.auth.user?.isAdmin === true)) return repoNotFound(ctx); | |
| 33 | 34 | const crew = listCrew(ctx.app, ctx.auth.user, repo); |
| 34 | 35 | saveGrants(ctx, form, repo.id, crew.ok ? crew.value : []); |
| 35 | 36 | return flashTo(ctx, `${repoBase(repo)}/settings#crew`, { |
src/web/pages/crew.ts +3 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * the crew is actually there, in words, before anyone assigns anything. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { memberRecords, type MemberRecord } from "../../crew/member_record.ts"; |
| 10 | 11 | import { crewTop, TOP_HELP } from "../crew_top.ts"; |
| 11 | 12 | import { sshOn } from "../../settings/ssh.ts"; |
| @@ -96,8 +97,8 @@ import { forgeCeiling } from "../../flow/ceiling.ts"; | ||
| 96 | 97 | |
| 97 | 98 | /** The admin, or the response that turns everyone else away. */ |
| 98 | 99 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 99 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 100 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 100 | if (!signedInPage(ctx, "crew")) return signInFirst(ctx); | |
| 101 | if (!adminPage(ctx, "crew", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 101 | 102 | return undefined; |
| 102 | 103 | } |
| 103 | 104 |
src/web/pages/data.ts +2 −1
| @@ -21,6 +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 | 25 | |
| 25 | 26 | const PURPOSE = "Every SQLite file you may read; secrets are masked."; |
| 26 | 27 | |
| @@ -61,7 +62,7 @@ export async function adminDataPage(ctx: Ctx): Promise<Response> { | ||
| 61 | 62 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 62 | 63 | const viewer = ctx.auth.user; |
| 63 | 64 | if (!viewer) return signInFirst(ctx); |
| 64 | if (!viewer.isAdmin) return refuse(ctx); | |
| 65 | if (!adminPage(ctx, "data", viewer.isAdmin)) return refuse(ctx); | |
| 65 | 66 | const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.kind === "forge"); |
| 66 | 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." })); |
| 67 | 68 | } |
src/web/pages/dataset.ts +3 −2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * so the page stays quick on a forge with a long history. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { datasetAnswers as answers, lastExport } from "../../actions/dataset.ts"; |
| 9 | 10 | import { datasetStats } from "../../core/dataset.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| @@ -23,8 +24,8 @@ const usd = (n: number): string => `$${n.toFixed(2)}`; | ||
| 23 | 24 | export function datasetPage(ctx: Ctx): Response { |
| 24 | 25 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 25 | 26 | const rendering = performance.now(); |
| 26 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 27 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 27 | if (!signedInPage(ctx, "dataset")) return signInFirst(ctx); | |
| 28 | if (!adminPage(ctx, "dataset", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 28 | 29 | const stats = datasetStats(ctx.app.db); |
| 29 | 30 | const last = lastExport(ctx.app); |
| 30 | 31 | const a = answers(ctx.app.db); |
src/web/pages/economics.ts +3 −2
| @@ -13,6 +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 | 17 | import { sshOn } from "../../settings/ssh.ts"; |
| 17 | 18 | import { emptyNote } from "../empty_words.ts"; |
| 18 | 19 | import { ECONOMICS_WORDS, changeEconomics, readEconomics } from "../../actions/economics.ts"; |
| @@ -32,7 +33,7 @@ const PATH = "/settings/economics"; | ||
| 32 | 33 | // GET /settings/economics |
| 33 | 34 | export function economicsPage(ctx: Ctx): Response { |
| 34 | 35 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 35 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 36 | if (!signedInPage(ctx, "economics")) return signInFirst(ctx); | |
| 36 | 37 | const read = timePhase(ctx.request, "economics", () => readEconomics(ctx.app, ctx.auth.user)); |
| 37 | 38 | if (!read.ok) return notFoundPage(ctx); |
| 38 | 39 | const rendering = performance.now(); |
| @@ -175,7 +176,7 @@ export function economicsPage(ctx: Ctx): Response { | ||
| 175 | 176 | // POST /settings/economics |
| 176 | 177 | export async function economicsSet(ctx: Ctx): Promise<Response> { |
| 177 | 178 | // Checked before the body is read: a non-admin learns nothing of the door. |
| 178 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 179 | if (!adminPage(ctx, "economics", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 179 | 180 | const form = await readForm(ctx, "admin"); |
| 180 | 181 | if (form instanceof Response) return form; |
| 181 | 182 | // A field the posted form does not carry is left undefined: kept as it stands. |
src/web/pages/edit.ts +5 −4
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | * preview are `editorJs`, and none of them is load-bearing. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | import { signedInPage } from "../../http/page_may.ts"; | |
| 20 | 21 | import { binaryRefusal } from "../render/opens_with.ts"; |
| 21 | 22 | import { fileKind, NO_BYTES } from "../render/kinds.ts"; |
| 22 | 23 | import { editFiles, fileAt, MAX_FILE_BYTES } from "../../actions/contents.ts"; |
| @@ -651,7 +652,7 @@ const isMarkdownPath = (path: string): boolean => | ||
| 651 | 652 | function editContext(ctx: Ctx): { scope: RepoScope; ref: string } | Response { |
| 652 | 653 | const repo = loadRepo(ctx); |
| 653 | 654 | if (!repo) return notFoundPage(ctx); |
| 654 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 655 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 655 | 656 | const scope = localScope(ctx, repo); |
| 656 | 657 | // A reader may not change it; a fork is how they propose. Someone who cannot read never got here. |
| 657 | 658 | if (!scope.caps.write) return cannotChangePage(ctx, scope, repo); |
| @@ -963,7 +964,7 @@ export async function runContribute( | ||
| 963 | 964 | export async function contributeSubmit(ctx: Ctx): Promise<Response> { |
| 964 | 965 | const repo = loadRepo(ctx); |
| 965 | 966 | if (!repo) return notFoundPage(ctx); |
| 966 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 967 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 967 | 968 | const form = await readForm(ctx, "rw"); |
| 968 | 969 | if (form instanceof Response) return form; |
| 969 | 970 | const scope = localScope(ctx, repo); |
| @@ -1105,7 +1106,7 @@ async function dxfSubmit(ctx: Ctx, scope: RepoScope, repo: Repo, form: Form): Pr | ||
| 1105 | 1106 | export async function editSubmit(ctx: Ctx): Promise<Response> { |
| 1106 | 1107 | const repo = loadRepo(ctx); |
| 1107 | 1108 | if (!repo) return notFoundPage(ctx); |
| 1108 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1109 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 1109 | 1110 | const form = await readForm(ctx, "rw"); |
| 1110 | 1111 | if (form instanceof Response) return form; |
| 1111 | 1112 | const scope = localScope(ctx, repo); |
| @@ -1296,7 +1297,7 @@ export async function deleteFilePage(ctx: Ctx): Promise<Response> { | ||
| 1296 | 1297 | export async function deleteFileSubmit(ctx: Ctx): Promise<Response> { |
| 1297 | 1298 | const repo = loadRepo(ctx); |
| 1298 | 1299 | if (!repo) return notFoundPage(ctx); |
| 1299 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1300 | if (!signedInPage(ctx, "edit")) return signInFirst(ctx); | |
| 1300 | 1301 | const form = await readForm(ctx, "rw"); |
| 1301 | 1302 | if (form instanceof Response) return form; |
| 1302 | 1303 | const scope = localScope(ctx, repo); |
src/web/pages/everyday.ts +4 −3
| @@ -40,6 +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 | 44 | |
| 44 | 45 | const USERNAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/; |
| 45 | 46 | |
| @@ -166,7 +167,7 @@ export async function everydayOptions(ctx: Ctx): Promise<Response> { | ||
| 166 | 167 | const admin = ctx.auth.user; |
| 167 | 168 | if (!admin) return refuse(401, "Sign in first."); |
| 168 | 169 | if (ctx.auth.via !== "session") return refuse(403, "Passkeys are made from a signed-in browser."); |
| 169 | if (!admin.isAdmin) return refuse(403, NOT_ADMIN_HERE); | |
| 170 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return refuse(403, NOT_ADMIN_HERE); | |
| 170 | 171 | if (everydayOf(ctx.app.db, admin) !== undefined) |
| 171 | 172 | return refuse(409, "You already have an everyday account."); |
| 172 | 173 | const data = await boundedBody(ctx.request, STRANGER_MAX); |
| @@ -184,7 +185,7 @@ export async function everydayCreate(ctx: Ctx): Promise<Response> { | ||
| 184 | 185 | if (!admin) return signInFirst(ctx); |
| 185 | 186 | const form = await readForm(ctx, "admin"); |
| 186 | 187 | if (form instanceof Response) return form; |
| 187 | if (!admin.isAdmin) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 188 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 188 | 189 | const existing = everydayOf(ctx.app.db, admin); |
| 189 | 190 | if (existing !== undefined) |
| 190 | 191 | return flashTo(ctx, "/settings", { |
| @@ -252,7 +253,7 @@ export async function everydayKeep(ctx: Ctx): Promise<Response> { | ||
| 252 | 253 | if (!admin) return signInFirst(ctx); |
| 253 | 254 | const form = await readForm(ctx, "admin"); |
| 254 | 255 | if (form instanceof Response) return form; |
| 255 | if (!admin.isAdmin) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 256 | if (!adminPage(ctx, "everyday", admin.isAdmin)) return forbiddenPage(ctx, NOT_ADMIN_HERE); | |
| 256 | 257 | keepAdmin(ctx.app.db, admin); |
| 257 | 258 | return flashTo(ctx, "/", { |
| 258 | 259 | message: |
src/web/pages/features.ts +3 −2
| @@ -6,6 +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 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { upstreamBlob } from "../../core/upstream.ts"; |
| 11 | 12 | import { |
| @@ -39,8 +40,8 @@ import { badge, btn, empty, row, time } from "../ui.ts"; | ||
| 39 | 40 | import { accountSections } from "./origins.ts"; |
| 40 | 41 | |
| 41 | 42 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 42 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 43 | if (!ctx.auth.user.isAdmin || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 43 | if (!signedInPage(ctx, "features")) return signInFirst(ctx); | |
| 44 | if (!adminPage(ctx, "features", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 44 | 45 | return undefined; |
| 45 | 46 | } |
| 46 | 47 |
src/web/pages/first.ts +2 −1
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | /** POST /:owner/:name/issues/:number/first — a writer puts a ready issue first (#7808). */ |
| 2 | import { signedInPage } from "../../http/page_may.ts"; | |
| 2 | 3 | import { putIssueFirst } from "../../actions/first.ts"; |
| 3 | 4 | import type { Ctx } from "../../http/context.ts"; |
| 4 | 5 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| @@ -8,7 +9,7 @@ import { flashOrJson } from "../layout.ts"; | ||
| 8 | 9 | export async function firstSubmit(ctx: Ctx): Promise<Response> { |
| 9 | 10 | const repo = loadRepo(ctx); |
| 10 | 11 | if (!repo) return notFoundPage(ctx); |
| 11 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 12 | if (!signedInPage(ctx, "first")) return signInFirst(ctx); | |
| 12 | 13 | const form = await readForm(ctx, "rw"); |
| 13 | 14 | if (form instanceof Response) return form; |
| 14 | 15 | const dest = backTo(form, `${repoBase(repo)}/map`); |
src/web/pages/fleet-ops.ts +4 −3
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * is same-origin (`readForm`), and only a signed-in person acts. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { |
| 10 | 11 | applyPreviewed, |
| 11 | 12 | getFleetOp, |
| @@ -25,7 +26,7 @@ import { canAct, renderFleet } from "./fleet.ts"; | ||
| 25 | 26 | |
| 26 | 27 | /** POST /fleet */ |
| 27 | 28 | export async function fleetAct(ctx: Ctx): Promise<Response> { |
| 28 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 29 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 29 | 30 | if (!canAct(ctx)) return notFoundPage(ctx); |
| 30 | 31 | const form = await readForm(ctx, "rw"); |
| 31 | 32 | if (form instanceof Response) return form; |
| @@ -90,7 +91,7 @@ function refusal( | ||
| 90 | 91 | |
| 91 | 92 | /** GET /fleet/ops/:id */ |
| 92 | 93 | export function fleetReceipt(ctx: Ctx): Response { |
| 93 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 94 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 94 | 95 | const found = getFleetOp(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
| 95 | 96 | if (!found.ok) return notFoundPage(ctx); |
| 96 | 97 | const op = found.value; |
| @@ -107,7 +108,7 @@ export function fleetReceipt(ctx: Ctx): Response { | ||
| 107 | 108 | |
| 108 | 109 | /** POST /fleet/ops/:id/undo */ |
| 109 | 110 | export async function fleetUndo(ctx: Ctx): Promise<Response> { |
| 110 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 111 | if (!signedInPage(ctx, "fleet-ops")) return signInFirst(ctx); | |
| 111 | 112 | if (!canAct(ctx)) return notFoundPage(ctx); |
| 112 | 113 | const form = await readForm(ctx, "rw"); |
| 113 | 114 | if (form instanceof Response) return form; |
src/web/pages/flow.ts +5 −4
| @@ -14,6 +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 | 18 | import { retryBackup } from "../../actions/backup_retry.ts"; |
| 18 | 19 | import { alarmBackup, type BackupAlarm } from "../../flow/alarm_backup.ts"; |
| 19 | 20 | import { acceptSuggestion, turnValveFor, type ValveError } from "../../actions/valves.ts"; |
| @@ -160,7 +161,7 @@ export async function flowPage(ctx: Ctx): Promise<Response> { | ||
| 160 | 161 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 161 | 162 | const user = ctx.auth.user; |
| 162 | 163 | if (user === undefined) return signInFirst(ctx); |
| 163 | if (!user.isAdmin || user.kind === "agent") return notFoundPage(ctx); | |
| 164 | if (!adminPage(ctx, "flow", user.isAdmin && user.kind !== "agent")) return notFoundPage(ctx); | |
| 164 | 165 | // What a "Reading…" page asks: it answers when the worker has the picture, and draws nothing. |
| 165 | 166 | if (waiting) { |
| 166 | 167 | return waitAnswer(await flowPicture(ctx.app, user.id, LONG_WAIT_MS)); |
| @@ -241,7 +242,7 @@ function done(ctx: Ctx, result: ReturnType<typeof turnValveFor>): Response { | ||
| 241 | 242 | |
| 242 | 243 | // POST /flow/valve |
| 243 | 244 | export async function valveSet(ctx: Ctx): Promise<Response> { |
| 244 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 245 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 245 | 246 | const form = await readForm(ctx, "admin"); |
| 246 | 247 | if (form instanceof Response) return form; |
| 247 | 248 | return done(ctx, turnValveFor(ctx.app, ctx.auth.user, field(form, "repo"), field(form, "level"))); |
| @@ -249,7 +250,7 @@ export async function valveSet(ctx: Ctx): Promise<Response> { | ||
| 249 | 250 | |
| 250 | 251 | // POST /flow/suggestion |
| 251 | 252 | export async function suggestionTake(ctx: Ctx): Promise<Response> { |
| 252 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 253 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 253 | 254 | const form = await readForm(ctx, "admin"); |
| 254 | 255 | if (form instanceof Response) return form; |
| 255 | 256 | return done(ctx, acceptSuggestion(ctx.app, ctx.auth.user, field(form, "repo"))); |
| @@ -257,7 +258,7 @@ export async function suggestionTake(ctx: Ctx): Promise<Response> { | ||
| 257 | 258 | |
| 258 | 259 | // POST /flow/backup/retry: one snapshot now, through the service's own queue, so two never run at once. |
| 259 | 260 | export async function backupRetry(ctx: Ctx): Promise<Response> { |
| 260 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 261 | if (!signedInPage(ctx, "flow")) return signInFirst(ctx); | |
| 261 | 262 | const form = await readForm(ctx, "admin"); |
| 262 | 263 | if (form instanceof Response) return form; |
| 263 | 264 | const retried = await retryBackup(ctx.app, ctx.auth.user); |
src/web/pages/flows-all.ts +2 −1
| @@ -15,6 +15,7 @@ import { html } from "../html.ts"; | ||
| 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 | 19 | |
| 19 | 20 | /** Lines drawn at once; the count above says how many matched. */ |
| 20 | 21 | const SHOWN = 500; |
| @@ -25,7 +26,7 @@ const TONE: Record<Health, Tone> = { ok: "default", behind: "attn", diverged: "d | ||
| 25 | 26 | export function allFlowsPage(ctx: Ctx): Response { |
| 26 | 27 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 27 | 28 | const user = ctx.auth.user; |
| 28 | if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx); | |
| 29 | if (!adminPage(ctx, "flows", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx); | |
| 29 | 30 | const q = new URL(ctx.request.url).searchParams; |
| 30 | 31 | const kind = parseKind(q.get("kind")); |
| 31 | 32 | const stale = q.get("stale") === "1"; |
src/web/pages/following.ts +2 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * — it becomes the crew's proposal, or an honest sentence about why not. |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { signedInPage } from "../../http/page_may.ts"; | |
| 13 | 14 | import { |
| 14 | 15 | relationOf, |
| 15 | 16 | type ForkRelation, |
| @@ -602,7 +603,7 @@ export function followingCard( | ||
| 602 | 603 | export async function followingSubmit(ctx: Ctx): Promise<Response> { |
| 603 | 604 | const repo = loadRepo(ctx); |
| 604 | 605 | if (!repo) return notFoundPage(ctx); |
| 605 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 606 | if (!signedInPage(ctx, "following")) return signInFirst(ctx); | |
| 606 | 607 | const form = await readForm(ctx, "rw"); |
| 607 | 608 | if (form instanceof Response) return form; |
| 608 | 609 | const base = repoBase(repo); |
src/web/pages/forge_machine.ts +3 −2
| @@ -16,6 +16,7 @@ import { readForm } from "../form.ts"; | ||
| 16 | 16 | import { html } from "../html.ts"; |
| 17 | 17 | import { page } from "../layout.ts"; |
| 18 | 18 | import { btn } from "../ui.ts"; |
| 19 | import { adminPage } from "../../http/page_may.ts"; | |
| 19 | 20 | |
| 20 | 21 | const back = (name: string) => btn("Back to your forges", { href: `/forges#forge-${name}`, size: "sm" }); |
| 21 | 22 | |
| @@ -29,7 +30,7 @@ const choose = (name: string, machines: readonly string[], recover: boolean) => | ||
| 29 | 30 | |
| 30 | 31 | export async function forgeMachineForm(ctx: Ctx): Promise<Response> { |
| 31 | 32 | const user = ctx.auth.user; |
| 32 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 33 | if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx); | |
| 33 | 34 | const name = ctx.params["name"] ?? ""; |
| 34 | 35 | const to = ctx.url.searchParams.get("to") ?? ""; |
| 35 | 36 | const recover = ctx.url.searchParams.get("recover") === "1"; |
| @@ -57,7 +58,7 @@ export async function forgeMachineForm(ctx: Ctx): Promise<Response> { | ||
| 57 | 58 | |
| 58 | 59 | export async function forgeMachineSubmit(ctx: Ctx): Promise<Response> { |
| 59 | 60 | const user = ctx.auth.user; |
| 60 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 61 | if (user === undefined || !adminPage(ctx, "forge_machine", user.isAdmin)) return notFoundPage(ctx); | |
| 61 | 62 | const form = await readForm(ctx, "admin"); |
| 62 | 63 | if (form instanceof Response) return form; |
| 63 | 64 | const name = ctx.params["name"] ?? ""; |
src/web/pages/forge_move_in.ts +3 −2
| @@ -16,6 +16,7 @@ import { html, type Html } from "../html.ts"; | ||
| 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 | 20 | |
| 20 | 21 | const wrap = (title: string, body: Html) => |
| 21 | 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>`; |
| @@ -27,7 +28,7 @@ const done = (response: Response): Response => { | ||
| 27 | 28 | |
| 28 | 29 | export function forgeMoveInForm(ctx: Ctx): Response { |
| 29 | 30 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 30 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 31 | if (!adminPage(ctx, "forge_move_in", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 31 | 32 | const rendering = performance.now(); |
| 32 | 33 | const cost = moveInCost(); |
| 33 | 34 | const body = html`<dl class="status-rows" data-preview>${cost.rows.map(([label, value]) => statusRow(label, html`${value}`))}</dl> |
| @@ -45,7 +46,7 @@ export function forgeMoveInForm(ctx: Ctx): Response { | ||
| 45 | 46 | |
| 46 | 47 | export async function forgeMoveInSubmit(ctx: Ctx): Promise<Response> { |
| 47 | 48 | const user = ctx.auth.user; |
| 48 | if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx); | |
| 49 | if (!adminPage(ctx, "forge_move_in", user?.isAdmin === true && user.kind !== "agent")) return notFoundPage(ctx); | |
| 49 | 50 | const form = await readForm(ctx, "admin", BODY_CAPS.moveIn.bytes); |
| 50 | 51 | if (form instanceof Response) return form; |
| 51 | 52 | const name = String(form.get("name") ?? "").trim().toLowerCase(); |
src/web/pages/forge_upgrade.ts +3 −2
| @@ -15,6 +15,7 @@ import { html, type Html } from "../html.ts"; | ||
| 15 | 15 | import { page } from "../layout.ts"; |
| 16 | 16 | import { btn, selectField } from "../ui.ts"; |
| 17 | 17 | import { statusRow } from "./security.ts"; |
| 18 | import { adminPage } from "../../http/page_may.ts"; | |
| 18 | 19 | |
| 19 | 20 | const back = (name: string) => btn("Back to your forges", { href: `/forges#forge-${name}`, size: "sm" }); |
| 20 | 21 | |
| @@ -23,7 +24,7 @@ const wrap = (name: string, body: Html) => | ||
| 23 | 24 | |
| 24 | 25 | export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> { |
| 25 | 26 | const user = ctx.auth.user; |
| 26 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 27 | if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx); | |
| 27 | 28 | const name = ctx.params["name"] ?? ""; |
| 28 | 29 | const plan = ctx.url.searchParams.get("plan") ?? ""; |
| 29 | 30 | const to = ctx.url.searchParams.get("to") ?? ""; |
| @@ -52,7 +53,7 @@ export async function forgeUpgradeForm(ctx: Ctx): Promise<Response> { | ||
| 52 | 53 | |
| 53 | 54 | export async function forgeUpgradeSubmit(ctx: Ctx): Promise<Response> { |
| 54 | 55 | const user = ctx.auth.user; |
| 55 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 56 | if (!adminPage(ctx, "forge_upgrade", user?.isAdmin === true)) return notFoundPage(ctx); | |
| 56 | 57 | const form = await readForm(ctx, "admin"); |
| 57 | 58 | if (form instanceof Response) return form; |
| 58 | 59 | const name = ctx.params["name"] ?? ""; |
src/web/pages/forges.ts +13 −12
| @@ -49,6 +49,7 @@ import { claimedWords, isForgeSort, keepWords, SORT_WORDS, sortForges, type Forg | ||
| 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 | 53 | |
| 53 | 54 | |
| 54 | 55 | /** "3 apps running", or which one is not and why. */ |
| @@ -261,7 +262,7 @@ function refusedLink(ctx: Ctx): Html | null { | ||
| 261 | 262 | // GET /forges/export.csv — the client list as a download, behind the page's own gate (a missing |
| 262 | 263 | // page to anyone else). |
| 263 | 264 | export async function forgesCsv(ctx: Ctx): Promise<Response> { |
| 264 | if (!ctx.auth.user?.isAdmin) return notFoundPage(ctx); | |
| 265 | if (!adminPage(ctx, "forges", ctx.auth.user?.isAdmin === true)) return notFoundPage(ctx); | |
| 265 | 266 | const rows = sortForges(await servedRows(ctx.app), "attention"); |
| 266 | 267 | return new Response(clientsCsv(rows), { |
| 267 | 268 | headers: { |
| @@ -276,7 +277,7 @@ export async function forgesCsv(ctx: Ctx): Promise<Response> { | ||
| 276 | 277 | // GET /forges — an admin's only. |
| 277 | 278 | export async function forgesPage(ctx: Ctx): Promise<Response> { |
| 278 | 279 | const user = ctx.auth.user; |
| 279 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 280 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 280 | 281 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 281 | 282 | const asked = ctx.url.searchParams.get("sort"); |
| 282 | 283 | const sort: ForgeSort = isForgeSort(asked) ? asked : "attention"; |
| @@ -390,7 +391,7 @@ export async function forgeLinkForm(ctx: Ctx): Promise<Response> { | ||
| 390 | 391 | // does it; nothing changes until it is pressed (#14518). |
| 391 | 392 | export async function forgeRevokeConfirm(ctx: Ctx): Promise<Response> { |
| 392 | 393 | const user = ctx.auth.user; |
| 393 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 394 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 394 | 395 | const name = ctx.params["name"] ?? ""; |
| 395 | 396 | if (!CHILD_NAME.test(name)) return notFoundPage(ctx); |
| 396 | 397 | const response = page({ |
| @@ -443,7 +444,7 @@ async function namedForges(ctx: Ctx, wanted: readonly string[]): Promise<string[ | ||
| 443 | 444 | // that does it. |
| 444 | 445 | export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> { |
| 445 | 446 | const user = ctx.auth.user; |
| 446 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 447 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 447 | 448 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 448 | 449 | const names = await namedForges(ctx, ctx.url.searchParams.getAll("name")); |
| 449 | 450 | const rows = (await servedRows(ctx.app)).filter((r) => names.includes(r.name)); |
| @@ -477,7 +478,7 @@ export async function forgeArchiveConfirm(ctx: Ctx): Promise<Response> { | ||
| 477 | 478 | // POST /forges/archive — archive each named forge, one after another; the receipt says each result. |
| 478 | 479 | export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> { |
| 479 | 480 | const user = ctx.auth.user; |
| 480 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 481 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 481 | 482 | const form = await readForm(ctx, "admin"); |
| 482 | 483 | if (form instanceof Response) return form; |
| 483 | 484 | const names = await namedForges(ctx, form.getAll("name").filter((v): v is string => typeof v === "string")); |
| @@ -489,7 +490,7 @@ export async function forgeArchiveSubmit(ctx: Ctx): Promise<Response> { | ||
| 489 | 490 | // POST /forges/:name/restore — bring an archived forge back under its name. |
| 490 | 491 | export async function forgeRestoreSubmit(ctx: Ctx): Promise<Response> { |
| 491 | 492 | const user = ctx.auth.user; |
| 492 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 493 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 493 | 494 | const form = await readForm(ctx, "admin"); |
| 494 | 495 | if (form instanceof Response) return form; |
| 495 | 496 | const done = await restoreForge(ctx.app, ctx.params["name"] ?? "", { actorId: user.id }); |
| @@ -554,7 +555,7 @@ function receipt(ctx: Ctx, rows: readonly ClientRow[]): Html | null { | ||
| 554 | 555 | function linkChange(act: "revoke" | "undo") { |
| 555 | 556 | return async (ctx: Ctx): Promise<Response> => { |
| 556 | 557 | const user = ctx.auth.user; |
| 557 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 558 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 558 | 559 | const form = await readForm(ctx, "admin"); |
| 559 | 560 | if (form instanceof Response) return form; |
| 560 | 561 | const name = ctx.params["name"] ?? ""; |
| @@ -571,7 +572,7 @@ export const forgeLinkUndo = linkChange("undo"); | ||
| 571 | 572 | function manageSubmit(act: (app: Ctx["app"], name: string) => Promise<Managed>, title: string) { |
| 572 | 573 | return async (ctx: Ctx): Promise<Response> => { |
| 573 | 574 | const user = ctx.auth.user; |
| 574 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 575 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 575 | 576 | const form = await readForm(ctx, "admin"); |
| 576 | 577 | if (form instanceof Response) return form; |
| 577 | 578 | const done = await act(ctx.app, ctx.params["name"] ?? ""); |
| @@ -599,7 +600,7 @@ export const forgeStopSubmit = manageSubmit(stopForge, "Forge stopped"); | ||
| 599 | 600 | // own (`spawn/move_cell.ts`). |
| 600 | 601 | export async function forgeSandboxSubmit(ctx: Ctx): Promise<Response> { |
| 601 | 602 | const user = ctx.auth.user; |
| 602 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 603 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 603 | 604 | const form = await readForm(ctx, "admin"); |
| 604 | 605 | if (form instanceof Response) return form; |
| 605 | 606 | const name = ctx.params["name"] ?? ""; |
| @@ -627,7 +628,7 @@ export const forgeRemoveSubmit = manageSubmit(removeForge, "Forge removed"); | ||
| 627 | 628 | // GET /forges/:name/remove — what removing would delete, and the one button that does it. |
| 628 | 629 | export async function forgeRemoveConfirm(ctx: Ctx): Promise<Response> { |
| 629 | 630 | const user = ctx.auth.user; |
| 630 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 631 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 631 | 632 | const name = ctx.params["name"] ?? ""; |
| 632 | 633 | const child = (await listChildren(ctx.app)).find((c) => c.name === name); |
| 633 | 634 | if (child === undefined) return notFoundPage(ctx); |
| @@ -702,7 +703,7 @@ async function ownCodeSection(ctx: Ctx): Promise<Html | null> { | ||
| 702 | 703 | // with a receipt. |
| 703 | 704 | export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> { |
| 704 | 705 | const user = ctx.auth.user; |
| 705 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 706 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 706 | 707 | const form = await readForm(ctx, "admin"); |
| 707 | 708 | if (form instanceof Response) return form; |
| 708 | 709 | const want = form.get("on"); |
| @@ -716,7 +717,7 @@ export async function forgeOwnCodeSubmit(ctx: Ctx): Promise<Response> { | ||
| 716 | 717 | // POST /forges/:name/size — raise a forge to a larger size (xlarge); a receipt on the list. |
| 717 | 718 | export async function forgeSizeSubmit(ctx: Ctx): Promise<Response> { |
| 718 | 719 | const user = ctx.auth.user; |
| 719 | if (!user?.isAdmin) return notFoundPage(ctx); | |
| 720 | if (user === undefined || !adminPage(ctx, "forges", user.isAdmin)) return notFoundPage(ctx); | |
| 720 | 721 | const form = await readForm(ctx, "admin"); |
| 721 | 722 | if (form instanceof Response) return form; |
| 722 | 723 | const name = ctx.params["name"] ?? ""; |
src/web/pages/games.ts +5 −4
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * the box's compose repository, so a merge redeploys and the crew can propose them too. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import { cancelHeld, heldOf, holdUntilQuiet, QUIET_MINUTES } from "../../games/when_quiet.ts"; |
| 11 | 12 | import { addPluginUrl, commitServiceEnv, composeServices, readCompose, serviceEnv } from "../../games/compose.ts"; |
| 12 | 13 | import { verdictsOf } from "../../games/set_verdict.ts"; |
| @@ -165,7 +166,7 @@ export async function gameServersSubmit(ctx: Ctx): Promise<Response> { | ||
| 165 | 166 | } |
| 166 | 167 | |
| 167 | 168 | export function boxOf(ctx: Ctx, need: Role, service = ""): { box: GameBox; role: Role } | Response { |
| 168 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 169 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 169 | 170 | const box = boxNamed(ctx.app.db, ctx.params.box ?? ""); |
| 170 | 171 | if (box === undefined || !seesBox(ctx.app.db, ctx.auth.user, box.id)) return notFoundPage(ctx); |
| 171 | 172 | const role = roleOn(ctx.app.db, ctx.auth.user, box.id, service); |
| @@ -184,7 +185,7 @@ const startBox = (): Html => html`<form method="post" action="/talk" class="mt"> | ||
| 184 | 185 | // GET /games |
| 185 | 186 | export function gamesPage(ctx: Ctx): Response { |
| 186 | 187 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 187 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 188 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 188 | 189 | const user = ctx.auth.user; |
| 189 | 190 | const boxes = listBoxes(ctx.app.db).filter((b) => seesBox(ctx.app.db, user, b.id)); |
| 190 | 191 | return timePhase(ctx.request, "render", () => page({ |
| @@ -212,7 +213,7 @@ export function gamesPage(ctx: Ctx): Response { | ||
| 212 | 213 | // POST /settings/minecraft/code: a one-time code (ten minutes) the person types in game as !forge |
| 213 | 214 | // link <code>. |
| 214 | 215 | export async function gameLinkCode(ctx: Ctx): Promise<Response> { |
| 215 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 216 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 216 | 217 | const form = await readForm(ctx, "rw"); |
| 217 | 218 | if (form instanceof Response) return form; |
| 218 | 219 | const code = newLinkCode(ctx.app, ctx.auth.user); |
| @@ -222,7 +223,7 @@ export async function gameLinkCode(ctx: Ctx): Promise<Response> { | ||
| 222 | 223 | |
| 223 | 224 | // POST /settings/minecraft/unlink: forget one of the person's linked names. |
| 224 | 225 | export async function gameLinkRemove(ctx: Ctx): Promise<Response> { |
| 225 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 226 | if (!signedInPage(ctx, "games")) return signInFirst(ctx); | |
| 226 | 227 | const form = await readForm(ctx, "rw"); |
| 227 | 228 | if (form instanceof Response) return form; |
| 228 | 229 | unlink(ctx.app, ctx.auth.user.id, field(form, "box"), field(form, "player")); |
src/web/pages/gate.ts +3 −2
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * acting is `actions/gate.ts`. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { signedInPage } from "../../http/page_may.ts"; | |
| 7 | 8 | import { applyGateReview, reviewGate } from "../../actions/gate_review.ts"; |
| 8 | 9 | import { liftHold } from "../../actions/gate.ts"; |
| 9 | 10 | import { BAD_DATE, REVIVE_UNTIL } from "../../core/gate_snooze.ts"; |
| @@ -71,7 +72,7 @@ export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null { | ||
| 71 | 72 | export async function liftHoldSubmit(ctx: Ctx): Promise<Response> { |
| 72 | 73 | const found = threadContext(ctx, "issue"); |
| 73 | 74 | if (found instanceof Response) return found; |
| 74 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 75 | if (!signedInPage(ctx, "gate")) return signInFirst(ctx); | |
| 75 | 76 | const form = await readForm(ctx, "rw"); |
| 76 | 77 | if (form instanceof Response) return form; |
| 77 | 78 | const repo = loadRepo(ctx) ?? found.repo; |
| @@ -222,7 +223,7 @@ export function heldPage(ctx: Ctx): Response { | ||
| 222 | 223 | export async function heldApply(ctx: Ctx): Promise<Response> { |
| 223 | 224 | const repo = loadRepo(ctx); |
| 224 | 225 | if (!repo) return notFoundPage(ctx); |
| 225 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 226 | if (!signedInPage(ctx, "gate")) return signInFirst(ctx); | |
| 226 | 227 | const form = await readForm(ctx, "rw"); |
| 227 | 228 | if (form instanceof Response) return form; |
| 228 | 229 | const dest = `${repoBase(repo)}/held`; |
src/web/pages/gifts.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * who is not a subscriber sees no block, and the POST answers not found. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { GIFT_WORDS, giveGift, readGifts } from "../../actions/gifts.ts"; |
| 9 | 10 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| @@ -51,7 +52,7 @@ export function giftsBlock(ctx: Ctx, shown?: Shown, refusal?: string): Html | nu | ||
| 51 | 52 | |
| 52 | 53 | // POST /settings/gifts |
| 53 | 54 | export async function giftMake(ctx: Ctx): Promise<Response> { |
| 54 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 55 | if (!signedInPage(ctx, "gifts")) return signInFirst(ctx); | |
| 55 | 56 | const form = await readForm(ctx); |
| 56 | 57 | if (form instanceof Response) return form; |
| 57 | 58 | const made = giveGift(ctx.app, ctx.auth.user, publicOrigin(ctx.app.config.url, ctx.url.origin)); |
src/web/pages/grants.ts +3 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * rows and the gate are `actions/oauth_grants.ts`, which the terminal's |
| 8 | 8 | * `screens/oauthgrants.ts` shares. |
| 9 | 9 | */ |
| 10 | import { signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import { myOAuthGrants, myReusedGrants, revokeOAuthGrant, revokedWords } from "../../actions/oauth_grants.ts"; |
| 11 | 12 | import { emptyNote } from "../empty_words.ts"; |
| 12 | 13 | import type { OAuthGrant, ReusedGrant } from "../../core/oauth_grants.ts"; |
| @@ -75,7 +76,7 @@ function grantsView(grants: readonly OAuthGrant[], reused: readonly ReusedGrant[ | ||
| 75 | 76 | |
| 76 | 77 | // GET /settings/grants |
| 77 | 78 | export function grantsPage(ctx: Ctx): Response { |
| 78 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 79 | if (!signedInPage(ctx, "grants")) return signInFirst(ctx); | |
| 79 | 80 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 80 | 81 | const grants = timePhase(ctx.request, "grants", () => myOAuthGrants(ctx.app, ctx.auth.user)); |
| 81 | 82 | const reused = myReusedGrants(ctx.app, ctx.auth.user); |
| @@ -86,7 +87,7 @@ export function grantsPage(ctx: Ctx): Response { | ||
| 86 | 87 | |
| 87 | 88 | // POST /settings/grants/:id/revoke |
| 88 | 89 | export async function grantRevoke(ctx: Ctx): Promise<Response> { |
| 89 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 90 | if (!signedInPage(ctx, "grants")) return signInFirst(ctx); | |
| 90 | 91 | const form = await readForm(ctx, "admin"); |
| 91 | 92 | if (form instanceof Response) return form; |
| 92 | 93 | const revoked = revokeOAuthGrant(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
src/web/pages/hosted-forges.ts +3 −2
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | * `REACH_SETTINGS`, the section's own anchor. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | import { sshOn } from "../../settings/ssh.ts"; |
| 15 | 16 | import { |
| 16 | 17 | allowReach, |
| @@ -119,8 +120,8 @@ export function forgeReachRows( | ||
| 119 | 120 | } |
| 120 | 121 | |
| 121 | 122 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 122 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 123 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 123 | if (!signedInPage(ctx, "hosted-forges")) return signInFirst(ctx); | |
| 124 | if (!adminPage(ctx, "hosted-forges", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 124 | 125 | return undefined; |
| 125 | 126 | } |
| 126 | 127 |
src/web/pages/identities.ts +3 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * for a tick first: removing it puts the account back behind the email gate. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import { sshOn } from "../../settings/ssh.ts"; |
| 11 | 12 | import { |
| 12 | 13 | CONNECTION_WORDS, MINECRAFT_PROOF, NOT_RETROACTIVE, SIGN_IN_ADDRESS, addConnection, addMinecraftConnection, chooseUse, |
| @@ -66,7 +67,7 @@ const card = (c: Connection): Html => { | ||
| 66 | 67 | // GET /settings/identities |
| 67 | 68 | export function identitiesPage(ctx: Ctx): Response { |
| 68 | 69 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 69 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 70 | if (!signedInPage(ctx, "identities")) return signInFirst(ctx); | |
| 70 | 71 | const list = connectionsOf(ctx.app, ctx.auth.user); |
| 71 | 72 | const body = html`<section class="settings-block"> |
| 72 | 73 | <h2>Proven identities</h2> |
| @@ -99,7 +100,7 @@ const said = (ctx: Ctx, message: string, ok: boolean): Response => | ||
| 99 | 100 | |
| 100 | 101 | /** Read the form as the signed-in account, same-origin; the acts below share it. */ |
| 101 | 102 | async function acting(ctx: Ctx): Promise<{ form: import("../form.ts").Form } | Response> { |
| 102 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 103 | if (!signedInPage(ctx, "identities")) return signInFirst(ctx); | |
| 103 | 104 | const form = await readForm(ctx, "admin"); |
| 104 | 105 | return form instanceof Response ? form : { form }; |
| 105 | 106 | } |
src/web/pages/inventory.ts +2 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * The rows are `actions/inventory.ts`'s, the same the MCP answers. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { holds, inventoryOfOrigins, moveRoom, type InventoryItem } from "../../actions/inventory.ts"; |
| 10 | 11 | import { listUserOrigins } from "../../actions/origins.ts"; |
| 11 | 12 | import { MIGRATION_STATES, STATE_WORDS, type MigrationState } from "../../origins/inventory.ts"; |
| @@ -62,7 +63,7 @@ function tally(items: readonly InventoryItem[]): string { | ||
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | export async function inventoryPage(ctx: Ctx): Promise<Response> { |
| 65 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 66 | if (!signedInPage(ctx, "inventory")) return signInFirst(ctx); | |
| 66 | 67 | const user = ctx.auth.user; |
| 67 | 68 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 68 | 69 | const origins = listUserOrigins(ctx.app, user); |
src/web/pages/issues.ts +6 −5
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * Mobile-first, no JavaScript required. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { originError } from "../../actions/merge_words.ts"; |
| 9 | 10 | import { comeBack } from "../come_back.ts"; |
| 10 | 11 | import { CEILING_REFUSAL, PAUSE_REFUSAL } from "../../core/planner_pause.ts"; |
| @@ -249,7 +250,7 @@ export function newIssueAnywhere(ctx: Ctx): Response { | ||
| 249 | 250 | export async function newIssueSubmit(ctx: Ctx): Promise<Response> { |
| 250 | 251 | const repo = loadRepo(ctx); |
| 251 | 252 | if (!repo) return notFoundPage(ctx); |
| 252 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 253 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 253 | 254 | const form = await readForm(ctx, "rw"); |
| 254 | 255 | if (form instanceof Response) return form; |
| 255 | 256 | |
| @@ -297,7 +298,7 @@ export function issueThreadFragment(ctx: Ctx): Response { | ||
| 297 | 298 | export async function issueSealSubmit(ctx: Ctx): Promise<Response> { |
| 298 | 299 | const found = threadContext(ctx, "issue"); |
| 299 | 300 | if (found instanceof Response) return found; |
| 300 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 301 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 301 | 302 | const form = await readForm(ctx, "rw"); |
| 302 | 303 | if (form instanceof Response) return form; |
| 303 | 304 | const sealed = field(form, "sealed") === "1"; |
| @@ -322,7 +323,7 @@ export async function issueSealSubmit(ctx: Ctx): Promise<Response> { | ||
| 322 | 323 | export async function issuePrivateSubmit(ctx: Ctx): Promise<Response> { |
| 323 | 324 | const found = threadContext(ctx, "issue"); |
| 324 | 325 | if (found instanceof Response) return found; |
| 325 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 326 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 326 | 327 | const form = await readForm(ctx, "rw"); |
| 327 | 328 | if (form instanceof Response) return form; |
| 328 | 329 | const made = await privateRepoForSealed(ctx.app, ctx.auth.user, found.repo, found.issue); |
| @@ -356,7 +357,7 @@ const BACK = new Map<string, { to: string; said: (n: number) => string }>([ | ||
| 356 | 357 | export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { |
| 357 | 358 | const found = threadContext(ctx, "issue"); |
| 358 | 359 | if (found instanceof Response) return found; |
| 359 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 360 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 360 | 361 | const form = await readForm(ctx, "rw"); |
| 361 | 362 | if (form instanceof Response) return form; |
| 362 | 363 | |
| @@ -413,7 +414,7 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 413 | 414 | export async function issueQuestionSubmit(ctx: Ctx): Promise<Response> { |
| 414 | 415 | const found = threadContext(ctx, "issue"); |
| 415 | 416 | if (found instanceof Response) return found; |
| 416 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 417 | if (!signedInPage(ctx, "issues")) return signInFirst(ctx); | |
| 417 | 418 | const form = await readForm(ctx, "rw"); |
| 418 | 419 | if (form instanceof Response) return form; |
| 419 | 420 | const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`; |
src/web/pages/iterations.ts +2 −1
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | * selections) are not on this forge yet. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | import { signedInPage } from "../../http/page_may.ts"; | |
| 16 | 17 | import { notePin } from "../../actions/builds.ts"; |
| 17 | 18 | import { iterationsOf, lanesOf, type IterationBuild, type IterationFork, type IterationLane } from "../../core/iterations.ts"; |
| 18 | 19 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| @@ -583,7 +584,7 @@ const NOTE_ERRORS: Record<string, string> = { | ||
| 583 | 584 | export async function noteSubmit(ctx: Ctx): Promise<Response> { |
| 584 | 585 | const repo = loadRepo(ctx); |
| 585 | 586 | if (!repo) return notFoundPage(ctx); |
| 586 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 587 | if (!signedInPage(ctx, "iterations")) return signInFirst(ctx); | |
| 587 | 588 | const form = await readForm(ctx, "rw"); |
| 588 | 589 | if (form instanceof Response) return form; |
| 589 | 590 | const to = backTo(form, `${repoBase(repo)}/iterations`); |
src/web/pages/knobs.ts +3 −2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * leaves the event the setting's own page leaves. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { setKnob } from "../../actions/knobs.ts"; |
| 9 | 10 | import { derivedLine, readKnobs, type KnobRow } from "../../crew/knobs.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| @@ -50,8 +51,8 @@ export function knobsCard(ctx: Ctx): Html { | ||
| 50 | 51 | |
| 51 | 52 | // POST /settings/crew/knobs |
| 52 | 53 | export async function knobSet(ctx: Ctx): Promise<Response> { |
| 53 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 54 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 54 | if (!signedInPage(ctx, "knobs")) return signInFirst(ctx); | |
| 55 | if (!adminPage(ctx, "knobs", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 55 | 56 | const form = await readForm(ctx, "admin"); |
| 56 | 57 | if (form instanceof Response) return form; |
| 57 | 58 | const knob = field(form, "knob"); |
src/web/pages/limb.ts +4 −3
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * take it back once. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { isReplanAction } from "../../actions/limb_replan.ts"; |
| 10 | 11 | import { getFleetOp, undoFleetOp } from "../../actions/fleet.ts"; |
| 11 | 12 | import { |
| @@ -152,7 +153,7 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 152 | 153 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 153 | 154 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); |
| 154 | 155 | if (!repo) return notFoundPage(ctx); |
| 155 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 156 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 156 | 157 | const number = Number(ctx.params.number); |
| 157 | 158 | const action = ctx.url.searchParams.get("action"); |
| 158 | 159 | if (action === "replan") return replanPreviewPage(ctx, repo, number); |
| @@ -349,7 +350,7 @@ export function limbPreviewPage(ctx: Ctx): Response { | ||
| 349 | 350 | export async function limbSubmit(ctx: Ctx): Promise<Response> { |
| 350 | 351 | const repo = loadRepo(ctx); |
| 351 | 352 | if (!repo) return notFoundPage(ctx); |
| 352 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 353 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 353 | 354 | const form = await readForm(ctx, "admin"); |
| 354 | 355 | if (form instanceof Response) return form; |
| 355 | 356 | const number = Number(ctx.params.number); |
| @@ -439,7 +440,7 @@ export function limbReceiptPage(ctx: Ctx): Response { | ||
| 439 | 440 | export async function limbUndo(ctx: Ctx): Promise<Response> { |
| 440 | 441 | const repo = loadRepo(ctx); |
| 441 | 442 | if (!repo) return notFoundPage(ctx); |
| 442 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 443 | if (!signedInPage(ctx, "limb")) return signInFirst(ctx); | |
| 443 | 444 | const form = await readForm(ctx, "admin"); |
| 444 | 445 | if (form instanceof Response) return form; |
| 445 | 446 | const number = Number(ctx.params.number); |
src/web/pages/maintenance.ts +7 −6
| @@ -4,6 +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 | 8 | import { json } from "../../http/respond.ts"; |
| 8 | 9 | import { emptyNote } from "../empty_words.ts"; |
| 9 | 10 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -41,8 +42,8 @@ import { diskLine } from "../../maintenance/disk_line.ts"; | ||
| 41 | 42 | import { readDisk } from "../../kernel/disk_reading.ts"; |
| 42 | 43 | |
| 43 | 44 | function admin(ctx: Ctx): Response | undefined { |
| 44 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 45 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 45 | if (!signedInPage(ctx, "maintenance")) return signInFirst(ctx); | |
| 46 | if (!adminPage(ctx, "maintenance", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 46 | 47 | return undefined; |
| 47 | 48 | } |
| 48 | 49 | |
| @@ -343,7 +344,7 @@ function quietedRows(withActions: boolean, rows: readonly Quieted[]): Html { | ||
| 343 | 344 | function mayQuiet(ctx: Ctx): Response | undefined { |
| 344 | 345 | const user = ctx.auth.user; |
| 345 | 346 | if (user === undefined) return signInFirst(ctx); |
| 346 | if (!user.isAdmin) return notFoundPage(ctx); | |
| 347 | if (!adminPage(ctx, "maintenance", user.isAdmin)) return notFoundPage(ctx); | |
| 347 | 348 | if (user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a person may quiet a finding." }); |
| 348 | 349 | return undefined; |
| 349 | 350 | } |
| @@ -409,7 +410,7 @@ export function stalePullsSection(ctx: Ctx, withActions: boolean): Html { | ||
| 409 | 410 | */ |
| 410 | 411 | export async function staleAction(ctx: Ctx): Promise<Response> { |
| 411 | 412 | const user = ctx.auth.user; |
| 412 | if (user === undefined || !user.isAdmin || user.kind === "agent") | |
| 413 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 413 | 414 | return flashTo(ctx, "/maintenance", { tone: "danger", message: STALE_WORDS.forbidden }); |
| 414 | 415 | const form = await readForm(ctx, "admin"); |
| 415 | 416 | if (form instanceof Response) return form; |
| @@ -441,7 +442,7 @@ function mergedRows(withActions: boolean, found: readonly MergedBranch[]): Html | ||
| 441 | 442 | */ |
| 442 | 443 | export async function mergedAction(ctx: Ctx): Promise<Response> { |
| 443 | 444 | const user = ctx.auth.user; |
| 444 | if (user === undefined || !user.isAdmin || user.kind === "agent") | |
| 445 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 445 | 446 | return flashTo(ctx, "/maintenance", { tone: "danger", message: MERGED_WORDS.forbidden }); |
| 446 | 447 | const form = await readForm(ctx, "admin"); |
| 447 | 448 | if (form instanceof Response) return form; |
| @@ -474,7 +475,7 @@ function previewRows(withActions: boolean, found: readonly PreviewDir[]): Html { | ||
| 474 | 475 | */ |
| 475 | 476 | export async function previewAction(ctx: Ctx): Promise<Response> { |
| 476 | 477 | const user = ctx.auth.user; |
| 477 | if (user === undefined || !user.isAdmin || user.kind === "agent") | |
| 478 | if (!adminPage(ctx, "maintenance", user !== undefined && user.isAdmin && user.kind !== "agent")) | |
| 478 | 479 | return flashTo(ctx, "/maintenance", { tone: "danger", message: PREVIEW_WORDS.forbidden }); |
| 479 | 480 | const form = await readForm(ctx, "admin"); |
| 480 | 481 | if (form instanceof Response) return form; |
src/web/pages/migrate.ts +4 −3
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | * Every mutation is `migrateRepo`; the page only puts its answer into words. |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | import { signedInPage } from "../../http/page_may.ts"; | |
| 23 | 24 | import { USERNAME_PATTERN } from "../username_pattern.ts"; |
| 24 | 25 | import { repositoryLimitMessage } from "../../actions/repos.ts"; |
| 25 | 26 | import { listAllAgents } from "../../actions/crew.ts"; |
| @@ -709,7 +710,7 @@ async function show( | ||
| 709 | 710 | // GET /migrate |
| 710 | 711 | export async function migratePage(ctx: Ctx): Promise<Response> { |
| 711 | 712 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 712 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 713 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 713 | 714 | const q = ctx.url.searchParams; |
| 714 | 715 | const origins = await timePhaseAsync(ctx.request, "origins", () => |
| 715 | 716 | originChoices(ctx), |
| @@ -758,7 +759,7 @@ export async function migratePage(ctx: Ctx): Promise<Response> { | ||
| 758 | 759 | |
| 759 | 760 | // POST /migrate |
| 760 | 761 | export async function migrateSubmit(ctx: Ctx): Promise<Response> { |
| 761 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 762 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 762 | 763 | const form = await readForm(ctx, "rw"); |
| 763 | 764 | if (form instanceof Response) return form; |
| 764 | 765 | const values: MigrateValues = { |
| @@ -943,7 +944,7 @@ const migrateJobJs = /* js */ ` | ||
| 943 | 944 | |
| 944 | 945 | export function migrationJobPage(ctx: Ctx): Response { |
| 945 | 946 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 946 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 947 | if (!signedInPage(ctx, "migrate")) return signInFirst(ctx); | |
| 947 | 948 | const user = ctx.auth.user; |
| 948 | 949 | const found = timePhase(ctx.request, "job", () => |
| 949 | 950 | migrationJobFor(user, ctx.params.job ?? ""), |
src/web/pages/milestones.ts +2 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * Read-only: the page, the API and the MCP tool give the same numbers. |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { signedInPage } from "../../http/page_may.ts"; | |
| 13 | 14 | import { issueCounts } from "../../core/milestone_front.ts"; |
| 14 | 15 | import { |
| 15 | 16 | limbJson, |
| @@ -696,7 +697,7 @@ export async function milestonePage( | ||
| 696 | 697 | export async function milestoneWatch(ctx: Ctx): Promise<Response> { |
| 697 | 698 | const repo = loadRepo(ctx); |
| 698 | 699 | if (!repo) return notFoundPage(ctx); |
| 699 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 700 | if (!signedInPage(ctx, "milestones")) return signInFirst(ctx); | |
| 700 | 701 | const form = await readForm(ctx, "rw"); |
| 701 | 702 | if (form instanceof Response) return form; |
| 702 | 703 | const number = Number(ctx.params.number); |
src/web/pages/model.ts +5 −4
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * card). A token is typed once and never shown again. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { blockedWay } from "../blocked.ts"; |
| 11 | 12 | import { noBudgetBlocked } from "../../actions/blocked_words.ts"; |
| @@ -152,8 +153,8 @@ export function grantCard(ctx: Ctx, user: User, at: string): Html { | ||
| 152 | 153 | |
| 153 | 154 | // POST /settings/accounts/:username/model |
| 154 | 155 | export async function grantAct(ctx: Ctx): Promise<Response> { |
| 155 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 156 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 156 | if (!signedInPage(ctx, "model")) return signInFirst(ctx); | |
| 157 | if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 157 | 158 | const form = await readForm(ctx, "admin"); |
| 158 | 159 | if (form instanceof Response) return form; |
| 159 | 160 | const username = ctx.params.username ?? ""; |
| @@ -181,8 +182,8 @@ export async function grantAct(ctx: Ctx): Promise<Response> { | ||
| 181 | 182 | |
| 182 | 183 | // POST /settings/accounts/:username/ceiling |
| 183 | 184 | export async function ceilingAct(ctx: Ctx): Promise<Response> { |
| 184 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 185 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 185 | if (!signedInPage(ctx, "model")) return signInFirst(ctx); | |
| 186 | if (!adminPage(ctx, "model", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 186 | 187 | const form = await readForm(ctx, "admin"); |
| 187 | 188 | if (form instanceof Response) return form; |
| 188 | 189 | const username = ctx.params.username ?? ""; |
src/web/pages/next.ts +2 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * phone need no script; a row can also be dragged, or moved by the key shown |
| 7 | 7 | * beside each action (`j`/`k` choose the row), which post the same form. |
| 8 | 8 | */ |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { keyStep } from "./next_keys.ts"; |
| 10 | 11 | import { keyOf, oldKeys } from "../keymap.ts"; |
| 11 | 12 | import { DEFAULT_DECLINE, decideOffer, decideOutsider, decisionOf, outsiderShelf } from "../../actions/outsider_decision.ts"; |
| @@ -376,7 +377,7 @@ export function nextPage(ctx: Ctx): Response { | ||
| 376 | 377 | export async function nextSubmit(ctx: Ctx): Promise<Response> { |
| 377 | 378 | const repo: Repo | undefined = loadRepo(ctx); |
| 378 | 379 | if (!repo) return notFoundPage(ctx); |
| 379 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 380 | if (!signedInPage(ctx, "next")) return signInFirst(ctx); | |
| 380 | 381 | const form = await readForm(ctx, "rw"); |
| 381 | 382 | if (form instanceof Response) return form; |
| 382 | 383 | const dest = backTo(form, `${repoBase(repo)}/next`); |
src/web/pages/next_batch.ts +2 −1
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * needed; the POST lands back on the page with `?undo=` naming the rows, and |
| 5 | 5 | * the page offers Undo only for rows still inside their minute. |
| 6 | 6 | */ |
| 7 | import { signedInPage } from "../../http/page_may.ts"; | |
| 7 | 8 | import { batchWords, BATCH_MAX, numbersOf, snoozeMany, undoable, undoMany, UNDO_MS } from "../../actions/next.ts"; |
| 8 | 9 | import type { Ctx } from "../../http/context.ts"; |
| 9 | 10 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| @@ -55,7 +56,7 @@ export function batchButtons(live: readonly number[]): Html { | ||
| 55 | 56 | export async function nextBatch(ctx: Ctx): Promise<Response> { |
| 56 | 57 | const repo = loadRepo(ctx); |
| 57 | 58 | if (!repo) return notFoundPage(ctx); |
| 58 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 59 | if (!signedInPage(ctx, "next_batch")) return signInFirst(ctx); | |
| 59 | 60 | const form = await readForm(ctx, "rw"); |
| 60 | 61 | if (form instanceof Response) return form; |
| 61 | 62 | const dest = backTo(form, `${repoBase(repo)}/next`); |
src/web/pages/offer-receipt.ts +2 −1
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | * where it stands, in the words the MCP `offer` tool returns (`core/fork_offer.ts`). Only the |
| 4 | 4 | * offerer and the upstream's writers read it; anyone else sees the page of an id never given. |
| 5 | 5 | */ |
| 6 | import { signedInPage } from "../../http/page_may.ts"; | |
| 6 | 7 | import { offerDay, readForkOffer } from "../../core/fork_offer.ts"; |
| 7 | 8 | import { getRepo } from "../../core/repos.ts"; |
| 8 | 9 | import type { Ctx } from "../../http/context.ts"; |
| @@ -11,7 +12,7 @@ import { html } from "../html.ts"; | ||
| 11 | 12 | import { page } from "../layout.ts"; |
| 12 | 13 | |
| 13 | 14 | export function offerReceiptPage(ctx: Ctx): Response { |
| 14 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 15 | if (!signedInPage(ctx, "offer-receipt")) return signInFirst(ctx); | |
| 15 | 16 | const r = readForkOffer(ctx.app.db, ctx.auth.user, ctx.params.id ?? ""); |
| 16 | 17 | if (r === undefined) return notFoundPage(ctx); |
| 17 | 18 | const [owner = "", name = ""] = r.upstream.split("/"); |
src/web/pages/offer-upstream.ts +4 −3
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * `upstreamOffer`'s, shared with the terminal; no git here. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { OFFER_COMMIT_WORDS, offerCommit } from "../../actions/offer_commit.ts"; |
| 10 | 11 | import { OFFER_PULL_WORDS, offerPull, previewOfferPull } from "../../actions/offer_pull.ts"; |
| 11 | 12 | import { OFFER_WITHDRAW_WORDS, withdrawOffer } from "../../actions/offer_withdraw.ts"; |
| @@ -62,7 +63,7 @@ export function offerCommitButton( | ||
| 62 | 63 | export async function offerCommitPost(ctx: Ctx): Promise<Response> { |
| 63 | 64 | const repo = loadRepo(ctx); |
| 64 | 65 | if (!repo) return notFoundPage(ctx); |
| 65 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 66 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 66 | 67 | const form = await readForm(ctx, "rw"); |
| 67 | 68 | if (form instanceof Response) return form; |
| 68 | 69 | const rev = ctx.params.oid ?? ""; |
| @@ -87,7 +88,7 @@ export async function offerCommitPost(ctx: Ctx): Promise<Response> { | ||
| 87 | 88 | export async function offerWithdrawPost(ctx: Ctx): Promise<Response> { |
| 88 | 89 | const fork = loadRepo(ctx); |
| 89 | 90 | if (!fork) return notFoundPage(ctx); |
| 90 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 91 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 91 | 92 | const form = await readForm(ctx, "rw"); |
| 92 | 93 | if (form instanceof Response) return form; |
| 93 | 94 | const number = Number(ctx.params.number); |
| @@ -127,7 +128,7 @@ export function offerPullCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null { | ||
| 127 | 128 | export async function offerPullPost(ctx: Ctx): Promise<Response> { |
| 128 | 129 | const repo = loadRepo(ctx); |
| 129 | 130 | if (!repo) return notFoundPage(ctx); |
| 130 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 131 | if (!signedInPage(ctx, "offer-upstream")) return signInFirst(ctx); | |
| 131 | 132 | const form = await readForm(ctx, "rw"); |
| 132 | 133 | if (form instanceof Response) return form; |
| 133 | 134 | const number = Number(ctx.params.number); |
src/web/pages/org.ts +3 −2
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * unknown username now says so. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | import { USERNAME_PATTERN } from "../username_pattern.ts"; |
| 13 | 14 | import { emptyNote } from "../empty_words.ts"; |
| 14 | 15 | import { |
| @@ -496,7 +497,7 @@ function orgSecrets(ctx: Ctx, name: string): Html | null { | ||
| 496 | 497 | // POST /:owner/-/subscriptions |
| 497 | 498 | export async function orgSubscriptionsSave(ctx: Ctx): Promise<Response> { |
| 498 | 499 | const org = requireOrgAdmin(ctx); |
| 499 | if (!org || ctx.auth.user?.isAdmin !== true) return notFoundPage(ctx); | |
| 500 | if (!org || ctx.auth.user === undefined || !adminPage(ctx, "org", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 500 | 501 | const form = await readForm(ctx, "admin"); |
| 501 | 502 | if (form instanceof Response) return form; |
| 502 | 503 | saveGrants(ctx, form, org.id, agentsOnForge(ctx)); |
| @@ -551,7 +552,7 @@ export function newOrgPage(ctx: Ctx): Response { | ||
| 551 | 552 | |
| 552 | 553 | // POST /organizations/new |
| 553 | 554 | export async function newOrgSubmit(ctx: Ctx): Promise<Response> { |
| 554 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 555 | if (!signedInPage(ctx, "org")) return signInFirst(ctx); | |
| 555 | 556 | const form = await readForm(ctx, "rw"); |
| 556 | 557 | if (form instanceof Response) return form; |
| 557 | 558 | const name = field(form, "name"); |
src/web/pages/origin-reach.ts +3 −2
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | * same. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | import { signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | import { |
| 15 | 16 | ASK_ERROR_WORDS, |
| 16 | 17 | askHost, |
| @@ -182,7 +183,7 @@ export const reachJs = /* js */ ` | ||
| 182 | 183 | |
| 183 | 184 | // POST /settings/origins/reach — the button: ask the host to allow `host`. |
| 184 | 185 | export async function originReachAsk(ctx: Ctx): Promise<Response> { |
| 185 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 186 | if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx); | |
| 186 | 187 | const form = await readForm(ctx, "rw"); |
| 187 | 188 | if (form instanceof Response) return form; |
| 188 | 189 | const host = field(form, "host").trim(); |
| @@ -208,7 +209,7 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> { | ||
| 208 | 209 | |
| 209 | 210 | // POST /settings/origins/reach/dismiss — take one's own answered ask off the page. |
| 210 | 211 | export async function originReachDismiss(ctx: Ctx): Promise<Response> { |
| 211 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 212 | if (!signedInPage(ctx, "origin-reach")) return signInFirst(ctx); | |
| 212 | 213 | const form = await readForm(ctx, "rw"); |
| 213 | 214 | if (form instanceof Response) return form; |
| 214 | 215 | dismissAsk(ctx.app, ctx.auth.user, field(form, "host")); |
src/web/pages/origins.ts +2 −1
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | * where it was — that page and its poll live in `origin-flow.ts`. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | import { signedInPage } from "../../http/page_may.ts"; | |
| 20 | 21 | import { originIcon } from "../origin_icon.ts"; |
| 21 | 22 | import { sshOn } from "../../settings/ssh.ts"; |
| 22 | 23 | import type { Database } from "bun:sqlite"; |
| @@ -247,7 +248,7 @@ export const callbackUri = (ctx: Ctx): string => | ||
| 247 | 248 | * enumerate whose GitHub is connected, let alone spend it. |
| 248 | 249 | */ |
| 249 | 250 | export function accountOnly(ctx: Ctx): Response | undefined { |
| 250 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 251 | if (!signedInPage(ctx, "origins")) return signInFirst(ctx); | |
| 251 | 252 | if (ctx.auth.via === "session" || ctx.auth.via === "password") |
| 252 | 253 | return undefined; |
| 253 | 254 | if (ctx.auth.scope === "admin") return undefined; |
src/web/pages/packs-settings.ts +3 −2
| @@ -6,6 +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 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 11 | 12 | import { refreshCatalogQuietly } from "../../packs/catalog.ts"; |
| @@ -20,8 +21,8 @@ import { btn, field as uiField, row } from "../ui.ts"; | ||
| 20 | 21 | import { accountSections } from "./origins.ts"; |
| 21 | 22 | |
| 22 | 23 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 23 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 24 | if (!ctx.auth.user.isAdmin || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 24 | if (!signedInPage(ctx, "packs-settings")) return signInFirst(ctx); | |
| 25 | if (!adminPage(ctx, "packs-settings", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 25 | 26 | return undefined; |
| 26 | 27 | } |
| 27 | 28 |
src/web/pages/packs.ts +2 −1
| @@ -20,6 +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 | 24 | |
| 24 | 25 | const plural = (n: number, one: string): string => `${n} ${one}${n === 1 ? "" : "s"}`; |
| 25 | 26 | |
| @@ -225,7 +226,7 @@ export async function packPage(ctx: Ctx): Promise<Response> { | ||
| 225 | 226 | |
| 226 | 227 | // POST /packs/mirror (admin) |
| 227 | 228 | export async function packsMirror(ctx: Ctx): Promise<Response> { |
| 228 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 229 | if (!adminPage(ctx, "packs", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 229 | 230 | const form = await readForm(ctx, "admin"); |
| 230 | 231 | if (form instanceof Response) return form; |
| 231 | 232 | const done = await mirrorPacks(ctx.app, ctx.auth.user); |
src/web/pages/passkeys.ts +4 −3
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * same-origin checked, and a challenge answers once. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { challenges, verifyAssertion, verifyRegistration } from "../../auth/webauthn.ts"; |
| 10 | 11 | import type { App } from "../../app.ts"; |
| 11 | 12 | import { |
| @@ -62,7 +63,7 @@ const refuse = (status: number, message: string) => | ||
| 62 | 63 | /** A signed-in browser, on a same-origin request; else the refusal to send. */ |
| 63 | 64 | function sessionOnly(ctx: Ctx): Response | undefined { |
| 64 | 65 | if (crossOrigin(ctx.request, ctx.url, ctx.app.log)) return refuse(403, CAME_FROM_ELSEWHERE); |
| 65 | if (!ctx.auth.user) return refuse(401, "Sign in first."); | |
| 66 | if (!signedInPage(ctx, "passkeys")) return refuse(401, "Sign in first."); | |
| 66 | 67 | // A browser the platform edge signed in is a signed-in browser too: adding a |
| 67 | 68 | // passkey there is how an account comes to sign in without the edge (#9432). |
| 68 | 69 | if (ctx.auth.via !== "session" && ctx.auth.via !== "edge") |
| @@ -73,7 +74,7 @@ function sessionOnly(ctx: Ctx): Response | undefined { | ||
| 73 | 74 | // GET /settings/passkeys |
| 74 | 75 | export function passkeysPage(ctx: Ctx): Response { |
| 75 | 76 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 76 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 77 | if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx); | |
| 77 | 78 | const user = ctx.auth.user; |
| 78 | 79 | const keys = timePhase(ctx.request, "passkeys", () => listPasskeys(ctx.app.db, user.id)); |
| 79 | 80 | const rendering = performance.now(); |
| @@ -164,7 +165,7 @@ export async function passkeyAdd(ctx: Ctx): Promise<Response> { | ||
| 164 | 165 | |
| 165 | 166 | // POST /settings/passkeys/:id/delete |
| 166 | 167 | export async function passkeyDelete(ctx: Ctx): Promise<Response> { |
| 167 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 168 | if (!signedInPage(ctx, "passkeys")) return signInFirst(ctx); | |
| 168 | 169 | const form = await readForm(ctx, "admin"); |
| 169 | 170 | if (form instanceof Response) return form; |
| 170 | 171 | const gone = removeOwnPasskey(ctx.app, ctx.auth.user, ctx.params.id ?? ""); |
src/web/pages/people.ts +5 −4
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * username wraps anywhere, so the page never scrolls sideways (#9374). |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 13 | 14 | import { sshOn } from "../../settings/ssh.ts"; |
| 14 | 15 | import { setRole } from "../../actions/roles.ts"; |
| 15 | 16 | import { GRANT_MAX_USD } from "../../core/model_grant.ts"; |
| @@ -45,8 +46,8 @@ export function appsMade(ctx: Ctx): Map<string, string[]> { | ||
| 45 | 46 | |
| 46 | 47 | // GET /settings/people |
| 47 | 48 | export function peoplePage(ctx: Ctx): Response { |
| 48 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 49 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 49 | if (!signedInPage(ctx, "people")) return signInFirst(ctx); | |
| 50 | if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 50 | 51 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 51 | 52 | const only = wordFilter(ctx.url.searchParams.get("role")); |
| 52 | 53 | const rows = timePhase(ctx.request, "people", () => peopleByActivity(ctx.app.db, only)); |
| @@ -125,8 +126,8 @@ export function peoplePage(ctx: Ctx): Response { | ||
| 125 | 126 | |
| 126 | 127 | // POST /settings/people/:username/role |
| 127 | 128 | export async function roleAct(ctx: Ctx): Promise<Response> { |
| 128 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 129 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 129 | if (!signedInPage(ctx, "people")) return signInFirst(ctx); | |
| 130 | if (!adminPage(ctx, "people", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 130 | 131 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 131 | 132 | const form = await readForm(ctx, "admin"); |
| 132 | 133 | if (form instanceof Response) return form; |
src/web/pages/proven_identities.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * Minecraft name by a code typed in game (#17284), shown where the forge has a game box, and |
| 6 | 6 | * unlinked here. The terminal says the same in Your profile (`tui/screens/profile.ts`). |
| 7 | 7 | */ |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { listOf, NO_EMAIL_TO_REMOVE, REMOVED_EMAIL, removeEmail, typeBackEmail, type Identity } from "../../core/proven_identities.ts"; |
| 9 | 10 | import { isStandInEmail } from "../../core/users.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| @@ -55,7 +56,7 @@ export function identitiesBlock(ctx: Ctx): Html { | ||
| 55 | 56 | // again. Only from the confirm page (`/-/confirm`), with the address typed back: the terminal asks |
| 56 | 57 | // first too. |
| 57 | 58 | export async function emailRemove(ctx: Ctx): Promise<Response> { |
| 58 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 59 | if (!signedInPage(ctx, "proven_identities")) return signInFirst(ctx); | |
| 59 | 60 | const form = await readForm(ctx, "rw"); |
| 60 | 61 | if (form instanceof Response) return form; |
| 61 | 62 | if (field(form, "confirm") !== ctx.auth.user.email) |
src/web/pages/pull-guest.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * says what happens next in one sentence, read from the diff on the server. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| 11 | 12 | import type { Pull } from "../../core/pulls.ts"; |
| 12 | 13 | import type { Repo } from "../../core/repos.ts"; |
| @@ -73,7 +74,7 @@ export async function guestWalls(ctx: Ctx, repo: Repo, pull: Pull, baseOid: stri | ||
| 73 | 74 | export async function pullApproveGuestSubmit(ctx: Ctx): Promise<Response> { |
| 74 | 75 | const found = pullContext(ctx); |
| 75 | 76 | if (found instanceof Response) return found; |
| 76 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 77 | if (!signedInPage(ctx, "pull-guest")) return signInFirst(ctx); | |
| 77 | 78 | const form = await readForm(ctx, "rw"); |
| 78 | 79 | if (form instanceof Response) return form; |
| 79 | 80 | const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`; |
src/web/pages/pull.ts +6 −5
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * it needs. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { paneJs } from "../studio/pane.ts"; |
| 12 | 13 | import { pullProposalAt } from "../../core/proposal_token.ts"; |
| 13 | 14 | import { keyOf, oldKeys } from "../keymap.ts"; |
| @@ -1351,7 +1352,7 @@ export function pullThreadFragment(ctx: Ctx): Response { | ||
| 1351 | 1352 | export async function pullCommentSubmit(ctx: Ctx): Promise<Response> { |
| 1352 | 1353 | const found = pullContext(ctx); |
| 1353 | 1354 | if (found instanceof Response) return found; |
| 1354 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1355 | if (!signedInPage(ctx, "pull")) return signInFirst(ctx); | |
| 1355 | 1356 | const form = await readForm(ctx, "rw"); |
| 1356 | 1357 | if (form instanceof Response) return form; |
| 1357 | 1358 | |
| @@ -1389,7 +1390,7 @@ export async function pullCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 1389 | 1390 | export async function pullReviewSubmit(ctx: Ctx): Promise<Response> { |
| 1390 | 1391 | const found = pullContext(ctx); |
| 1391 | 1392 | if (found instanceof Response) return found; |
| 1392 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1393 | if (!signedInPage(ctx, "pull")) return signInFirst(ctx); | |
| 1393 | 1394 | const form = await readForm(ctx, "rw"); |
| 1394 | 1395 | if (form instanceof Response) return form; |
| 1395 | 1396 | |
| @@ -1484,7 +1485,7 @@ export function approveHereCard( | ||
| 1484 | 1485 | export async function pullApproveHereSubmit(ctx: Ctx): Promise<Response> { |
| 1485 | 1486 | const found = pullContext(ctx); |
| 1486 | 1487 | if (found instanceof Response) return found; |
| 1487 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1488 | if (!signedInPage(ctx, "pull")) return signInFirst(ctx); | |
| 1488 | 1489 | const form = await readForm(ctx, "rw"); |
| 1489 | 1490 | if (form instanceof Response) return form; |
| 1490 | 1491 | const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`; |
| @@ -1527,7 +1528,7 @@ export async function pullApproveHereSubmit(ctx: Ctx): Promise<Response> { | ||
| 1527 | 1528 | export async function pullReviewStateSubmit(ctx: Ctx): Promise<Response> { |
| 1528 | 1529 | const found = pullContext(ctx); |
| 1529 | 1530 | if (found instanceof Response) return found; |
| 1530 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1531 | if (!signedInPage(ctx, "pull")) return signInFirst(ctx); | |
| 1531 | 1532 | const form = await readForm(ctx, "rw"); |
| 1532 | 1533 | if (form instanceof Response) return form; |
| 1533 | 1534 | |
| @@ -1589,7 +1590,7 @@ export function threadResolveSubmit( | ||
| 1589 | 1590 | return async (ctx: Ctx): Promise<Response> => { |
| 1590 | 1591 | const found = pullContext(ctx); |
| 1591 | 1592 | if (found instanceof Response) return found; |
| 1592 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1593 | if (!signedInPage(ctx, "pull")) return signInFirst(ctx); | |
| 1593 | 1594 | const form = await readForm(ctx, "rw"); |
| 1594 | 1595 | if (form instanceof Response) return form; |
| 1595 | 1596 |
src/web/pages/pulls.ts +3 −2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * `src/web/studio/lists.ts`). |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { DELETING_SAYS } from "../../core/repo_deleting.ts"; |
| 9 | 10 | import { openPull } from "../../actions/pulls.ts"; |
| 10 | 11 | import { VERIFY_FIRST } from "../../actions/verify_words.ts"; |
| @@ -139,7 +140,7 @@ export async function newPullPage(ctx: Ctx): Promise<Response> { | ||
| 139 | 140 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 140 | 141 | const repo = loadRepo(ctx); |
| 141 | 142 | if (!repo) return notFoundPage(ctx); |
| 142 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 143 | if (!signedInPage(ctx, "pulls")) return signInFirst(ctx); | |
| 143 | 144 | const forceSelf = ctx.url.searchParams.get("self") !== null; |
| 144 | 145 | const comparing = performance.now(); |
| 145 | 146 | const c = await composeContext(ctx, repo, forceSelf); |
| @@ -220,7 +221,7 @@ const COMPOSE_ERRORS: Record<string, string> = { | ||
| 220 | 221 | export async function newPullSubmit(ctx: Ctx): Promise<Response> { |
| 221 | 222 | const repo = loadRepo(ctx); |
| 222 | 223 | if (!repo) return notFoundPage(ctx); |
| 223 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 224 | if (!signedInPage(ctx, "pulls")) return signInFirst(ctx); | |
| 224 | 225 | const form = await readForm(ctx, "rw"); |
| 225 | 226 | if (form instanceof Response) return form; |
| 226 | 227 |
src/web/pages/repo.ts +5 −4
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * path segment and can never smuggle a path of its own. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { clamp } from "../clamp.ts"; |
| 12 | 13 | import { reviewCard } from "./review.ts"; |
| 13 | 14 | import { keyOf } from "../keymap.ts"; |
| @@ -379,7 +380,7 @@ function forkBar(ctx: Ctx, repo: Repo, visible: readonly RecentFork[]): Html { | ||
| 379 | 380 | export async function forkSubmit(ctx: Ctx): Promise<Response> { |
| 380 | 381 | const repo = loadRepo(ctx); |
| 381 | 382 | if (!repo) return notFoundPage(ctx); |
| 382 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 383 | if (!signedInPage(ctx, "repo")) return signInFirst(ctx); | |
| 383 | 384 | const form = await readForm(ctx, "rw"); |
| 384 | 385 | if (form instanceof Response) return form; |
| 385 | 386 | |
| @@ -447,7 +448,7 @@ export async function forkSubmit(ctx: Ctx): Promise<Response> { | ||
| 447 | 448 | export async function repoSyncSubmit(ctx: Ctx): Promise<Response> { |
| 448 | 449 | const repo = loadRepo(ctx); |
| 449 | 450 | if (!repo) return notFoundPage(ctx); |
| 450 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 451 | if (!signedInPage(ctx, "repo")) return signInFirst(ctx); | |
| 451 | 452 | const form = await readForm(ctx, "rw"); |
| 452 | 453 | if (form instanceof Response) return form; |
| 453 | 454 | |
| @@ -503,7 +504,7 @@ function mirrorRefusal(repo: Repo, error: "unauthorized" | "forbidden" | "not_fo | ||
| 503 | 504 | export async function repoTakeSubmit(ctx: Ctx): Promise<Response> { |
| 504 | 505 | const repo = loadRepo(ctx); |
| 505 | 506 | if (!repo) return notFoundPage(ctx); |
| 506 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 507 | if (!signedInPage(ctx, "repo")) return signInFirst(ctx); | |
| 507 | 508 | const form = await readForm(ctx, "rw"); |
| 508 | 509 | if (form instanceof Response) return form; |
| 509 | 510 | const taken = await takeFromOrigin(ctx.app, ctx.auth.user, repo); |
| @@ -529,7 +530,7 @@ export async function repoTakeSubmit(ctx: Ctx): Promise<Response> { | ||
| 529 | 530 | export async function pinSubmit(ctx: Ctx): Promise<Response> { |
| 530 | 531 | const repo = loadRepo(ctx); |
| 531 | 532 | if (!repo) return notFoundPage(ctx); |
| 532 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 533 | if (!signedInPage(ctx, "repo")) return signInFirst(ctx); | |
| 533 | 534 | const form = await readForm(ctx, "rw"); |
| 534 | 535 | if (form instanceof Response) return form; |
| 535 | 536 |
src/web/pages/reports.ts +4 −3
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * gets the usual 404. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | import { |
| 13 | 14 | acceptReport, |
| 14 | 15 | dismissReport, |
| @@ -365,7 +366,7 @@ export function reportsPage(ctx: Ctx): Response { | ||
| 365 | 366 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 366 | 367 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); |
| 367 | 368 | if (!repo) return notFoundPage(ctx); |
| 368 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 369 | if (!signedInPage(ctx, "reports")) return signInFirst(ctx); | |
| 369 | 370 | // A read-only token (an app process holds its owner's) never reads them. |
| 370 | 371 | if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "rw")) |
| 371 | 372 | return notFoundPage(ctx); |
| @@ -413,7 +414,7 @@ export function reportsPage(ctx: Ctx): Response { | ||
| 413 | 414 | export async function reportAcceptSubmit(ctx: Ctx): Promise<Response> { |
| 414 | 415 | const repo = loadRepo(ctx); |
| 415 | 416 | if (!repo) return notFoundPage(ctx); |
| 416 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 417 | if (!signedInPage(ctx, "reports")) return signInFirst(ctx); | |
| 417 | 418 | const form = await readForm(ctx, "rw"); |
| 418 | 419 | if (form instanceof Response) return form; |
| 419 | 420 | const accepted = await acceptReport( |
| @@ -447,7 +448,7 @@ export async function reportAcceptSubmit(ctx: Ctx): Promise<Response> { | ||
| 447 | 448 | export async function reportDismissSubmit(ctx: Ctx): Promise<Response> { |
| 448 | 449 | const repo = loadRepo(ctx); |
| 449 | 450 | if (!repo) return notFoundPage(ctx); |
| 450 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 451 | if (!signedInPage(ctx, "reports")) return signInFirst(ctx); | |
| 451 | 452 | const form = await readForm(ctx, "rw"); |
| 452 | 453 | if (form instanceof Response) return form; |
| 453 | 454 | const dismissed = dismissReport( |
src/web/pages/resilience.ts +5 −4
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * any forge given no bucket — that they are off here and why, said plainly. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { readResilience, type Row } from "../../checks/resilience.ts"; |
| 12 | 13 | import type { Standing } from "../../core/threats.ts"; |
| 13 | 14 | import type { Ctx } from "../../http/context.ts"; |
| @@ -45,8 +46,8 @@ export function nightlyHtml(ctx: Ctx): Html { | ||
| 45 | 46 | // GET /resilience/nightly/:job: the newest output of one nightly job, the |
| 46 | 47 | // run its `Flaky:` and `Red:` issues link to. An admin's, as /resilience is. |
| 47 | 48 | export function nightlyOutputPage(ctx: Ctx): Response { |
| 48 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 49 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 49 | if (!signedInPage(ctx, "resilience")) return signInFirst(ctx); | |
| 50 | if (!adminPage(ctx, "resilience", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 50 | 51 | const at = JOBS.findIndex((j) => j.name === ctx.params.job); |
| 51 | 52 | const job = JOBS[at]; |
| 52 | 53 | if (job === undefined) return notFoundPage(ctx); |
| @@ -100,8 +101,8 @@ export function protectionsHtml(rows: readonly Row[]): Html { | ||
| 100 | 101 | // GET /resilience: a forge admin's, since live red lines name what to attack. |
| 101 | 102 | export function resiliencePage(ctx: Ctx): Response { |
| 102 | 103 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 103 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 104 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 104 | if (!signedInPage(ctx, "resilience")) return signInFirst(ctx); | |
| 105 | if (!adminPage(ctx, "resilience", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 105 | 106 | const rows = timePhase(ctx.request, "threats", () => readResilience(ctx.app.config.dataDir)); |
| 106 | 107 | const rendering = performance.now(); |
| 107 | 108 | const count = (s: Standing): number => rows.filter((r) => r.s === s).length; |
src/web/pages/runners.ts +4 −3
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * routes are marked `open` in `http/marks/settings.json`, as `/admin/flows` is, so this page's own |
| 9 | 9 | * check answers rather than the admin gate's 403. |
| 10 | 10 | */ |
| 11 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { listLending, offerLending, resumeLending, stopLending, type LendView } from "../../actions/lending.ts"; |
| 12 | 13 | import { setRunnerTrust } from "../../actions/environments.ts"; |
| 13 | 14 | import { enrol, list, pause, removeHandMade, resume, revoke, runnerState } from "../../actions/runners.ts"; |
| @@ -32,8 +33,8 @@ import { accountSections } from "./origins.ts"; | ||
| 32 | 33 | const HERE = "/settings/runners"; |
| 33 | 34 | |
| 34 | 35 | function admin(ctx: Ctx): Response | undefined { |
| 35 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 36 | return ctx.auth.user.isAdmin && ctx.auth.user.kind === "user" ? undefined : notFoundPage(ctx); | |
| 36 | if (!signedInPage(ctx, "runners")) return signInFirst(ctx); | |
| 37 | return adminPage(ctx, "runners", ctx.auth.user.isAdmin && ctx.auth.user.kind === "user") ? undefined : notFoundPage(ctx); | |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | /** |
| @@ -222,7 +223,7 @@ export async function runnerPause(ctx: Ctx): Promise<Response> { | ||
| 222 | 223 | |
| 223 | 224 | // GET /settings/runners/lending/live |
| 224 | 225 | export function lendingLive(ctx: Ctx): Response { |
| 225 | if (!ctx.auth.user?.isAdmin || ctx.auth.user.kind !== "user") return fragment(html``, { status: 404 }); | |
| 226 | if (!adminPage(ctx, "runners", ctx.auth.user?.isAdmin === true && ctx.auth.user.kind === "user")) return fragment(html``, { status: 404 }); | |
| 226 | 227 | return fragment(lendingNowPart(ctx), { request: ctx.request }); |
| 227 | 228 | } |
| 228 | 229 |
src/web/pages/runs.ts +5 −4
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | * id, so the redirect itself says nothing about what exists. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | import { signedInPage } from "../../http/page_may.ts"; | |
| 14 | 15 | import { crewFace } from "../pixel.ts"; |
| 15 | 16 | import { steerRefusedWords } from "../../actions/steer_words.ts"; |
| 16 | 17 | import { readLooks } from "../../checks/looks.ts"; |
| @@ -397,7 +398,7 @@ export async function runPage(ctx: Ctx): Promise<Response> { | ||
| 397 | 398 | export async function runSteer(ctx: Ctx): Promise<Response> { |
| 398 | 399 | const repo = loadRepo(ctx); |
| 399 | 400 | if (!repo) return notFoundPage(ctx); |
| 400 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 401 | if (!signedInPage(ctx, "runs")) return signInFirst(ctx); | |
| 401 | 402 | const form = await readForm(ctx, "rw"); |
| 402 | 403 | if (form instanceof Response) return form; |
| 403 | 404 | const id = ctx.params.id ?? ""; |
| @@ -426,7 +427,7 @@ export async function runSteer(ctx: Ctx): Promise<Response> { | ||
| 426 | 427 | |
| 427 | 428 | // GET /runs/:id — the run's own page, wherever it lives. |
| 428 | 429 | export function runRedirect(ctx: Ctx): Response { |
| 429 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 430 | if (!signedInPage(ctx, "runs")) return signInFirst(ctx); | |
| 430 | 431 | const run = getRun(ctx.app.db, ctx.params.id ?? ""); |
| 431 | 432 | const repo = |
| 432 | 433 | run === undefined ? undefined : getRepoById(ctx.app.db, run.repoId); |
| @@ -439,7 +440,7 @@ export function runRedirect(ctx: Ctx): Response { | ||
| 439 | 440 | export async function runCancel(ctx: Ctx): Promise<Response> { |
| 440 | 441 | const repo = loadRepo(ctx); |
| 441 | 442 | if (!repo) return notFoundPage(ctx); |
| 442 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 443 | if (!signedInPage(ctx, "runs")) return signInFirst(ctx); | |
| 443 | 444 | const form = await readForm(ctx, "rw"); |
| 444 | 445 | if (form instanceof Response) return form; |
| 445 | 446 | const id = ctx.params.id ?? ""; |
| @@ -471,7 +472,7 @@ const REQUEUE_REFUSED: Record<string, string> = { | ||
| 471 | 472 | export async function runRequeue(ctx: Ctx): Promise<Response> { |
| 472 | 473 | const repo = loadRepo(ctx); |
| 473 | 474 | if (!repo) return notFoundPage(ctx); |
| 474 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 475 | if (!signedInPage(ctx, "runs")) return signInFirst(ctx); | |
| 475 | 476 | const form = await readForm(ctx, "rw"); |
| 476 | 477 | if (form instanceof Response) return form; |
| 477 | 478 | const queued = requeueRepoRun(ctx.app, ctx.auth.user, repo, ctx.params.id ?? ""); |
src/web/pages/scrapes.ts +3 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * of identity stops at a network or a group, and says so. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 11 | 12 | import type { Ctx } from "../../http/context.ts"; |
| @@ -37,8 +38,8 @@ const days = (raw: string | null): number => { | ||
| 37 | 38 | }; |
| 38 | 39 | |
| 39 | 40 | function admin(ctx: Ctx): Response | null { |
| 40 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 41 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 41 | if (!signedInPage(ctx, "scrapes")) return signInFirst(ctx); | |
| 42 | if (!adminPage(ctx, "scrapes", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 42 | 43 | return null; |
| 43 | 44 | } |
| 44 | 45 |
src/web/pages/secrets.ts +3 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * when something last opened it. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import { sshOn } from "../../settings/ssh.ts"; |
| 11 | 12 | import type { SecretUse } from "../../core/app_secrets.ts"; |
| 12 | 13 | import { lookMailAws, setUpMailAws, testMailAws, undoMailAws } from "../../actions/mail_aws.ts"; |
| @@ -152,8 +153,8 @@ export function secretsSection( | ||
| 152 | 153 | } |
| 153 | 154 | |
| 154 | 155 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 155 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 156 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 156 | if (!signedInPage(ctx, "secrets")) return signInFirst(ctx); | |
| 157 | if (!adminPage(ctx, "secrets", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 157 | 158 | return undefined; |
| 158 | 159 | } |
| 159 | 160 |
src/web/pages/security.ts +5 −4
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * names, never the value of a token or key. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { upstreamBlob } from "../../core/upstream.ts"; |
| 11 | 12 | import { readFileSync, statSync } from "node:fs"; |
| @@ -309,8 +310,8 @@ function scriptErrorRow(db: Database, nowMs: number): Html | null { | ||
| 309 | 310 | } |
| 310 | 311 | |
| 311 | 312 | export function securityPage(ctx: Ctx): Response { |
| 312 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 313 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 313 | if (!signedInPage(ctx, "security")) return signInFirst(ctx); | |
| 314 | if (!adminPage(ctx, "security", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 314 | 315 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 315 | 316 | const rendering = performance.now(); |
| 316 | 317 | const nowMs = Date.now(); |
| @@ -400,8 +401,8 @@ export function securityPage(ctx: Ctx): Response { | ||
| 400 | 401 | |
| 401 | 402 | /** POST /settings/security/shield: move the Shield; the page's Undo posts here too. */ |
| 402 | 403 | export async function securityShieldSet(ctx: Ctx): Promise<Response> { |
| 403 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 404 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 404 | if (!signedInPage(ctx, "security")) return signInFirst(ctx); | |
| 405 | if (!adminPage(ctx, "security", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 405 | 406 | const form = await readForm(ctx, "admin"); |
| 406 | 407 | if (form instanceof Response) return form; |
| 407 | 408 | const changed = changeShield(ctx.app, ctx.auth.user, field(form, "state")); |
src/web/pages/security_controls.ts +3 −2
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | * (`checks/controls.ts`). |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 6 | 7 | import { sshOn } from "../../settings/ssh.ts"; |
| 7 | 8 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 8 | 9 | import { controlStandings, type Standing } from "../../checks/controls.ts"; |
| @@ -40,8 +41,8 @@ function line(s: Standing): Html { | ||
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | export function securityControlsPage(ctx: Ctx): Response { |
| 43 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 44 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 44 | if (!signedInPage(ctx, "security_controls")) return signInFirst(ctx); | |
| 45 | if (!adminPage(ctx, "security_controls", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 45 | 46 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 46 | 47 | const rendering = performance.now(); |
| 47 | 48 | const standings = controlStandings(ctx.app.config.dataDir, Date.now()); |
src/web/pages/series.ts +4 −3
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * forge admin who is a person. Everything lives in the address (`q`, |
| 8 | 8 | * `range`, `from`, `to`), so a view is a link; the only script is none. |
| 9 | 9 | */ |
| 10 | import { signedInPage } from "../../http/page_may.ts"; | |
| 10 | 11 | import { canSeeMemory } from "../../boards/memory.ts"; |
| 11 | 12 | import type { Ctx } from "../../http/context.ts"; |
| 12 | 13 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| @@ -91,7 +92,7 @@ function savedList(rows: readonly Saved[], minutes: number): Html { | ||
| 91 | 92 | |
| 92 | 93 | export function seriesPage(ctx: Ctx): Response { |
| 93 | 94 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 94 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 95 | if (!signedInPage(ctx, "series")) return signInFirst(ctx); | |
| 95 | 96 | if (!canSeeMemory(ctx.auth.user)) return notFoundPage(ctx); |
| 96 | 97 | const ask = askOf(ctx.url.searchParams); |
| 97 | 98 | const a = answer(ctx.app.db, ask, Date.now()); |
| @@ -115,7 +116,7 @@ export function seriesPage(ctx: Ctx): Response { | ||
| 115 | 116 | |
| 116 | 117 | /** POST /explore/series/save: a pin or a report. */ |
| 117 | 118 | export async function seriesSave(ctx: Ctx): Promise<Response> { |
| 118 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 119 | if (!signedInPage(ctx, "series")) return signInFirst(ctx); | |
| 119 | 120 | const form = await readForm(ctx, "admin"); |
| 120 | 121 | if (form instanceof Response) return form; |
| 121 | 122 | if (!canSeeMemory(ctx.auth.user)) return ctx.auth.user.kind === "agent" ? forbiddenPage(ctx, "Saving a query is a person's.") : notFoundPage(ctx); |
| @@ -127,7 +128,7 @@ export async function seriesSave(ctx: Ctx): Promise<Response> { | ||
| 127 | 128 | |
| 128 | 129 | /** POST /explore/series/remove: forget one saved query. */ |
| 129 | 130 | export async function seriesRemove(ctx: Ctx): Promise<Response> { |
| 130 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 131 | if (!signedInPage(ctx, "series")) return signInFirst(ctx); | |
| 131 | 132 | const form = await readForm(ctx, "admin"); |
| 132 | 133 | if (form instanceof Response) return form; |
| 133 | 134 | if (!canSeeMemory(ctx.auth.user)) return ctx.auth.user.kind === "agent" ? forbiddenPage(ctx, "Removing a saved query is a person's.") : notFoundPage(ctx); |
src/web/pages/site.ts +3 −2
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * typed still in it. A dead end that loses input is a bug, not a message. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { contributorMay } from "../../text/contributor.ts"; |
| 12 | 13 | import { closeState, closingSays } from "../../actions/account_close.ts"; |
| 13 | 14 | import { USERNAME_PATTERN } from "../username_pattern.ts"; |
| @@ -991,7 +992,7 @@ function newRepoForm( | ||
| 991 | 992 | } |
| 992 | 993 | |
| 993 | 994 | export function newRepoPage(ctx: Ctx): Response { |
| 994 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 995 | if (!signedInPage(ctx, "site")) return signInFirst(ctx); | |
| 995 | 996 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 996 | 997 | const owners = ownersFor(ctx, ctx.auth.user); |
| 997 | 998 | const rendering = performance.now(); |
| @@ -1014,7 +1015,7 @@ export function newRepoPage(ctx: Ctx): Response { | ||
| 1014 | 1015 | } |
| 1015 | 1016 | |
| 1016 | 1017 | export async function newRepoSubmit(ctx: Ctx): Promise<Response> { |
| 1017 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1018 | if (!signedInPage(ctx, "site")) return signInFirst(ctx); | |
| 1018 | 1019 | const form = await readForm(ctx, "rw"); |
| 1019 | 1020 | if (form instanceof Response) return form; |
| 1020 | 1021 | const values: RepoValues = { |
src/web/pages/sources.ts +3 −2
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * stored views (`perf/views_store.ts`) in one indexed read. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | import { sshOn } from "../../settings/ssh.ts"; |
| 13 | 14 | import { getAppById } from "../../core/apps.ts"; |
| 14 | 15 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -269,8 +270,8 @@ export function sourcesBody(ctx: Ctx, q: Query, label: string): Html { | ||
| 269 | 270 | |
| 270 | 271 | /** GET /settings/traffic/sources — the forge's view, or `?app=<id>` for any app; admins only. */ |
| 271 | 272 | export function sourcesPage(ctx: Ctx): Response { |
| 272 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 273 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 273 | if (!signedInPage(ctx, "sources")) return signInFirst(ctx); | |
| 274 | if (!adminPage(ctx, "sources", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 274 | 275 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 275 | 276 | const asked = ctx.url.searchParams.get("app"); |
| 276 | 277 | const record = asked === null ? undefined : getAppById(ctx.app.db, asked); |
src/web/pages/spend-tab.ts +3 −2
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * on the Subscriptions page before; the numbers are the same. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 7 | 8 | import { readSpend } from "../../actions/spend.ts"; |
| 8 | 9 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 9 | 10 | import type { Ctx } from "../../http/context.ts"; |
| @@ -15,8 +16,8 @@ import { usageShell } from "./usage-tabs.ts"; | ||
| 15 | 16 | |
| 16 | 17 | // GET /settings/spend |
| 17 | 18 | export function spendPage(ctx: Ctx): Response { |
| 18 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 19 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 19 | if (!signedInPage(ctx, "spend-tab")) return signInFirst(ctx); | |
| 20 | if (!adminPage(ctx, "spend-tab", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 20 | 21 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 21 | 22 | const spend = timePhase(ctx.request, "spend", () => readSpend(ctx.app, new Date())); |
| 22 | 23 | const rendering = performance.now(); |
src/web/pages/subscriptions.ts +3 −2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * for. A token is typed once and never shown again. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { ACCOUNTS_WORDS, allowAccount, crewAccountWords } from "../../actions/crew_accounts.ts"; |
| 9 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import { listAgents, type Agent } from "../../core/agents.ts"; |
| @@ -75,8 +76,8 @@ import { limitValue } from "../../settings/limits.ts"; | ||
| 75 | 76 | const POOL = "/settings/subscriptions"; |
| 76 | 77 | |
| 77 | 78 | function requireAdmin(ctx: Ctx): Response | undefined { |
| 78 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 79 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 79 | if (!signedInPage(ctx, "subscriptions")) return signInFirst(ctx); | |
| 80 | if (!adminPage(ctx, "subscriptions", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 80 | 81 | return undefined; |
| 81 | 82 | } |
| 82 | 83 |
src/web/pages/system.ts +4 −3
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | * line each for memory, CPU and disk; a parent lists each child's use |
| 22 | 22 | * against its size (#10853, `spawn/usage.ts`). |
| 23 | 23 | */ |
| 24 | import { signedInPage } from "../../http/page_may.ts"; | |
| 24 | 25 | import { askingOf, type Asker } from "../../perf/asking.ts"; |
| 25 | 26 | import { keyOf } from "../keymap.ts"; |
| 26 | 27 | import { emptyNote } from "../empty_words.ts"; |
| @@ -358,7 +359,7 @@ export { CENSUS_AGENT_REFUSED }; | ||
| 358 | 359 | |
| 359 | 360 | /** POST /system/heap-census: one census, a person admin's, at most every ten minutes. */ |
| 360 | 361 | export async function heapCensusSubmit(ctx: Ctx): Promise<Response> { |
| 361 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 362 | if (!signedInPage(ctx, "system")) return signInFirst(ctx); | |
| 362 | 363 | const form = await readForm(ctx, "admin"); |
| 363 | 364 | if (form instanceof Response) return form; |
| 364 | 365 | // An agent hears why in one sentence; a person who is not an admin finds no such page. |
| @@ -738,7 +739,7 @@ export const sampleFrame = (v: SystemView): { regions: Record<string, string> } | ||
| 738 | 739 | |
| 739 | 740 | // GET /system/stream: the owner's live samples, one frame each. |
| 740 | 741 | export function systemStream(ctx: Ctx): Response { |
| 741 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 742 | if (!signedInPage(ctx, "system")) return signInFirst(ctx); | |
| 742 | 743 | if (telemetryReader(ctx.app, ctx.auth.user)?.kind !== "owner") return notFoundPage(ctx); |
| 743 | 744 | const sampler = live(); |
| 744 | 745 | return eventStream(ctx.app, ctx.request, (emit, _close, ready) => { |
| @@ -763,7 +764,7 @@ export function floorLine(held: FloorHold): Html { | ||
| 763 | 764 | |
| 764 | 765 | // GET /system |
| 765 | 766 | export async function systemPage(ctx: Ctx, patterns: () => readonly string[]): Promise<Response> { |
| 766 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 767 | if (!signedInPage(ctx, "system")) return signInFirst(ctx); | |
| 767 | 768 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 768 | 769 | const reader = timePhase(ctx.request, "reader", () => telemetryReader(ctx.app, ctx.auth.user!)); |
| 769 | 770 | if (reader?.kind !== "owner") return notFoundPage(ctx); |
src/web/pages/teams.ts +3 −2
| @@ -20,6 +20,7 @@ import { flashTo, page } from "../layout.ts"; | ||
| 20 | 20 | import { btn, icon, row, time } from "../ui.ts"; |
| 21 | 21 | import { emptyLine, emptyList } from "../empty_words.ts"; |
| 22 | 22 | import { accountSections } from "./origins.ts"; |
| 23 | import { adminPage } from "../../http/page_may.ts"; | |
| 23 | 24 | |
| 24 | 25 | const isAdminPerson = (ctx: Ctx): boolean => |
| 25 | 26 | ctx.auth.user?.isAdmin === true && ctx.auth.user.kind !== "agent"; |
| @@ -159,7 +160,7 @@ export const teamsLiveJs = /* js */ ` | ||
| 159 | 160 | |
| 160 | 161 | // GET /settings/teams/stream: the page's regions again, each time a team changes. |
| 161 | 162 | export function teamsStream(ctx: Ctx): Response { |
| 162 | if (!isAdminPerson(ctx)) return notFoundPage(ctx); | |
| 163 | if (!adminPage(ctx, "teams", isAdminPerson(ctx))) return notFoundPage(ctx); | |
| 163 | 164 | return eventStream(ctx.app, ctx.request, (emit, _close, ready) => { |
| 164 | 165 | const send = () => { |
| 165 | 166 | const r = regions(ctx); |
| @@ -203,7 +204,7 @@ export function teamsPage(ctx: Ctx): Response { | ||
| 203 | 204 | // POST /settings/teams/:slug |
| 204 | 205 | export async function teamSet(ctx: Ctx): Promise<Response> { |
| 205 | 206 | // Checked before the body is read: a non-admin learns nothing of the door. |
| 206 | if (!isAdminPerson(ctx)) return notFoundPage(ctx); | |
| 207 | if (!adminPage(ctx, "teams", isAdminPerson(ctx))) return notFoundPage(ctx); | |
| 207 | 208 | const form = await readForm(ctx, "admin"); |
| 208 | 209 | if (form instanceof Response) return form; |
| 209 | 210 | const slug = ctx.params.slug ?? ""; |
src/web/pages/telemetry.ts +3 −2
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | * Settings → Telemetry, for the owner: which named agents hold |
| 3 | 3 | * `telemetry:read`, one switch each, and the reads they have made (#1789). |
| 4 | 4 | */ |
| 5 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 5 | 6 | import { setTelemetryGrant } from "../../actions/telemetry.ts"; |
| 6 | 7 | import { grantable, recentReads } from "../../core/telemetry.ts"; |
| 7 | 8 | import type { Ctx } from "../../http/context.ts"; |
| @@ -14,8 +15,8 @@ import { btn, icon, row, time } from "../ui.ts"; | ||
| 14 | 15 | import { usageShell } from "./usage-tabs.ts"; |
| 15 | 16 | |
| 16 | 17 | function owner(ctx: Ctx): Response | undefined { |
| 17 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 18 | return ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx); | |
| 18 | if (!signedInPage(ctx, "telemetry")) return signInFirst(ctx); | |
| 19 | return adminPage(ctx, "telemetry", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx); | |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | // GET /settings/telemetry |
src/web/pages/thread.ts +8 −7
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * is what makes a long thread skimmable. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { signedInPage } from "../../http/page_may.ts"; | |
| 11 | 12 | import { originError } from "../../actions/merge_words.ts"; |
| 12 | 13 | import { keyOf } from "../keymap.ts"; |
| 13 | 14 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; |
| @@ -922,7 +923,7 @@ export async function assigneeSubmit( | ||
| 922 | 923 | ): Promise<Response> { |
| 923 | 924 | const found = threadContext(ctx, kind); |
| 924 | 925 | if (found instanceof Response) return found; |
| 925 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 926 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 926 | 927 | const form = await readForm(ctx, "rw"); |
| 927 | 928 | if (form instanceof Response) return form; |
| 928 | 929 | |
| @@ -972,7 +973,7 @@ export async function stateSubmit( | ||
| 972 | 973 | ): Promise<Response> { |
| 973 | 974 | const found = threadContext(ctx, kind); |
| 974 | 975 | if (found instanceof Response) return found; |
| 975 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 976 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 976 | 977 | const form = await readForm(ctx, "rw"); |
| 977 | 978 | if (form instanceof Response) return form; |
| 978 | 979 | |
| @@ -1049,7 +1050,7 @@ export async function wordsSubmit( | ||
| 1049 | 1050 | ): Promise<Response> { |
| 1050 | 1051 | const found = threadContext(ctx, kind); |
| 1051 | 1052 | if (found instanceof Response) return found; |
| 1052 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1053 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 1053 | 1054 | const form = await readForm(ctx, "rw"); |
| 1054 | 1055 | if (form instanceof Response) return form; |
| 1055 | 1056 | const dest = `${repoBase(found.repo)}/${kind === "pull" ? "pulls" : "issues"}/${found.issue.number}`; |
| @@ -1084,7 +1085,7 @@ export async function labelsSubmit( | ||
| 1084 | 1085 | ): Promise<Response> { |
| 1085 | 1086 | const found = threadContext(ctx, kind); |
| 1086 | 1087 | if (found instanceof Response) return found; |
| 1087 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1088 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 1088 | 1089 | const form = await readForm(ctx, "rw"); |
| 1089 | 1090 | if (form instanceof Response) return form; |
| 1090 | 1091 | |
| @@ -1121,7 +1122,7 @@ export async function labelsSubmit( | ||
| 1121 | 1122 | export async function flowSubmit(ctx: Ctx): Promise<Response> { |
| 1122 | 1123 | const found = threadContext(ctx, "issue"); |
| 1123 | 1124 | if (found instanceof Response) return found; |
| 1124 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1125 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 1125 | 1126 | const form = await readForm(ctx, "rw"); |
| 1126 | 1127 | if (form instanceof Response) return form; |
| 1127 | 1128 | const asked = field(form, "flow"); |
| @@ -1172,7 +1173,7 @@ export function issueTeamsCard(ctx: Ctx, repo: Repo, issue: Issue, action: strin | ||
| 1172 | 1173 | export async function teamsSubmit(ctx: Ctx): Promise<Response> { |
| 1173 | 1174 | const found = threadContext(ctx, "issue"); |
| 1174 | 1175 | if (found instanceof Response) return found; |
| 1175 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1176 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 1176 | 1177 | const form = await readForm(ctx, "rw"); |
| 1177 | 1178 | if (form instanceof Response) return form; |
| 1178 | 1179 | const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`; |
| @@ -1288,7 +1289,7 @@ export function dependenciesCard( | ||
| 1288 | 1289 | export async function dependencySubmit(ctx: Ctx): Promise<Response> { |
| 1289 | 1290 | const found = threadContext(ctx, "issue"); |
| 1290 | 1291 | if (found instanceof Response) return found; |
| 1291 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 1292 | if (!signedInPage(ctx, "thread")) return signInFirst(ctx); | |
| 1292 | 1293 | const form = await readForm(ctx, "rw"); |
| 1293 | 1294 | if (form instanceof Response) return form; |
| 1294 | 1295 | const dest = backTo(form, `${repoBase(found.repo)}/issues/${found.issue.number}`); |
src/web/pages/traffic.ts +3 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * but an admin. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 9 | 10 | import { sshOn } from "../../settings/ssh.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| 11 | 12 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -113,8 +114,8 @@ function legend(): Html { | ||
| 113 | 114 | } |
| 114 | 115 | |
| 115 | 116 | export function trafficPage(ctx: Ctx): Response { |
| 116 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 117 | if (!ctx.auth.user.isAdmin) return notFoundPage(ctx); | |
| 117 | if (!signedInPage(ctx, "traffic")) return signInFirst(ctx); | |
| 118 | if (!adminPage(ctx, "traffic", ctx.auth.user.isAdmin)) return notFoundPage(ctx); | |
| 118 | 119 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 119 | 120 | const rendering = performance.now(); |
| 120 | 121 | const now = Date.now(); |
src/web/pages/trusted.ts +3 −2
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | * a person's review, until when; a one-click remove; the kill switch that |
| 4 | 4 | * stops all folding in; and the revert of one source's landings. |
| 5 | 5 | */ |
| 6 | import { adminPage, signedInPage } from "../../http/page_may.ts"; | |
| 6 | 7 | import { sshOn } from "../../settings/ssh.ts"; |
| 7 | 8 | import { addTrust, removeTrust, revertBySource, setFoldInStopped } from "../../actions/trusted_sources.ts"; |
| 8 | 9 | import { |
| @@ -23,8 +24,8 @@ import { emptyList } from "../empty_words.ts"; | ||
| 23 | 24 | import { accountSections } from "./origins.ts"; |
| 24 | 25 | |
| 25 | 26 | function owner(ctx: Ctx): Response | undefined { |
| 26 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 27 | return ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent" ? undefined : notFoundPage(ctx); | |
| 27 | if (!signedInPage(ctx, "trusted")) return signInFirst(ctx); | |
| 28 | return adminPage(ctx, "trusted", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent") ? undefined : notFoundPage(ctx); | |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | const WORDS: Record<TrustError | "not_found", string> = { |
src/web/pages/variants.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * of script. A reader sees the cards and no buttons; their post is refused. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { signedInPage } from "../../http/page_may.ts"; | |
| 8 | 9 | import { DEFAULT_REASON, REASON_MAX, voteVariant } from "../../actions/variants.ts"; |
| 9 | 10 | import { getAppByRepo } from "../../core/apps.ts"; |
| 10 | 11 | import { variantMembers, type Pull } from "../../core/pulls.ts"; |
| @@ -121,7 +122,7 @@ export const variantVoteSubmit = | ||
| 121 | 122 | async (ctx: Ctx): Promise<Response> => { |
| 122 | 123 | const repo = loadRepo(ctx); |
| 123 | 124 | if (!repo) return notFoundPage(ctx); |
| 124 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 125 | if (!signedInPage(ctx, "variants")) return signInFirst(ctx); | |
| 125 | 126 | const form = await readForm(ctx, "rw"); |
| 126 | 127 | if (form instanceof Response) return form; |
| 127 | 128 | const group = ctx.params.group ?? ""; |
src/web/pages/visitor_bring.ts +4 −3
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * undoes them (`tui/screens/visitor_bring.ts`). |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { signedInPage } from "../../http/page_may.ts"; | |
| 12 | 13 | import { BRING_WORDS, broughtCount, bringable, bringToAccount, broughtReceipts, movedApps, mayBring, undoBrought } from "../../actions/visitor_bring.ts"; |
| 13 | 14 | import { MADE_SHOWN, type Made, type MovedApp, type Receipt } from "../../core/visitor_bring.ts"; |
| 14 | 15 | import type { Ctx } from "../../http/context.ts"; |
| @@ -58,7 +59,7 @@ const receiptRow = (r: Receipt, now: number): Html => { | ||
| 58 | 59 | // GET /settings/bring |
| 59 | 60 | export function visitorBringPage(ctx: Ctx): Response { |
| 60 | 61 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 61 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 62 | if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx); | |
| 62 | 63 | const user = ctx.auth.user; |
| 63 | 64 | const carry = carryOf(ctx.url.searchParams.get("carry")); |
| 64 | 65 | const { made, more } = bringable(ctx.app, { carry, headers: ctx.request.headers }); |
| @@ -105,7 +106,7 @@ export function visitorBringPage(ctx: Ctx): Response { | ||
| 105 | 106 | |
| 106 | 107 | // POST /settings/bring |
| 107 | 108 | export async function visitorBringSubmit(ctx: Ctx): Promise<Response> { |
| 108 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 109 | if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx); | |
| 109 | 110 | const form = await readForm(ctx, "admin"); |
| 110 | 111 | if (form instanceof Response) return form; |
| 111 | 112 | const carry = carryOf(field(form, "carry")); |
| @@ -118,7 +119,7 @@ export async function visitorBringSubmit(ctx: Ctx): Promise<Response> { | ||
| 118 | 119 | |
| 119 | 120 | // POST /settings/bring/:id/undo |
| 120 | 121 | export async function visitorBringUndo(ctx: Ctx): Promise<Response> { |
| 121 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 122 | if (!signedInPage(ctx, "visitor_bring")) return signInFirst(ctx); | |
| 122 | 123 | const form = await readForm(ctx, "admin"); |
| 123 | 124 | if (form instanceof Response) return form; |
| 124 | 125 | const done = undoBrought(ctx.app, ctx.auth.user, ctx.params["id"] ?? ""); |
src/web/pages/visitors.ts +2 −1
| @@ -17,6 +17,7 @@ import { flashTo } from "../layout.ts"; | ||
| 17 | 17 | import { TRAFFIC_TONES } from "../studio/kpi_row.ts"; |
| 18 | 18 | import { btn, row } from "../ui.ts"; |
| 19 | 19 | import { emptyList } from "../empty_words.ts"; |
| 20 | import { adminPage } from "../../http/page_may.ts"; | |
| 20 | 21 | |
| 21 | 22 | const W = 600; |
| 22 | 23 | const H = 72; |
| @@ -110,7 +111,7 @@ export function visitorsBlock(ctx: Ctx, now: number): Html { | ||
| 110 | 111 | |
| 111 | 112 | /** POST /settings/traffic/returning: an admin turns the setting on or off. */ |
| 112 | 113 | export async function returningSet(ctx: Ctx): Promise<Response> { |
| 113 | if (ctx.auth.user?.isAdmin !== true || ctx.auth.user.kind === "agent") return notFoundPage(ctx); | |
| 114 | if (ctx.auth.user === undefined || !adminPage(ctx, "visitors", ctx.auth.user.isAdmin && ctx.auth.user.kind !== "agent")) return notFoundPage(ctx); | |
| 114 | 115 | const form = await readForm(ctx, "admin"); |
| 115 | 116 | if (form instanceof Response) return form; |
| 116 | 117 | const value = field(form, "returning"); |
src/web/pages/week.ts +2 −1
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * proposals, each its own form: one tap by someone who writes here takes it, |
| 5 | 5 | * and nothing else on the page changes anything. |
| 6 | 6 | */ |
| 7 | import { signedInPage } from "../../http/page_may.ts"; | |
| 7 | 8 | import { takeProposal } from "../../actions/week.ts"; |
| 8 | 9 | import { emptyNote } from "../empty_words.ts"; |
| 9 | 10 | import { whileFull, whileFullLine } from "../../checks/full_window_recheck.ts"; |
| @@ -121,7 +122,7 @@ export function weekPage(ctx: Ctx): Response { | ||
| 121 | 122 | export async function weekSubmit(ctx: Ctx): Promise<Response> { |
| 122 | 123 | const repo = loadRepo(ctx); |
| 123 | 124 | if (!repo) return notFoundPage(ctx); |
| 124 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 125 | if (!signedInPage(ctx, "week")) return signInFirst(ctx); | |
| 125 | 126 | const form = await readForm(ctx, "rw"); |
| 126 | 127 | if (form instanceof Response) return form; |
| 127 | 128 | const dest = backTo(form, `${repoBase(repo)}/week`); |
11 more files not shown.
new above
offline
Medium: this asks
forge.writefor every sign-in gate, GET pages included. A read-only token may legitimately read them, so each such view records a false disagreement. Take the action as a parameter (forge.readfor GET,forge.writefor writes) so the count stays meaningful.