Public: anyone can read this; the crew can change it.
may() is the only permission check: every helper in STILL_TO_FOLD is deleted #18631
The crew's run on it is queued
mason/forge:mason/18605-may-is-the-only-permission-check-every-h → main 2 commits fork
18 files
changed +114
−113
- src/actions/crew_ceiling.ts
- src/actions/planner_switch.ts
- src/core/may.ts
- src/http/mcp/tools/system.ts
- src/tui/screens/accountorder.ts
- src/tui/screens/atlas.ts
- src/tui/screens/autonomy.ts
- src/tui/screens/crewswitch.ts
- src/tui/screens/dataimport.ts
- src/tui/screens/datamove.ts
- src/tui/screens/pull.ts
- src/tui/screens/readgrants.ts
- src/web/chrome.ts
- src/web/pages/boards-view.ts
- src/web/studio/alarm_lines.ts
- src/web/studio/review_start.ts
- test/flow-alarm-lane.test.ts
- test/may-only.test.ts
src/actions/crew_ceiling.ts −5
| @@ -20,11 +20,6 @@ export function applyStoredCeiling(app: App): void { | ||
| 20 | 20 | holdRaisedCeiling(app.config, typeof stored === "number" && stored > 0 && stored <= MAX_CEILING ? stored : null); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | /** Whether `actor` may raise the ceiling: a forge admin, and a cap is set. */ | |
| 24 | export function mayRaiseCeiling(app: App, actor: User | undefined): boolean { | |
| 25 | return actor?.isAdmin === true && forgeCeiling(app.config) !== null; | |
| 26 | } | |
| 27 | ||
| 28 | 23 | /** |
| 29 | 24 | * Raise to `to`, the figure the caller showed. Refused unless it is what one Raise from the |
| 30 | 25 | * current cap gives, so a repeated or stale Raise does not compound. |
src/actions/planner_switch.ts +6 −9
| @@ -4,9 +4,11 @@ | ||
| 4 | 4 | * rule (what a pause stops) lives in `core/planner_pause.ts`. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { holds } from "../core/may.ts"; | |
| 8 | import { principalOfUser } from "../core/principal.ts"; | |
| 7 | 9 | import { forgetGrowthPanel } from "../core/growth_panel.ts"; |
| 8 | 10 | import type { App } from "../app.ts"; |
| 9 | import { canAdmin, type Repo } from "../core/repos.ts"; | |
| 11 | import type { Repo } from "../core/repos.ts"; | |
| 10 | 12 | import type { User } from "../core/users.ts"; |
| 11 | 13 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 12 | 14 | import { FOREVER, liftCeilingOnce, nextWeek, pauseForChapter, parseCeiling, pausePlanner, pausedUntil, resumePlanner, setOpenCeiling } from "../core/planner_pause.ts"; |
| @@ -30,11 +32,6 @@ export const SWITCH_REFUSED: Record<SwitchError, string> = { | ||
| 30 | 32 | no_chapter: "There is no open chapter to wait for.", |
| 31 | 33 | }; |
| 32 | 34 | |
| 33 | /** A person who administers the repository may switch the planner; an agent never. */ | |
| 34 | export function maySwitch(app: App, actor: User | undefined, repo: Repo): boolean { | |
| 35 | return actor !== undefined && actor.kind !== "agent" && canAdmin(app.db, repo, actor); | |
| 36 | } | |
| 37 | ||
| 38 | 35 | /** Whether `at` (UTC) is a time in the future within a year. */ |
| 39 | 36 | export function validUntil(at: string, now = new Date()): boolean { |
| 40 | 37 | const t = Date.parse(at); |
| @@ -50,7 +47,7 @@ export function setPlannerSwitch( | ||
| 50 | 47 | now = new Date(), |
| 51 | 48 | ): Result<string | null, SwitchError> { |
| 52 | 49 | if (actor === undefined) return err("not_found"); |
| 53 | if (!maySwitch(app, actor, repo)) return err("forbidden"); | |
| 50 | if (!holds(app.db, principalOfUser(actor), "repo.admin_person", { repo })) return err("forbidden"); | |
| 54 | 51 | if (input.mode === "on") resumePlanner(app.db, repo.id); |
| 55 | 52 | else if (input.mode === "chapter") { |
| 56 | 53 | if (!pauseForChapter(app.db, repo.id, actor.id)) return err("no_chapter"); |
| @@ -104,7 +101,7 @@ export function setCeiling( | ||
| 104 | 101 | input: { readonly mode: "set"; readonly value: string } | { readonly mode: "resume" }, |
| 105 | 102 | ): Result<number, SwitchError> { |
| 106 | 103 | if (actor === undefined) return err("not_found"); |
| 107 | if (actor.kind === "agent" || !canAdmin(app.db, repo, actor)) return err("forbidden"); | |
| 104 | if (!holds(app.db, principalOfUser(actor), "repo.admin_person", { repo })) return err("forbidden"); | |
| 108 | 105 | let value: number; |
| 109 | 106 | if (input.mode === "resume") value = liftCeilingOnce(app.db, repo.id, actor.id); |
| 110 | 107 | else { |
| @@ -123,7 +120,7 @@ export function setCeiling( | ||
| 123 | 120 | */ |
| 124 | 121 | export function setPullsCeiling(app: App, actor: User | undefined, repo: Repo, raw: string): Result<number, SwitchError> { |
| 125 | 122 | if (actor === undefined) return err("not_found"); |
| 126 | if (actor.kind === "agent" || !canAdmin(app.db, repo, actor)) return err("forbidden"); | |
| 123 | if (!holds(app.db, principalOfUser(actor), "repo.admin_person", { repo })) return err("forbidden"); | |
| 127 | 124 | const n = parsePullsCeiling(raw); |
| 128 | 125 | if (n === undefined) return err("invalid"); |
| 129 | 126 | setOpenPullsCeiling(app.db, repo.id, n, actor.id); |
src/core/may.ts +4
| @@ -59,6 +59,8 @@ export const ACTIONS = { | ||
| 59 | 59 | "repo.read": { says: "Read a repository: its code, issues and pulls", over: "repo", scope: "ro" }, |
| 60 | 60 | "repo.write": { says: "Change a repository: push, merge, label, close", over: "repo", scope: "rw" }, |
| 61 | 61 | "repo.admin": { says: "Administer a repository: its settings, webhooks, protection and deletion", over: "repo", scope: "rw" }, |
| 62 | "repo.write_person": { says: "Change a repository as a person: one who writes to it, never a crew member", over: "repo", scope: "rw" }, | |
| 63 | "repo.admin_person": { says: "Administer a repository as a person: one who administers it, never a crew member", over: "repo", scope: "rw" }, | |
| 62 | 64 | "forge.read": forgeAction("read"), |
| 63 | 65 | "forge.write": { says: "Change something as your account: any write, by a session or a token of scope rw", over: "forge", scope: "rw" }, |
| 64 | 66 | "forge.comment": forgeAction("comment"), |
| @@ -116,6 +118,8 @@ const ABILITY_OF: Readonly<Partial<Record<Action, Ability>>> = { | ||
| 116 | 118 | function repoRuleHolds(db: Database, action: Action, repo: Repo, user: User | undefined): boolean { |
| 117 | 119 | if (action === "repo.read") return readsRepo(db, repo, user); |
| 118 | 120 | if (action === "repo.write") return writesRepo(db, repo, user); |
| 121 | if (action === "repo.write_person") return user?.kind !== "agent" && writesRepo(db, repo, user); | |
| 122 | if (action === "repo.admin_person") return user?.kind !== "agent" && adminsRepo(db, repo, user); | |
| 119 | 123 | return adminsRepo(db, repo, user); |
| 120 | 124 | } |
| 121 | 125 |
src/http/mcp/tools/system.ts +5 −3
| @@ -1,4 +1,6 @@ | ||
| 1 | 1 | import { noteRead, telemetryReader } from "../../../actions/telemetry.ts"; |
| 2 | import { holds } from "../../../core/may.ts"; | |
| 3 | import { principalOfUser } from "../../../core/principal.ts"; | |
| 2 | 4 | import { badBlocked } from "../shared.ts"; |
| 3 | 5 | import { noTelemetryBlocked } from "../../../actions/blocked_words.ts"; |
| 4 | 6 | import { systemWithReaders } from "../../../system/telemetry.ts"; |
| @@ -22,7 +24,7 @@ import { largestDirs } from "../../../system/largest_dirs.ts"; | ||
| 22 | 24 | import { dbSize } from "../../../system/db_size.ts"; |
| 23 | 25 | import { resultWords, weekRows } from "../../../maintain/week_line.ts"; |
| 24 | 26 | import { duties } from "../../../maintain/registry.ts"; |
| 25 | import { maySwitch, setPlannerSwitch, setPullsCeiling, SWITCH_REFUSED, utcAt, validUntil, type SwitchInput } from "../../../actions/planner_switch.ts"; | |
| 27 | import { setPlannerSwitch, setPullsCeiling, SWITCH_REFUSED, utcAt, validUntil, type SwitchInput } from "../../../actions/planner_switch.ts"; | |
| 26 | 28 | import { pauseSentence, pausedUntil } from "../../../core/planner_pause.ts"; |
| 27 | 29 | import { openPullsCeiling, parsePullsCeiling, pullsCeilingHold } from "../../../core/pulls_ceiling.ts"; |
| 28 | 30 | import { growthCounts } from "../../../core/growth.ts"; |
| @@ -67,7 +69,7 @@ export const tool: Tool = { | ||
| 67 | 69 | const n = args["pulls"]; |
| 68 | 70 | if (typeof n !== "number" || !Number.isInteger(n)) return bad("invalid", "pulls is a whole number, 0 for off"); |
| 69 | 71 | if (args["confirm"] !== undefined && typeof args["confirm"] !== "boolean") return bad("invalid", "confirm is true or false"); |
| 70 | if (!maySwitch(ctx.app, user, repo)) return bad("forbidden", SWITCH_REFUSED.forbidden); | |
| 72 | if (!holds(ctx.app.db, principalOfUser(user), "repo.admin_person", { repo })) return bad("forbidden", SWITCH_REFUSED.forbidden); | |
| 71 | 73 | if (parsePullsCeiling(String(n)) === undefined) return bad("invalid", "pulls is a whole number from 0 to 100000"); |
| 72 | 74 | if (args["confirm"] !== true) |
| 73 | 75 | return good({ done: false, says: `The open-pull ceiling would be ${n === 0 ? "off" : n} (now ${openPullsCeiling(ctx.app.db, repo.id) || "off"}). Nothing changed; call again with confirm:true to do it.` }); |
| @@ -80,7 +82,7 @@ export const tool: Tool = { | ||
| 80 | 82 | if (args["chapter"] !== undefined && (args["chapter"] !== true || a === "resume" || args["until"] !== undefined)) return bad("invalid", "chapter is true, for pause without until"); |
| 81 | 83 | if (args["confirm"] !== undefined && typeof args["confirm"] !== "boolean") return bad("invalid", "confirm is true or false"); |
| 82 | 84 | if (args["until"] !== undefined && (typeof args["until"] !== "string" || a === "resume")) return bad("invalid", "until is a UTC time, for pause"); |
| 83 | if (!maySwitch(ctx.app, user, repo)) return bad("forbidden", SWITCH_REFUSED.forbidden); | |
| 85 | if (!holds(ctx.app.db, principalOfUser(user), "repo.admin_person", { repo })) return bad("forbidden", SWITCH_REFUSED.forbidden); | |
| 84 | 86 | const input: SwitchInput = |
| 85 | 87 | a === "resume" ? { mode: "on" } : args["chapter"] === true ? { mode: "chapter" } : typeof args["until"] === "string" ? { mode: "until", at: utcAt(args["until"]) } : { mode: "owner" }; |
| 86 | 88 | if (input.mode === "until" && !validUntil(input.at)) return bad("invalid", SWITCH_REFUSED.invalid); |
src/tui/screens/accountorder.ts +6 −7
| @@ -6,8 +6,10 @@ | ||
| 6 | 6 | * a write made there. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { holds } from "../../core/may.ts"; | |
| 10 | import { principalOfUser } from "../../core/principal.ts"; | |
| 9 | 11 | import { ORDER_WORDS, parseOrder, repoOrderNames, setRepoOrder } from "../../actions/repo_account_order.ts"; |
| 10 | import { canWrite, type Repo } from "../../core/repos.ts"; | |
| 12 | import type { Repo } from "../../core/repos.ts"; | |
| 11 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 12 | 14 | import { binding } from "../app/keys.ts"; |
| 13 | 15 | import type { Command } from "../app/palette.ts"; |
| @@ -17,9 +19,6 @@ import { truncate } from "../term/width.ts"; | ||
| 17 | 19 | import { fill, len, split } from "../ui/layout.ts"; |
| 18 | 20 | import { ListState, drawList, later, live, promptScreen, type ListRow } from "./common.ts"; |
| 19 | 21 | |
| 20 | /** Who sets the order: a person who can write to the repository. */ | |
| 21 | export const mayOrder = (f: Session, repo: Repo): boolean => f.user !== undefined && f.user.kind !== "agent" && canWrite(f.db, repo, f.user); | |
| 22 | ||
| 23 | 22 | /** Say what a save did, as a toast would. */ |
| 24 | 23 | export function saveOrder(f: Session, repo: Repo, names: readonly string[]): { text: string; bad: boolean } { |
| 25 | 24 | const set = setRepoOrder(f.app, f.user, repo, names); |
| @@ -39,7 +38,7 @@ export function accountOrderScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 39 | 38 | const c = ctx.theme.c; |
| 40 | 39 | const names = repoOrderNames(f.app, repo); |
| 41 | 40 | const [head, list] = split(area, "v", [len(1), fill(1)]); |
| 42 | const said = !mayOrder(f, repo) | |
| 41 | const said = !holds(f.db, principalOfUser(f.user), "repo.write_person", { repo }) | |
| 43 | 42 | ? "A writer of this repository sets its account order." |
| 44 | 43 | : names.length === 0 |
| 45 | 44 | ? "The forge's order. e names accounts to try first here." |
| @@ -51,7 +50,7 @@ export function accountOrderScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 51 | 50 | key(e) { |
| 52 | 51 | if (state.key(e, repoOrderNames(f.app, repo).length)) return true; |
| 53 | 52 | if (e.ctrl || e.alt || (e.key !== "e" && e.key !== "c")) return false; |
| 54 | if (!mayOrder(f, repo)) { | |
| 53 | if (!holds(f.db, principalOfUser(f.user), "repo.write_person", { repo })) { | |
| 55 | 54 | ctx.toast("A writer of this repository sets its account order.", "danger"); |
| 56 | 55 | return true; |
| 57 | 56 | } |
| @@ -86,7 +85,7 @@ export function accountOrderScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 86 | 85 | |
| 87 | 86 | /** The palette's command while a repository the viewer can write to is open. */ |
| 88 | 87 | export function accountOrderCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 89 | if (repo === undefined || !mayOrder(f, repo)) return []; | |
| 88 | if (repo === undefined || !holds(f.db, principalOfUser(f.user), "repo.write_person", { repo })) return []; | |
| 90 | 89 | return [ |
| 91 | 90 | { |
| 92 | 91 | id: "account-order", |
src/tui/screens/atlas.ts +10 −9
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | * viewers live are one code path. Offered to whoever may plan here. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { holds } from "../../core/may.ts"; | |
| 11 | import { principalOfUser } from "../../core/principal.ts"; | |
| 10 | 12 | import { |
| 11 | 13 | ATLAS_BODY_MAX, |
| 12 | 14 | businessItems, |
| @@ -18,7 +20,7 @@ import { | ||
| 18 | 20 | } from "../../actions/business_plan.ts"; |
| 19 | 21 | import type { PlanItem } from "../../actions/plan.ts"; |
| 20 | 22 | import { isCrew } from "../../core/agents.ts"; |
| 21 | import { canRead, canWrite, type Repo } from "../../core/repos.ts"; | |
| 23 | import type { Repo } from "../../core/repos.ts"; | |
| 22 | 24 | import type { Ctx, Screen } from "../app/app.ts"; |
| 23 | 25 | import { binding } from "../app/keys.ts"; |
| 24 | 26 | import type { Command } from "../app/palette.ts"; |
| @@ -29,12 +31,11 @@ import { fill, len, split } from "../ui/layout.ts"; | ||
| 29 | 31 | import { Textarea } from "../ui/textarea.ts"; |
| 30 | 32 | import { card } from "../ui/widgets.ts"; |
| 31 | 33 | |
| 32 | /** Who may plan here: as the API's confirm decides it. */ | |
| 33 | export function mayPlan(f: Session, repo: Repo): boolean { | |
| 34 | const u = f.user; | |
| 35 | if (u === undefined || !canRead(f.db, repo, u)) return false; | |
| 36 | return canWrite(f.db, repo, u) || isCrew(f.db, repo.id, u.id); | |
| 37 | } | |
| 34 | /** Who may plan here, as the API's confirm decides it: a reader who writes, or sits on the crew. */ | |
| 35 | const plans = (f: Session, repo: Repo): boolean => { | |
| 36 | const p = principalOfUser(f.user); | |
| 37 | return holds(f.db, p, "repo.read", { repo }) && (holds(f.db, p, "repo.write", { repo }) || (f.user !== undefined && isCrew(f.db, repo.id, f.user.id))); | |
| 38 | }; | |
| 38 | 39 | |
| 39 | 40 | export type AtlasStep = |
| 40 | 41 | | { readonly kind: "error"; readonly message: string } |
| @@ -46,7 +47,7 @@ export type AtlasStep = | ||
| 46 | 47 | * or, when it is the plan just previewed (`previewed` is its stamp), confirmed. |
| 47 | 48 | */ |
| 48 | 49 | export function atlasStep(f: Session, repo: Repo, text: string, previewed?: string): AtlasStep { |
| 49 | if (!mayPlan(f, repo)) return { kind: "error", message: "you need write access to plan here" }; | |
| 50 | if (!plans(f, repo)) return { kind: "error", message: "you need write access to plan here" }; | |
| 50 | 51 | if (new TextEncoder().encode(text).length > ATLAS_BODY_MAX) |
| 51 | 52 | return { kind: "error", message: `a plan is at most ${ATLAS_BODY_MAX} bytes` }; |
| 52 | 53 | let input: unknown; |
| @@ -155,7 +156,7 @@ export function atlasScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 155 | 156 | |
| 156 | 157 | /** The per-repository command: offered to whoever may plan here. */ |
| 157 | 158 | export function atlasCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 158 | if (repo === undefined || !mayPlan(f, repo)) return []; | |
| 159 | if (repo === undefined || !plans(f, repo)) return []; | |
| 159 | 160 | return [ |
| 160 | 161 | { |
| 161 | 162 | id: "atlas-plan", |
src/tui/screens/autonomy.ts +7 −4
| @@ -14,8 +14,11 @@ | ||
| 14 | 14 | * Anyone else gets no palette entry and, if the screen is reached, no values. |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | import { holds } from "../../core/may.ts"; | |
| 18 | import { principalOfUser } from "../../core/principal.ts"; | |
| 19 | import { forgeCeiling } from "../../flow/ceiling.ts"; | |
| 17 | 20 | import { movedKey } from "./moved_key.ts"; |
| 18 | import { mayRaiseCeiling, raiseCrewCeiling } from "../../actions/crew_ceiling.ts"; | |
| 21 | import { raiseCrewCeiling } from "../../actions/crew_ceiling.ts"; | |
| 19 | 22 | import { checkPool, setCheckSlots } from "../../actions/check_slots.ts"; |
| 20 | 23 | import { pullChecksOf } from "../../checks/check_slots.ts"; |
| 21 | 24 | import { updateRepoSettings } from "../../actions/repos.ts"; |
| @@ -80,7 +83,7 @@ export function autonomyCommands(f: Session, ctx: Ctx, repo: Repo | undefined): | ||
| 80 | 83 | /** The header's crew line, as the web prints it, with its fix. */ |
| 81 | 84 | function stopLineOf(f: Session, r: Repo): string { |
| 82 | 85 | const w = stopWords(autonomyStatus(f.app, r)); |
| 83 | if (w.raiseTo !== undefined && mayRaiseCeiling(f.app, f.user)) return `${w.words} Raise to $${w.raiseTo} (c).`; | |
| 86 | if (w.raiseTo !== undefined && (holds(f.app.db, principalOfUser(f.user), "forge.administer") && forgeCeiling(f.app.config) !== null)) return `${w.words} Raise to $${w.raiseTo} (c).`; | |
| 84 | 87 | return w.fix === null ? w.words : `${w.words} ${w.fix} (m).`; |
| 85 | 88 | } |
| 86 | 89 | |
| @@ -128,7 +131,7 @@ export function autonomyScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 128 | 131 | title: "Autonomy", |
| 129 | 132 | get keys() { |
| 130 | 133 | return mayChange() |
| 131 | ? [binding(["m"], "mode"), binding(["p"], "planner"), binding(["s"], "builder"), binding(["r"], "reviewer"), binding(["o"], "polish share"), binding(["C"], "check slots"), ...(mayRaiseCeiling(f.app, f.user) ? [binding(["c"], "raise ceiling")] : [])] | |
| 134 | ? [binding(["m"], "mode"), binding(["p"], "planner"), binding(["s"], "builder"), binding(["r"], "reviewer"), binding(["o"], "polish share"), binding(["C"], "check slots"), ...((holds(f.app.db, principalOfUser(f.user), "forge.administer") && forgeCeiling(f.app.config) !== null) ? [binding(["c"], "raise ceiling")] : [])] | |
| 132 | 135 | : []; |
| 133 | 136 | }, |
| 134 | 137 | render(area, s) { |
| @@ -194,7 +197,7 @@ export function autonomyScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 194 | 197 | }); |
| 195 | 198 | return true; |
| 196 | 199 | } |
| 197 | if (e.key === "c" && mayRaiseCeiling(f.app, f.user)) { | |
| 200 | if (e.key === "c" && (holds(f.app.db, principalOfUser(f.user), "forge.administer") && forgeCeiling(f.app.config) !== null)) { | |
| 198 | 201 | const to = stopWords(autonomyStatus(f.app, current())).raiseTo; |
| 199 | 202 | if (to === undefined) { |
| 200 | 203 | ctx.toast("The crew is not paused at the forge's ceiling.", "danger"); |
src/tui/screens/crewswitch.ts +5 −7
| @@ -5,9 +5,11 @@ | ||
| 5 | 5 | * open settings page redraws, and this screen follows a change made there. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { holds } from "../../core/may.ts"; | |
| 9 | import { principalOfUser } from "../../core/principal.ts"; | |
| 8 | 10 | import { crewHereSaid, setCrewHere } from "../../actions/crew_switch.ts"; |
| 9 | 11 | import { CREW_OFF_LINE, crewBuildsHere } from "../../core/crew_switch.ts"; |
| 10 | import { canAdmin, type Repo } from "../../core/repos.ts"; | |
| 12 | import type { Repo } from "../../core/repos.ts"; | |
| 11 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 12 | 14 | import { binding } from "../app/keys.ts"; |
| 13 | 15 | import type { Command } from "../app/palette.ts"; |
| @@ -17,13 +19,9 @@ import { drawLines, live, Scroll } from "./common.ts"; | ||
| 17 | 19 | |
| 18 | 20 | const NOT_YOURS = "An admin of this repository switches its crew."; |
| 19 | 21 | |
| 20 | /** The settings page's gate: an admin of the repository, never an agent. */ | |
| 21 | export const maySwitchCrew = (f: Session, repo: Repo): boolean => | |
| 22 | f.user !== undefined && f.user.kind !== "agent" && canAdmin(f.db, repo, f.user); | |
| 23 | ||
| 24 | 22 | /** What the screen says: the switch's state, and the key that flips it for whoever may. */ |
| 25 | 23 | export function crewSwitchLines(f: Session, repo: Repo): string[] { |
| 26 | if (!maySwitchCrew(f, repo)) return [NOT_YOURS]; | |
| 24 | if (!holds(f.db, principalOfUser(f.user), "repo.admin_person", { repo })) return [NOT_YOURS]; | |
| 27 | 25 | return crewBuildsHere(f.db, repo.id) |
| 28 | 26 | ? ["Crew builds here: on. Its builders and planner pick its ready issues.", "Space turns it off."] |
| 29 | 27 | : [CREW_OFF_LINE, "Space turns it on."]; |
| @@ -56,7 +54,7 @@ export function crewSwitchScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 56 | 54 | |
| 57 | 55 | /** The palette's command while a repository the viewer administers is open. */ |
| 58 | 56 | export function crewSwitchCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 59 | if (repo === undefined || !maySwitchCrew(f, repo)) return []; | |
| 57 | if (repo === undefined || !holds(f.db, principalOfUser(f.user), "repo.admin_person", { repo })) return []; | |
| 60 | 58 | return [ |
| 61 | 59 | { |
| 62 | 60 | id: "crew-builds-here", |
src/tui/screens/dataimport.ts +7 −15
| @@ -9,12 +9,14 @@ | ||
| 9 | 9 | * dump's rows and checksum, the store's, and whether they match. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { holds } from "../../core/may.ts"; | |
| 13 | import { principalOfUser } from "../../core/principal.ts"; | |
| 12 | 14 | import { importAppData, importDataMessage } from "../../actions/migrate.ts"; |
| 13 | 15 | import { envDataDir } from "../../apps/data.ts"; |
| 14 | 16 | import { DUMP_FILE_WORDS, readStagedDump } from "../../apps/dump_file.ts"; |
| 15 | 17 | import type { ImportReport } from "../../apps/dump_import.ts"; |
| 16 | 18 | import { getAppByRepo } from "../../core/apps.ts"; |
| 17 | import { canAdmin, type Repo } from "../../core/repos.ts"; | |
| 19 | import type { Repo } from "../../core/repos.ts"; | |
| 18 | 20 | import type { Ctx, Screen } from "../app/app.ts"; |
| 19 | 21 | import { binding } from "../app/keys.ts"; |
| 20 | 22 | import type { Command } from "../app/palette.ts"; |
| @@ -24,16 +26,6 @@ import { truncate } from "../term/width.ts"; | ||
| 24 | 26 | import { fill, len, split } from "../ui/layout.ts"; |
| 25 | 27 | import { ListState, drawList, promptScreen, type ListRow } from "./common.ts"; |
| 26 | 28 | |
| 27 | /** Whether this viewer may import: the repository's admin, and it is an app. */ | |
| 28 | export function mayImport(f: Session, repo: Repo | undefined): repo is Repo { | |
| 29 | return ( | |
| 30 | repo !== undefined && | |
| 31 | f.user !== undefined && | |
| 32 | getAppByRepo(f.app.db, repo.id) !== undefined && | |
| 33 | canAdmin(f.app.db, repo, f.user) | |
| 34 | ); | |
| 35 | } | |
| 36 | ||
| 37 | 29 | /** What an import's report says, a row per table. */ |
| 38 | 30 | export function reportRows(report: ImportReport): ListRow[] { |
| 39 | 31 | return report.tables.map((t) => ({ |
| @@ -52,7 +44,7 @@ export function importStaged( | ||
| 52 | 44 | replace: boolean, |
| 53 | 45 | ): { ok: true; report: ImportReport } | { ok: false; words: string } { |
| 54 | 46 | const record = getAppByRepo(f.app.db, repo.id); |
| 55 | if (record === undefined || !canAdmin(f.app.db, repo, f.user)) return { ok: false, words: "No such repository, or you are not its admin." }; | |
| 47 | if (record === undefined || f.user === undefined || !holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo })) return { ok: false, words: "No such repository, or you are not its admin." }; | |
| 56 | 48 | const read = readStagedDump(envDataDir(f.app.config.dataDir, record.id, "production"), name); |
| 57 | 49 | if (!read.ok) return { ok: false, words: DUMP_FILE_WORDS[read.error] }; |
| 58 | 50 | const done = importAppData(f.app, f.user, repo, { dump: read.sql, replace }); |
| @@ -84,13 +76,13 @@ export function dataImportScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 84 | 76 | render(area, s) { |
| 85 | 77 | const c = ctx.theme.c; |
| 86 | 78 | const [head, list] = split(area, "v", [len(1), fill(1)]); |
| 87 | s.text(head!.x, head!.y, truncate(mayImport(f, repo) ? note : "Only the app's admin imports a database.", head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 79 | s.text(head!.x, head!.y, truncate((repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo })) ? note : "Only the app's admin imports a database.", head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 88 | 80 | drawList(s, list!, c, state, rows); |
| 89 | 81 | }, |
| 90 | 82 | key(e) { |
| 91 | 83 | if (state.key(e, rows.length)) return true; |
| 92 | 84 | if (e.ctrl || e.alt || !["i", "r"].includes(e.key)) return false; |
| 93 | if (!mayImport(f, repo)) { | |
| 85 | if (!(repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo }))) { | |
| 94 | 86 | ctx.toast("Only the app's admin imports a database.", "danger"); |
| 95 | 87 | return true; |
| 96 | 88 | } |
| @@ -103,7 +95,7 @@ export function dataImportScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 103 | 95 | |
| 104 | 96 | /** The palette's command: an admin of a repository that is an app. */ |
| 105 | 97 | export function dataImportCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 106 | if (!mayImport(f, repo)) return []; | |
| 98 | if (!(repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo }))) return []; | |
| 107 | 99 | return [ |
| 108 | 100 | { |
| 109 | 101 | id: "data-import", |
src/tui/screens/datamove.ts +7 −5
| @@ -8,9 +8,11 @@ | ||
| 8 | 8 | * store; the result line says whether it was. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { holds } from "../../core/may.ts"; | |
| 12 | import { principalOfUser } from "../../core/principal.ts"; | |
| 11 | 13 | import { afterMoveWords, dataMoveState, moveData, moveMessage, undoMove, type MoveReceipt } from "../../actions/migrate_data.ts"; |
| 12 | 14 | import { lostKeys, skippedWords } from "../../apps/pg_dump.ts"; |
| 13 | import { canAdmin, type Repo } from "../../core/repos.ts"; | |
| 15 | import type { Repo } from "../../core/repos.ts"; | |
| 14 | 16 | import type { Ctx, Screen } from "../app/app.ts"; |
| 15 | 17 | import { binding } from "../app/keys.ts"; |
| 16 | 18 | import type { Command } from "../app/palette.ts"; |
| @@ -19,7 +21,7 @@ import { style } from "../term/style.ts"; | ||
| 19 | 21 | import { truncate } from "../term/width.ts"; |
| 20 | 22 | import { fill, len, split } from "../ui/layout.ts"; |
| 21 | 23 | import { ListState, confirmScreen, drawList, promptScreen, type ListRow } from "./common.ts"; |
| 22 | import { mayImport } from "./dataimport.ts"; | |
| 24 | import { getAppByRepo } from "../../core/apps.ts"; | |
| 23 | 25 | |
| 24 | 26 | /** A move's receipt, a row per table. */ |
| 25 | 27 | export function moveRows(receipt: MoveReceipt): ListRow[] { |
| @@ -83,13 +85,13 @@ export function dataMoveScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 83 | 85 | render(area, s) { |
| 84 | 86 | const c = ctx.theme.c; |
| 85 | 87 | const [head, list] = split(area, "v", [len(1), fill(1)]); |
| 86 | s.text(head!.x, head!.y, truncate(mayImport(f, repo) ? note : "Only the app's admin moves the data.", head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 88 | s.text(head!.x, head!.y, truncate((repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo })) ? note : "Only the app's admin moves the data.", head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 87 | 89 | drawList(s, list!, c, state, rows); |
| 88 | 90 | }, |
| 89 | 91 | key(e) { |
| 90 | 92 | if (state.key(e, rows.length)) return true; |
| 91 | 93 | if (e.ctrl || e.alt || !["m", "a", "u"].includes(e.key)) return false; |
| 92 | if (!mayImport(f, repo)) { | |
| 94 | if (!(repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo }))) { | |
| 93 | 95 | ctx.toast("Only the app's admin moves the data.", "danger"); |
| 94 | 96 | return true; |
| 95 | 97 | } |
| @@ -108,7 +110,7 @@ export function dataMoveScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 108 | 110 | |
| 109 | 111 | /** The palette's command: an admin of a repository that is an app. */ |
| 110 | 112 | export function dataMoveCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 111 | if (!mayImport(f, repo) || f.user === undefined || !canAdmin(f.app.db, repo, f.user)) return []; | |
| 113 | if (!(repo !== undefined && getAppByRepo(f.app.db, repo.id) !== undefined && holds(f.app.db, principalOfUser(f.user), "repo.admin", { repo }))) return []; | |
| 112 | 114 | return [ |
| 113 | 115 | { |
| 114 | 116 | id: "data-move", |
src/tui/screens/pull.ts +4 −2
| @@ -26,11 +26,13 @@ | ||
| 26 | 26 | * `n`/`p` walk the unsettled ones while the cursor is inside a thread. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | import { holds } from "../../core/may.ts"; | |
| 30 | import { principalOfUser } from "../../core/principal.ts"; | |
| 29 | 31 | import { OFFER_PULL_WORDS, offerPull, previewOfferPull } from "../../actions/offer_pull.ts"; |
| 30 | 32 | import { keyOf } from "../../web/keymap.ts"; |
| 31 | 33 | import { offerStatusLinkFor } from "../../core/outsider_status.ts"; |
| 32 | 34 | import { outsideClause } from "../../web/outside.ts"; |
| 33 | import { mayRetryReview, RETRY_WORDS, reviewFailedToStart } from "../../web/studio/review_start.ts"; | |
| 35 | import { RETRY_WORDS, reviewFailedToStart } from "../../web/studio/review_start.ts"; | |
| 34 | 36 | import { retryFailedStart } from "../../crew/review.ts"; |
| 35 | 37 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; |
| 36 | 38 | import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts"; |
| @@ -385,7 +387,7 @@ export function pullScreen( | ||
| 385 | 387 | /** This open agent pull's review failed to start twice (#16178); `F` sends it again. */ |
| 386 | 388 | let reviewFailed = false; |
| 387 | 389 | /** `F` is the page's "Re-run review", gated as the page gates it (`mayRetryReview`). */ |
| 388 | const mayRerunReview = (): boolean => reviewFailed && repo !== undefined && mayRetryReview(f.db, repo, f.user); | |
| 390 | const mayRerunReview = (): boolean => reviewFailed && repo !== undefined && holds(f.db, principalOfUser(f.user), "repo.write_person", { repo }); | |
| 389 | 391 | /** A writer, on a pull that is one of several variants. */ |
| 390 | 392 | const mayVote = (): boolean => |
| 391 | 393 | mayWrite() && |
src/tui/screens/readgrants.ts +7 −9
| @@ -6,8 +6,10 @@ | ||
| 6 | 6 | * read. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { holds } from "../../core/may.ts"; | |
| 10 | import { principalOfUser } from "../../core/principal.ts"; | |
| 9 | 11 | import { GRANT_ERRORS, grantRead, isReadOnlyMirror, listGrants, revokeRead } from "../../actions/origin_read_grant.ts"; |
| 10 | import { canAdmin, type Repo } from "../../core/repos.ts"; | |
| 12 | import type { Repo } from "../../core/repos.ts"; | |
| 11 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 12 | 14 | import { binding } from "../app/keys.ts"; |
| 13 | 15 | import type { Command } from "../app/palette.ts"; |
| @@ -17,21 +19,17 @@ import { truncate } from "../term/width.ts"; | ||
| 17 | 19 | import { fill, len, split } from "../ui/layout.ts"; |
| 18 | 20 | import { ListState, confirmScreen, drawList, later, promptScreen, type ListRow } from "./common.ts"; |
| 19 | 21 | |
| 20 | /** An admin of a mirror of a read-only origin, the only one who grants. */ | |
| 21 | export const mayGrantRead = (f: Session, repo: Repo): boolean => | |
| 22 | f.user !== undefined && canAdmin(f.db, repo, f.user) && isReadOnlyMirror(f.app, repo); | |
| 23 | ||
| 24 | 22 | export function readGrantsScreen(f: Session, ctx: Ctx, repo: Repo): Screen { |
| 25 | 23 | const state = new ListState(); |
| 26 | 24 | const where = `${repo.ownerName}/${repo.name}`; |
| 27 | const rows = () => (mayGrantRead(f, repo) ? listGrants(f.db, repo.id) : []); | |
| 25 | const rows = () => ((holds(f.db, principalOfUser(f.user), "repo.admin", { repo }) && isReadOnlyMirror(f.app, repo)) ? listGrants(f.db, repo.id) : []); | |
| 28 | 26 | const screen: Screen = { |
| 29 | 27 | title: `${where} — Who may read this`, |
| 30 | 28 | keys: [binding(["j", "k"], "move cursor"), binding(["a"], "grant an app"), binding(["c"], "grant a crew member"), binding(["x"], "revoke")], |
| 31 | 29 | render(area, s) { |
| 32 | 30 | const c = ctx.theme.c; |
| 33 | 31 | const [head, list] = split(area, "v", [len(1), fill(1)]); |
| 34 | const said = mayGrantRead(f, repo) | |
| 32 | const said = (holds(f.db, principalOfUser(f.user), "repo.admin", { repo }) && isReadOnlyMirror(f.app, repo)) | |
| 35 | 33 | ? "Grants are reads only. a grants one of your apps, c a crew member, x revokes." |
| 36 | 34 | : "Only the admin of a mirror of a read-only origin grants reads."; |
| 37 | 35 | s.text(head!.x, head!.y, truncate(said, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); |
| @@ -42,7 +40,7 @@ export function readGrantsScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 42 | 40 | const all = rows(); |
| 43 | 41 | if (state.key(e, all.length)) return true; |
| 44 | 42 | if (e.ctrl || e.alt || (e.key !== "a" && e.key !== "c" && e.key !== "x")) return false; |
| 45 | if (!mayGrantRead(f, repo)) { | |
| 43 | if (!(holds(f.db, principalOfUser(f.user), "repo.admin", { repo }) && isReadOnlyMirror(f.app, repo))) { | |
| 46 | 44 | ctx.toast(GRANT_ERRORS.not_read_only, "danger"); |
| 47 | 45 | return true; |
| 48 | 46 | } |
| @@ -87,7 +85,7 @@ export function readGrantsScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 87 | 85 | |
| 88 | 86 | /** The palette's command while a mirror the viewer administers is open. */ |
| 89 | 87 | export function readGrantsCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| 90 | if (repo === undefined || !mayGrantRead(f, repo)) return []; | |
| 88 | if (repo === undefined || !(holds(f.db, principalOfUser(f.user), "repo.admin", { repo }) && isReadOnlyMirror(f.app, repo))) return []; | |
| 91 | 89 | return [ |
| 92 | 90 | { |
| 93 | 91 | id: "read-grants", |
src/web/chrome.ts +4 −2
| @@ -8,6 +8,9 @@ | ||
| 8 | 8 | * `ui.ts` may not. That is the line between the two files. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { holds } from "../core/may.ts"; | |
| 12 | import { principalOfUser } from "../core/principal.ts"; | |
| 13 | import { forgeCeiling } from "../flow/ceiling.ts"; | |
| 11 | 14 | import { togetherHtml } from "./together.ts"; |
| 12 | 15 | import { repoOnRequest } from "../http/request_repo.ts"; |
| 13 | 16 | import { hereAddress, returnTo, safeNext, withReturn } from "./return_to.ts"; |
| @@ -33,7 +36,6 @@ import { keptBehind, MINE_ANCHOR, ownsInTree } from "../core/following.ts"; | ||
| 33 | 36 | import { html, raw, when, type Html } from "./html.ts"; |
| 34 | 37 | import { clamp } from "./clamp.ts"; |
| 35 | 38 | import { autonomyStatus } from "../crew/autonomy_status.ts"; |
| 36 | import { mayRaiseCeiling } from "../actions/crew_ceiling.ts"; | |
| 37 | 39 | import { stopWords } from "../crew/stop_words.ts"; |
| 38 | 40 | import { icon } from "./icons.ts"; |
| 39 | 41 | import { seesAnyBox } from "../games/store.ts"; |
| @@ -401,7 +403,7 @@ export function scopeHeader( | ||
| 401 | 403 | export function crewStopLine(ctx: Ctx, repo: Repo, base: string): Html { |
| 402 | 404 | const w = stopWords(autonomyStatus(ctx.app, repo)); |
| 403 | 405 | const raise = |
| 404 | w.raiseTo !== undefined && mayRaiseCeiling(ctx.app, ctx.auth.user) | |
| 406 | w.raiseTo !== undefined && (holds(ctx.app.db, principalOfUser(ctx.auth.user), "forge.administer") && forgeCeiling(ctx.app.config) !== null) | |
| 405 | 407 | ? html` <form method="post" action="${base}/settings/autonomy/raise" class="inline" data-in-place><input type="hidden" name="to" value="${w.raiseTo}"><button type="submit">Raise to $${w.raiseTo}</button></form>` |
| 406 | 408 | : null; |
| 407 | 409 | return html`<p class="${w.stopped ? "small" : "muted small"}" data-crew-line data-fragment="${base}/settings/crew/line" role="status">${w.words}${w.fix === null ? null : html` <a href="${base}/settings/autonomy">${w.fix}</a>`}${raise}</p>`; |
src/web/pages/boards-view.ts +18 −2
| @@ -7,6 +7,12 @@ | ||
| 7 | 7 | * No client framework. Every form posts to `boards-edit.ts`. Anyone but a |
| 8 | 8 | * person who is an admin gets the not-found page. |
| 9 | 9 | */ |
| 10 | import type { Database } from "bun:sqlite"; | |
| 11 | import { getRepo } from "../../core/repos.ts"; | |
| 12 | import type { User } from "../../core/users.ts"; | |
| 13 | import { ownRepoPath } from "../../kernel/own_repo.ts"; | |
| 14 | import { holds } from "../../core/may.ts"; | |
| 15 | import { principalOfUser } from "../../core/principal.ts"; | |
| 10 | 16 | import { checkSlotsFold } from "./boards-slots.ts"; |
| 11 | 17 | import { CHART_NAMES } from "../../boards/chart.ts"; |
| 12 | 18 | import { isSlug, MAX_H, MAX_PANELS, MAX_TITLE, MAX_W, RANGES, type Board, type Panel } from "../../boards/store.ts"; |
| @@ -31,7 +37,7 @@ import { formatValue } from "../../boards/chart.ts"; | ||
| 31 | 37 | import { boardsIndexLiveJs } from "../boards-index-live.ts"; |
| 32 | 38 | import { flowPanel, outAsked } from "./flow-panel.ts"; |
| 33 | 39 | import { boardsHoldsCard } from "./boards-holds.ts"; |
| 34 | import { alarmLines, mayMergeOwn } from "../studio/alarm_lines.ts"; | |
| 40 | import { alarmLines } from "../studio/alarm_lines.ts"; | |
| 35 | 41 | import { boardPicture, boardsPicture, isFailed, LONG_WAIT_MS, waitAnswer } from "../../flow/pages.ts"; |
| 36 | 42 | import { isPinned, listPins } from "../../boards/pins.ts"; |
| 37 | 43 | import { boardMarks } from "../../boards/marks.ts"; |
| @@ -90,6 +96,16 @@ function grid(app: App, slug: string, board: Board, panels: readonly PanelDrawn[ | ||
| 90 | 96 | </section>`; |
| 91 | 97 | } |
| 92 | 98 | |
| 99 | /** | |
| 100 | * Merging into the forge's own repository is a person's act: an agent proposes and is shown no | |
| 101 | * Merge button. | |
| 102 | */ | |
| 103 | function mergesOwn(db: Database, user: User): boolean { | |
| 104 | const [owner, name] = ownRepoPath().split("/"); | |
| 105 | const repo = owner && name ? getRepo(db, owner, name) : undefined; | |
| 106 | return repo !== undefined && holds(db, principalOfUser(user), "repo.write_person", { repo }); | |
| 107 | } | |
| 108 | ||
| 93 | 109 | const denied = (ctx: Ctx) => !personAdminPage(ctx); |
| 94 | 110 | |
| 95 | 111 | /** |
| @@ -161,7 +177,7 @@ export async function boardsList(ctx: Ctx): Promise<Response> { | ||
| 161 | 177 | </section>`; |
| 162 | 178 | const drift = driftSection(picture.drifting ?? []); |
| 163 | 179 | const flow = timePhase(ctx.request, "flow", () => |
| 164 | flowPanel(ctx.app, { kind: "owner" }, ctx.url, "/boards", { picture, refetch: false, now: html`${liveLine(ctx.url.searchParams.has("pause"))}${alarmLines(picture.alarms, mayMergeOwn(ctx.app.db, user))}`, between: boards, first: drift, last: html`${checkSlotsFold(ctx.app)}${boardsHoldsCard(ctx.app.db, user, true)}` })); | |
| 180 | flowPanel(ctx.app, { kind: "owner" }, ctx.url, "/boards", { picture, refetch: false, now: html`${liveLine(ctx.url.searchParams.has("pause"))}${alarmLines(picture.alarms, mergesOwn(ctx.app.db, user))}`, between: boards, first: drift, last: html`${checkSlotsFold(ctx.app)}${boardsHoldsCard(ctx.app.db, user, true)}` })); | |
| 165 | 181 | const rendering = performance.now(); |
| 166 | 182 | const response = page({ |
| 167 | 183 | ctx, |
src/web/studio/alarm_lines.ts −13
| @@ -8,10 +8,7 @@ import type { Database } from "bun:sqlite"; | ||
| 8 | 8 | import { alarmBackup } from "../../flow/alarm_backup.ts"; |
| 9 | 9 | import type { Waiting } from "../../flow/alarm_lane.ts"; |
| 10 | 10 | import { firedAlarms, type FiredAlarm } from "../../flow/alarms.ts"; |
| 11 | import { canWrite, getRepo } from "../../core/repos.ts"; | |
| 12 | import type { User } from "../../core/users.ts"; | |
| 13 | 11 | import { writeStamp } from "../../core/write_clock.ts"; |
| 14 | import { ownRepoPath } from "../../kernel/own_repo.ts"; | |
| 15 | 12 | import { Stamped } from "../../kernel/stamped.ts"; |
| 16 | 13 | import { html, type Html } from "../html.ts"; |
| 17 | 14 | import { btn, row, rowList } from "../ui.ts"; |
| @@ -83,13 +80,3 @@ export function alarmLines(alarms: readonly FiredAlarm[], mayMerge = false): Htm | ||
| 83 | 80 | </div>`; |
| 84 | 81 | } |
| 85 | 82 | |
| 86 | /** | |
| 87 | * Whether `user` may merge into the forge's own repository: the lane alarm's Merge buttons are | |
| 88 | * theirs. Merging is a person's act; an agent proposes and is never shown one. | |
| 89 | */ | |
| 90 | export function mayMergeOwn(db: Database, user: User): boolean { | |
| 91 | if (user.kind === "agent") return false; | |
| 92 | const [owner, name] = ownRepoPath().split("/"); | |
| 93 | const repo = owner && name ? getRepo(db, owner, name) : undefined; | |
| 94 | return repo !== undefined && canWrite(db, repo, user); | |
| 95 | } |
src/web/studio/review_start.ts +4 −9
| @@ -6,11 +6,12 @@ | ||
| 6 | 6 | * again (`retryFailedStart`), posted under `/pulls/:number/review-retry`. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { holds } from "../../core/may.ts"; | |
| 10 | import { principalOfUser } from "../../core/principal.ts"; | |
| 9 | 11 | import type { Database } from "bun:sqlite"; |
| 10 | 12 | import { mayView } from "../../core/sealed.ts"; |
| 11 | 13 | import { getPull, type Pull } from "../../core/pulls.ts"; |
| 12 | import { canWrite, type Repo } from "../../core/repos.ts"; | |
| 13 | import type { User } from "../../core/users.ts"; | |
| 14 | import type { Repo } from "../../core/repos.ts"; | |
| 14 | 15 | import { retryFailedStart, waitsForPerson, type RetryOutcome } from "../../crew/review.ts"; |
| 15 | 16 | import { reviewSays } from "../../crew/review_says.ts"; |
| 16 | 17 | import type { Ctx } from "../../http/context.ts"; |
| @@ -28,13 +29,7 @@ export const RETRY_WORDS: Record<RetryOutcome, string> = { | ||
| 28 | 29 | wait: "Review could not be sent just now: a review is out, or the crew cannot run. Try again shortly.", |
| 29 | 30 | }; |
| 30 | 31 | |
| 31 | /** | |
| 32 | * The people the re-run lets through, on the page and in the terminal: a person who writes here. | |
| 33 | */ | |
| 34 | export const mayRetryReview = (db: Database, repo: Repo, user: User | undefined): boolean => | |
| 35 | user !== undefined && user.kind === "user" && canWrite(db, repo, user); | |
| 36 | ||
| 37 | const mayRetry = (ctx: Ctx, repo: Repo): boolean => mayRetryReview(ctx.app.db, repo, ctx.auth.user); | |
| 32 | const mayRetry = (ctx: Ctx, repo: Repo): boolean => holds(ctx.app.db, principalOfUser(ctx.auth.user), "repo.write_person", { repo }); | |
| 38 | 33 | |
| 39 | 34 | /** |
| 40 | 35 | * Whether this pull reads "review failed to start": an open agent pull whose two review runs never |
test/flow-alarm-lane.test.ts +4 −2
| @@ -1,4 +1,6 @@ | ||
| 1 | 1 | /** The lane has stopped (#11507): ten open pulls, 91 minutes without a merge and one repeated failure line raise exactly one alarm; a merge clears it. */ |
| 2 | import { holds } from "../src/core/may.ts"; | |
| 3 | import { principalOfUser } from "../src/core/principal.ts"; | |
| 2 | 4 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 3 | 5 | import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | 6 | import { tmpdir } from "node:os"; |
| @@ -13,7 +15,7 @@ import { laneStopped } from "../src/crew/sentinel_lane.ts"; | ||
| 13 | 15 | import { firedAlarms } from "../src/flow/alarms.ts"; |
| 14 | 16 | import { forgeFailed, laneAlarm, laneMinutes, maskLine } from "../src/flow/alarm_lane.ts"; |
| 15 | 17 | import { id } from "../src/kernel/id.ts"; |
| 16 | import { alarmLines, mayMergeOwn } from "../src/web/studio/alarm_lines.ts"; | |
| 18 | import { alarmLines } from "../src/web/studio/alarm_lines.ts"; | |
| 17 | 19 | import { waitingLines } from "../src/tui/screens/flow.ts"; |
| 18 | 20 | |
| 19 | 21 | const NOW = new Date("2026-11-12T17:11:00.000Z"); |
| @@ -413,7 +415,7 @@ describe("the lane alarm's green pulls carry a Merge action (#18339)", () => { | ||
| 413 | 415 | ]); |
| 414 | 416 | const fired = lane(); |
| 415 | 417 | expect(fired[0]!.waiting).toEqual(alarm.waiting!); |
| 416 | expect(mayMergeOwn(app.db, owner())).toBe(true); | |
| 418 | expect(holds(app.db, principalOfUser(owner()), "repo.write_person", { repo: getRepo(app.db, "trevato", "forge")! })).toBe(true); | |
| 417 | 419 | const out = String(alarmLines(fired, true)); |
| 418 | 420 | for (const n of [na, nb]) { |
| 419 | 421 | expect(out).toContain(`<a href="/trevato/forge/pulls/${n}" class="row"`); |
test/may-only.test.ts +16 −10
| @@ -17,7 +17,7 @@ import { createRepo } from "../src/actions/repos.ts"; | ||
| 17 | 17 | import { createApp, type App } from "../src/app.ts"; |
| 18 | 18 | import { holds } from "../src/core/may.ts"; |
| 19 | 19 | import { principalOfUser } from "../src/core/principal.ts"; |
| 20 | import { canAdmin, getRepo, type Repo } from "../src/core/repos.ts"; | |
| 20 | import { canAdmin, canWrite, getRepo, type Repo } from "../src/core/repos.ts"; | |
| 21 | 21 | import { createUser, type User } from "../src/core/users.ts"; |
| 22 | 22 | import { promote } from "./helpers/members.ts"; |
| 23 | 23 | |
| @@ -54,12 +54,10 @@ const NOT_ACCESS: Readonly<Record<string, string>> = { | ||
| 54 | 54 | */ |
| 55 | 55 | const STILL_TO_FOLD: readonly string[] = [ |
| 56 | 56 | "actions/blocked_words.ts canAnswer", |
| 57 | "actions/crew_ceiling.ts mayRaiseCeiling", | |
| 58 | 57 | "actions/destination.ts mayChangeDestination", |
| 59 | 58 | "actions/devices.ts mayManageDevices", |
| 60 | 59 | "actions/issues.ts mayEditIssue", |
| 61 | 60 | "actions/issues.ts maySetSealed", |
| 62 | "actions/planner_switch.ts maySwitch", | |
| 63 | 61 | "actions/places.ts mayPin", |
| 64 | 62 | "actions/runs.ts mayReadLogOfRun", |
| 65 | 63 | "actions/runs.ts mayReadRunLog", |
| @@ -103,25 +101,18 @@ const STILL_TO_FOLD: readonly string[] = [ | ||
| 103 | 101 | "release/gate.ts mayRollBack", |
| 104 | 102 | "security/accept.ts mayAct", |
| 105 | 103 | "security/optin.ts mayAsk", |
| 106 | "tui/screens/accountorder.ts mayOrder", | |
| 107 | "tui/screens/atlas.ts mayPlan", | |
| 108 | 104 | "tui/screens/builds.ts mayPin", |
| 109 | 105 | "tui/screens/can.ts canScreen", |
| 110 | 106 | "tui/screens/crewdevices.ts mayManageDevices", |
| 111 | "tui/screens/crewswitch.ts maySwitchCrew", | |
| 112 | "tui/screens/dataimport.ts mayImport", | |
| 113 | 107 | "tui/screens/fleet.ts mayAct", |
| 114 | 108 | "tui/screens/prompts.ts mayManagePrompts", |
| 115 | 109 | "tui/screens/quarantine.ts mayReview", |
| 116 | "tui/screens/readgrants.ts mayGrantRead", | |
| 117 | 110 | "tui/screens/returns.ts mayReadReturns", |
| 118 | 111 | "tui/screens/runlist.ts maySteer", |
| 119 | 112 | "web/pages/fleet.ts canAct", |
| 120 | 113 | "web/pages/growth_panel.ts isAdmin", |
| 121 | 114 | "web/pages/looks.ts mayFetchLook", |
| 122 | "web/studio/alarm_lines.ts mayMergeOwn", | |
| 123 | 115 | "web/studio/answers.ts canSeeAnswers", |
| 124 | "web/studio/review_start.ts mayRetryReview", | |
| 125 | 116 | "games/game_may.ts mayOnGame", |
| 126 | 117 | ]; |
| 127 | 118 | |
| @@ -198,3 +189,18 @@ test("an org-kind admin holds forge.administer_person, which mayRunners once ref | ||
| 198 | 189 | expect(holds(app.db, principalOfUser(org), "forge.administer_person")).toBe(true); |
| 199 | 190 | expect(holds(app.db, principalOfUser({ ...org, kind: "agent" }), "forge.administer_person")).toBe(false); |
| 200 | 191 | }); |
| 192 | ||
| 193 | test("repo.admin_person and repo.write_person answer what the person-only wrappers did: the rule, and never an agent", () => { | |
| 194 | const as = (u: User, kind: User["kind"]): User => ({ ...u, kind }); | |
| 195 | for (const base of [users["boss"]!, users["nina"]!]) | |
| 196 | for (const kind of ["user", "agent"] as const) { | |
| 197 | const u = as(base, kind); | |
| 198 | const p = principalOfUser(u); | |
| 199 | // maySwitch, maySwitchCrew, mayImport: `kind !== "agent" && canAdmin`. | |
| 200 | expect(holds(app.db, p, "repo.admin_person", { repo }), `${u.username} ${kind} admin`).toBe(kind !== "agent" && canAdmin(app.db, repo, u)); | |
| 201 | // mayOrder, mayMergeOwn: `kind !== "agent" && canWrite`. | |
| 202 | expect(holds(app.db, p, "repo.write_person", { repo }), `${u.username} ${kind} write`).toBe(kind !== "agent" && canWrite(app.db, repo, u)); | |
| 203 | } | |
| 204 | expect(holds(app.db, principalOfUser(undefined), "repo.admin_person", { repo })).toBe(false); | |
| 205 | expect(holds(app.db, principalOfUser(undefined), "repo.write_person", { repo })).toBe(false); | |
| 206 | }); |
new above
offline