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

A waiting person has one button, Let in, and a person stopped by a page can Ask for Host or Build #18578

opened this

Merged 9m ago, goes live with the next release

torque/forge:torque/18477-a-waiting-person-has-one-button-let-in-a → main 0 commits fork 1 thread · 1 unresolved

  • Merged. torque/18477-a-waiting-person-has-one-button-let-in-a was merged into main as 2a18773.

Review

Sign in to review this change.
31 files changed +795 −71
docs/design/quiet-debt.json +1 −2
@@ -506,8 +506,7 @@
506506 "bare-list": 2
507507 },
508508 "src/web/requests_card.ts": {
509 "bare-list": 1,
510 "row-primary": 1
509 "bare-list": 1
511510 },
512511 "src/web/settings/devices.ts": {
513512 "bare-list": 4,
docs/features/blocked-by.md +2 −2
@@ -36,7 +36,7 @@ A button on a page posts the ask as a form to the page's own route, with the act
3636 A reader who cannot change it is offered one action, and there are two, by who holds the control:
3737
3838 - **The host of this forge** (a name its gate has not opened): `POST /api/v1/reach/asks`, `docs/features/ask-to-reach.md`.
39 - **An admin of this forge, or of one repository**: `POST /api/v1/asks/admin { want, subject }` (`src/actions/ask_admin.ts`). `want` is one of a fixed list (`WANTS`, `src/actions/blocked_words.ts`): a model grant, a model account, a spend ceiling, a model key, a private destination, an email verified, membership, the telemetry grant, an agent, a host for a person's own model connection, a repository's crew. Each names the exact control, with the page's own anchor on the field (`/settings/accounts/bob#f-grant`, `/settings/crew#crew-key`).
39 - **An admin of this forge, or of one repository**: `POST /api/v1/asks/admin { want, subject }` (`src/actions/ask_admin.ts`). `want` is one of a fixed list (`WANTS`, `src/actions/blocked_words.ts`): a model grant, a model account, a spend ceiling, a model key, a private destination, an email verified, Build or Host (answered on People), the telemetry grant, an agent, a host for a person's own model connection, a repository's crew. Each names the exact control, with the page's own anchor on the field (`/settings/accounts/bob#f-grant`, `/settings/crew#crew-key`).
4040
4141 What happens when a person presses the button:
4242
@@ -57,7 +57,7 @@ A run's summary, a park comment and a log line are read by anyone. They are stor
5757 - Model keys, grants, accounts, ceilings and budgets: a run's stop (`src/crew/runner.ts`, `forge_budget.ts`, `src/core/account_ceiling.ts`, `subscriptions.ts`), the key card on every page that draws it, "Land it as it is", Settings → Connect your AI, and talking to the forge's agent (page, API, MCP `say`).
5858 - A private destination an app asks for: both rows on the app's settings, and the gate's own refusal.
5959 - Mail: no mail, and the day's mail spent (the resend on Settings, the API, MCP `email_verify`).
60 - A guest proposing a change (membership), no agents on this forge, the telemetry grant (MCP `flow`, `system`, `telemetry_history`), a repository's crew (MCP `crew`).
60 - A guest proposing a change (Build), no agents on this forge, the telemetry grant (MCP `flow`, `system`, `telemetry_history`), a repository's crew (MCP `crew`).
6161 - A hosted forge refused by its host's gate (`gateBlocked`).
6262
6363 ## What is held
docs/features/people.md +5 −2
@@ -1,6 +1,6 @@
11 ---
22 topic: Every setting, by topic
3 row: People: invite, who is here and what each can do, one line each with Remove
3 row: People: invite, let in, who is here and what each can do, one line each with Remove
44 ---
55 # People
66
@@ -10,4 +10,7 @@ row: People: invite, who is here and what each can do, one line each with Remove
1010 - **Mail**: one line says whether this forge can send mail. Without it a newcomer cannot prove an address until you verify them (`src/web/pages/people_cards.ts`, with who waits to be let in and who could not sign in without the platform edge).
1111 - **A person** is one row: their role badge, when they were seen, how their account was proved and by whom (a fact for each thing proved), then, under it, one line for each thing they can do (every grant, `src/core/grants_view.ts`). **Remove** on a line takes just that away, in place: the person's block is fetched again from `/settings/people/row/<name>`. Removable lines: membership, the model allowance, reading telemetry and one app they were let into (`src/actions/take_away.ts`, asked through `may("forge.administer")`). Other lines link to where they are changed. An owner keeps what they have, so the forge is never left without one. **Manage** opens the person's page (`/settings/accounts/<name>`: sign-ins, ceilings, suspend, verify, remove the account).
1212
13 In the terminal, People (`src/tui/screens/people.ts`) takes one thing away with `x` (a name, then `member`, `model_grant` or `telemetry_grant`, or `app` and the app's name). Invite links (`src/tui/screens/invites.ts`) lists each invite with its state; `c` shows a waiting link, `n` makes a new one like the selected (Send again), `x` revokes. Mail is said only when it cannot be sent.
13 - **Let in** is the one button for a person who waits: one who asked for an account (the Waiting card) or whose account is not proved. Beside it is the bundle to give them (Use, Build, or Host on the first machine the forge offers, 3 containers and 2048 MB). It proves the account (recorded as proved by you, `how: let_in`), lets in one who asked, and applies the bundle (`src/actions/let_in.ts`, `giveBundle` in `src/core/bundle_grants.ts`). It sends no mail and needs none, so it works with mail off. Decline stays on the Waiting card.
14 - **Asks** (`src/web/let_in_card.ts`): a person stopped by a page for lack of Build (a fork, make it yours) or Host (their settings, when the forge offers a machine) sees **Ask for Build** or **Ask for Host**. It adds one row under Asks with **Approve** (applies the bundle) and **Decline** (removes the row). The ask grants nothing itself: only an administrator, decided by `may("forge.administer")`, answers. Both answers are events (`ask.approved`, `ask.declined`; Let in is `account.let_in`).
15
16 In the terminal, People (`src/tui/screens/people.ts`) takes one thing away with `x` (a name, then `member`, `model_grant` or `telemetry_grant`, or `app` and the app's name). Invite links (`src/tui/screens/invites.ts`) lists each invite with its state; `c` shows a waiting link, `n` makes a new one like the selected (Send again), `x` revokes. Mail is said only when it cannot be sent. `l` lets a person in (a name, then use, build or host), `a` and `d` approve or decline an ask (build or host, then the name); a line above the list names who asks.
docs/features/request-access.md +3 −3
@@ -16,16 +16,16 @@ row: Request access
1616 Invite links keep working in every mode but `closed`; in `request` an open invite is a vouch, so its holder starts at once.
1717
1818 ## A stranger
19 `/signup` in `request` mode asks for a username, a password or passkey, and an optional "What do you want to build?". The account is made *waiting* (`user.waiting_at`): `isActive` is false, so no session, token, key or password opens anything. They land on `/signup/requested`: "Your request is in. Someone who runs this forge will look at it; you can close this page and sign in later to check." Signing in (password or passkey) while waiting shows the wait and starts no session; after Decline it says so politely. After Allow the next sign-in works, and home says "You're in." once.
19 `/signup` in `request` mode asks for a username, a password or passkey, and an optional "What do you want to build?". The account is made *waiting* (`user.waiting_at`): `isActive` is false, so no session, token, key or password opens anything. They land on `/signup/requested`: "Your request is in. Someone who runs this forge will look at it; you can close this page and sign in later to check." Signing in (password or passkey) while waiting shows the wait and starts no session; after Decline it says so politely. After Let in the next sign-in works, and home says "You're in." once.
2020
2121 `POST /api/v1/users` answers `202 {state:"waiting", username, message}`; it takes `note` and `from` (the forge or agent asking). The terminal's create screen says the same sentence.
2222
2323 ## The admin
2424 - The notifier sends a line for each of the first three waiting requests, then one count line ("N people ask for an account") that moves only every 25 more (`crew/notify.ts`, `requestLines`), linking to the Waiting list.
2525 - The terminal's **Waiting** screen (palette, `src/tui/screens/requests.ts`): `a` allows, `d` declines, through the same actions.
26 - The **Waiting** list is on top of Settings → Accounts and in home's "Needs you": name, note, when, from where, with **Allow** and **Decline** one tap each.
26 - The **Waiting** list is on top of Settings → Accounts and in home's "Needs you": name, note, when, from where, with **Let in** (a bundle beside it, Use by default) and **Decline** one tap each. In the terminal, Waiting has `l` and `d`.
2727 - API: `GET /api/v1/admin/requests`, `POST /api/v1/admin/requests/:username/allow|decline`; MCP: `account_requests`.
28 - Allow makes the person a member (small quotas, no model grant: the crew spends nothing until an admin gives credits). Decline keeps the record (`account_request`).
28 - Let in (the API and MCP still call it allow) makes the person a member (small quotas, no model grant: the crew spends nothing until an admin gives credits). Decline keeps the record (`account_request`).
2929
3030 ## Limits
3131 At most 200 requests wait (`WAITING_CAP`): past that a stranger meets the closed door, except one holding an open invite, until the admin answers some. Updating a forge that stored `closed` leaves it `closed`; the migration changes no setting.
src/actions/ask_admin.ts +6 −1
@@ -26,6 +26,7 @@ import {
2626 waitingAdminAsks,
2727 type AdminAsk,
2828 } from "../core/admin_ask.ts";
29 import { hostGrantOf } from "../core/bundle_grants.ts";
2930 import { getModelGrant, ownSubscription } from "../core/model_grant.ts";
3031 import { canAdmin, canRead, getRepoById } from "../core/repos.ts";
3132 import { roleOf } from "../core/roles.ts";
@@ -126,10 +127,14 @@ function met(app: App, a: AdminAsk): boolean {
126127 const u = who();
127128 return u !== undefined && (getModelGrant(app.db, u.id) !== undefined || ownSubscription(app.db, u.id) !== undefined);
128129 }
129 case "membership": {
130 case "build": {
130131 const u = who();
131132 return u !== undefined && roleOf(app.db, u) !== "guest";
132133 }
134 case "host": {
135 const u = who();
136 return u !== undefined && hostGrantOf(app.db, u.id) !== undefined;
137 }
133138 case "verify_email": {
134139 const u = who();
135140 return u !== undefined && emailVerified(app.db, u.id);
src/actions/blocked_words.ts +19 −5
@@ -122,13 +122,21 @@ export const WANTS = {
122122 ask: "Ask an admin to verify you",
123123 asks: (s) => `asks to have ${s}'s email verified: this forge could not send the link`,
124124 },
125 membership: {
125 build: {
126126 audience: "forge",
127127 subject: "account",
128 control: (s) => ({ href: `${account(s)}#actions`, label: `Make ${s} a member` }),
128 control: () => ({ href: "/settings/people#people", label: "Approve Build on People" }),
129129 can: "make you one",
130 ask: "Ask an admin to make you a member",
131 asks: (s) => `asks for ${s} to be made a member`,
130 ask: "Ask for Build",
131 asks: (s) => `asks for Build for ${s}: to make repositories and apps and run a crew`,
132 },
133 host: {
outdated

Finding 1: build duplicates membership just above. Two asks for one thing, and old membership asks can no longer be approved through People. Keep one.

134 audience: "forge",
135 subject: "account",
136 control: () => ({ href: "/settings/people#people", label: "Approve Host on People" }),
137 can: "give you Host",
138 ask: "Ask for Host",
139 asks: (s) => `asks for Host for ${s}: to run containers on one of this forge's machines`,
132140 },
133141 telemetry_grant: {
134142 audience: "forge",
@@ -275,7 +283,13 @@ export const FORK_NEEDS_MEMBER = "Proposing a change makes a fork, and forks are
275283
276284 /** A fork is a member's to make. */
277285 export function notMemberBlocked(app: App, reader: User, says: string): Blocked {
278 return wayTo(app, reader, "membership", says, reader.username);
286 return wayTo(app, reader, "build", says, reader.username);
287 }
288
289 /** Running containers on this forge's machines is Host, which an admin approves. */
290 export const NO_HOST = "Running containers on this forge's machines is for those given Host.";
291 export function noHostBlocked(app: App, reader: User): Blocked {
292 return wayTo(app, reader, "host", NO_HOST, reader.username);
279293 }
280294
281295 /** A private destination waits for a site admin's grant. */
src/actions/let_in.ts added +125
@@ -0,0 +1,125 @@
1 /**
2 * Let in: the one button for a person who waits, whether their account is unproven or they asked
3 * for one. It proves the account (no mail is sent, none is needed), lets in a person who asked,
4 * and applies the bundle picked beside it (`core/bundles.ts`): Use, Host or Build. Asked through
5 * `may("forge.administer")`; every door calls `letIn`.
6 *
7 * Also here: the bundle a person asked for from a page that stopped them (`build`, `host` in
8 * `blocked_words.ts`), answered on People by `approveAsk` (applies the bundle) or `declineAsk`
9 * (removes the row). A request grants nothing by itself: only an administrator's Approve does.
10 */
11
12 import type { App } from "../app.ts";
13 import type { AccountRow } from "../core/accounts.ts";
14 import { answerAdminAsk, removeAdminAsk, waitingAdminAsks } from "../core/admin_ask.ts";
15 import { BUNDLES, DEFAULT_BUNDLE, HOST_DEFAULTS, parseHost, type Bundle, type HostChoice } from "../core/bundles.ts";
16 import { giveBundle } from "../core/bundle_grants.ts";
17 import { may } from "../core/may.ts";
18 import { principalOfUser } from "../core/principal.ts";
19 import { requestOf } from "../core/requests.ts";
20 import { getUserByName, type User } from "../core/users.ts";
21 import { markVerified } from "../core/verify.ts";
22 import { err, ok, type Result } from "../kernel/result.ts";
23 import { BUNDLE_WORDS, hostMachines, type BundleInput } from "./invites.ts";
24 import { allowRequest } from "./requests.ts";
25
26 export type LetInError = "not_found" | "not_allowed" | "invalid_bundle" | "no_machine" | "invalid_machine" | "invalid_cap";
27
28 export const LET_IN_WORDS: Record<Exclude<LetInError, "not_found">, string> = {
29 not_allowed: "An admin, an agent or an organization needs no letting in.",
30 ...BUNDLE_WORDS,
31 };
32
33 /** Asked as the administrator `may()` knows: a person, never an agent. */
34 function administrator(app: App, actor: User | undefined): actor is User {
35 return actor !== undefined && actor.kind === "user" && may(app.db, principalOfUser(actor), "forge.administer").ok;
36 }
37
38 /** The bundle and, for Host, its machine and caps, as a door sends them. */
39 function choose(app: App, actor: User, choice: BundleInput): Result<{ bundle: Bundle; host?: HostChoice }, LetInError> {
40 const wanted = choice.bundle === undefined || choice.bundle === null || choice.bundle === "" ? DEFAULT_BUNDLE : choice.bundle;
41 if (!BUNDLES.includes(wanted as Bundle)) return err("invalid_bundle");
42 if (wanted !== "host") return ok({ bundle: wanted as Bundle });
43 const h = parseHost(choice, hostMachines(app, actor));
44 if (!h.ok) return err(h.error === "noMachine" ? "no_machine" : h.error === "badMachine" ? "invalid_machine" : "invalid_cap");
45 return ok({ bundle: "host", host: h.value });
46 }
47
48 /**
49 * Whether an account shows Let in: a person, not an admin, whose request waits or whose email is
50 * not proved.
51 */
52 export const waitsToBeLetIn = (a: Pick<AccountRow, "kind" | "isAdmin" | "removedAt" | "waiting" | "verified">): boolean =>
53 a.kind === "user" && !a.isAdmin && a.removedAt === null && (a.waiting || !a.verified);
54
55 export function letIn(app: App, actor: User | undefined, username: string, choice: BundleInput = {}): Result<{ username: string; bundle: Bundle }, LetInError> {
56 if (!administrator(app, actor)) return err("not_found");
57 const user = getUserByName(app.db, username);
58 if (user === undefined || user.kind === "org") return err("not_found");
59 if (user.kind === "agent" || user.isAdmin) return err("not_allowed");
60 const chosen = choose(app, actor, choice);
61 if (!chosen.ok) return chosen;
62 // One transaction: a person is let in whole or not at all.
63 app.db.transaction(() => {
64 if (requestOf(app.db, user.id)?.state === "waiting") allowRequest(app, actor, user.username);
65 markVerified(app.db, user.id, new Date().toISOString(), { by: actor.id, how: "let_in" });
66 giveBundle(app.db, user.id, chosen.value.bundle, actor.id, chosen.value.host);
67 })();
68 app.bus.append({ kind: "account.let_in", actorId: actor.id, payload: { username: user.username, bundle: chosen.value.bundle } });
69 return ok({ username: user.username, bundle: chosen.value.bundle });
70 }
71
72 /** The wants that ask for a bundle, by the bundle each stands for. */
73 export const BUNDLE_WANTS: Readonly<Record<string, Bundle>> = { build: "build", host: "host" };
74
75 /** A person's request for Host or Build, waiting for an administrator. */
76 export interface BundleAsk {
77 readonly username: string;
78 readonly bundle: Bundle;
79 readonly askedAt: string;
80 }
81
82 /**
83 * Who asked for Host or Build and has not been answered, oldest first; an administrator's to read.
84 */
85 export function bundleAsks(app: App, actor: User | undefined): BundleAsk[] {
86 if (!administrator(app, actor)) return [];
87 return waitingAdminAsks(app.db)
88 .filter((a) => Object.hasOwn(BUNDLE_WANTS, a.want))
89 .map((a) => ({ username: a.username, bundle: BUNDLE_WANTS[a.want]!, askedAt: a.askedAt }));
90 }
91
92 export type AnswerError = "not_found" | "gone" | LetInError;
93
94 /**
95 * Approve: the asker gets the bundle they asked for. Host takes the machine and caps from `choice`.
96 */
97 export function approveAsk(app: App, actor: User | undefined, username: string, want: string, choice: BundleInput = {}): Result<BundleAsk, AnswerError> {
98 if (!administrator(app, actor)) return err("not_found");
99 const bundle = BUNDLE_WANTS[want];
100 const asker = getUserByName(app.db, username);
101 if (bundle === undefined || asker === undefined) return err("not_found");
102 const ask = waitingAdminAsks(app.db).find((a) => a.userId === asker.id && a.want === want);
103 if (ask === undefined) return err("gone");
104 // Host without a pick is the first machine on offer at the usual caps, the form's defaults.
105 const host = bundle === "host" && choice.machine === undefined ? { machine: hostMachines(app, actor)[0], ...HOST_DEFAULTS } : choice;
106 const chosen = choose(app, actor, { ...host, bundle });
107 if (!chosen.ok) return chosen;
108 app.db.transaction(() => {
109 giveBundle(app.db, asker.id, bundle, actor.id, chosen.value.host);
110 answerAdminAsk(app.db, { userId: asker.id, want, subject: ask.subject, state: "done", by: actor.id });
111 })();
112 app.bus.append({ kind: "ask.approved", actorId: actor.id, payload: { want, who: asker.username, bundle } });
113 return ok({ username: asker.username, bundle, askedAt: ask.askedAt });
114 }
115
116 /** Decline: the row goes, and nothing is given. */
117 export function declineAsk(app: App, actor: User | undefined, username: string, want: string): Result<true, "not_found" | "gone"> {
118 if (!administrator(app, actor)) return err("not_found");
119 const asker = getUserByName(app.db, username);
120 if (BUNDLE_WANTS[want] === undefined || asker === undefined) return err("not_found");
121 const ask = waitingAdminAsks(app.db).find((a) => a.userId === asker.id && a.want === want);
122 if (ask === undefined || !removeAdminAsk(app.db, asker.id, want, ask.subject)) return err("gone");
123 app.bus.append({ kind: "ask.declined", actorId: actor.id, payload: { want, who: asker.username } });
124 return ok(true);
125 }
src/core/admin_ask.ts +5
@@ -144,3 +144,8 @@ export function pruneAdminAsks(db: Database, now: number = Date.now()): void {
144144 db.query("DELETE FROM admin_ask WHERE state IN ('later','done') AND answered_at <= ?1").run(new Date(now - ANSWERED_MS).toISOString());
145145 db.query("DELETE FROM admin_ask WHERE state = 'asked' AND last_at <= ?1").run(new Date(now - WAITING_MS).toISOString());
146146 }
147
148 /** One ask taken off the list (a Decline): true when a row was there. */
149 export function removeAdminAsk(db: Database, userId: string, want: string, subject: string): boolean {
150 return db.query("DELETE FROM admin_ask WHERE user_id = ?1 AND want = ?2 AND subject = ?3").run(userId, want, subject).changes > 0;
151 }
src/core/bundle_grants.ts +18
@@ -9,6 +9,7 @@
99
1010 import type { Database } from "bun:sqlite";
1111 import { inviteByToken } from "./invites.ts";
12 import type { Bundle, HostChoice } from "./bundles.ts";
1213 import { setMember } from "./roles.ts";
1314
1415 /** Whether the invite `token` names is a Host invite for a machine not among those offered now. */
@@ -39,3 +40,20 @@ export function hostGrantOf(db: Database, userId: string): { machine: string; co
3940 .get(userId);
4041 return row === null ? undefined : { machine: row.machine, containers: row.containers, memoryMb: row.memory_mb };
4142 }
43
44 /** The `invite_id` a Host grant carries when no invite gave it: an admin's Let in or Approve. */
45 export const GIVEN_BY_ADMIN = "admin";
46
47 /**
48 * A bundle given by a person's say-so, not by an invite: Build makes a member, Host keeps its one
49 * `host_grant` row (`host` is required for it), Use is what every account already is. The same
50 * grants `applyBundle` writes for an invite.
51 */
52 export function giveBundle(db: Database, userId: string, bundle: Bundle, by: string, host?: HostChoice, now: number = Date.now()): void {
53 const at = new Date(now);
54 if (bundle === "build") setMember(db, userId, true, by, at);
55 if (bundle === "host" && host !== undefined)
56 db.query(
57 "INSERT OR REPLACE INTO host_grant (user_id, machine, containers, memory_mb, invite_id, at) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
58 ).run(userId, host.machine, host.containers, host.memoryMb, GIVEN_BY_ADMIN, at.toISOString());
59 }
src/core/bundles.ts +6
@@ -52,6 +52,12 @@ export interface HostChoice {
5252 readonly memoryMb: number;
5353 }
5454
55 /**
56 * What Host is given when an administrator does not pick: the usual caps on the first machine
57 * offered.
58 */
59 export const HOST_DEFAULTS = { containers: 3, memoryMb: 2048 } as const;
60
5561 export const HOST_WORDS = {
5662 noMachine: "Host needs a machine this forge can offer, and it has none: connect a cloud account and build one first.",
5763 badMachine: "That machine is not one this forge offers.",
src/core/event_audience.ts +1
@@ -164,6 +164,7 @@ const READER_KINDS: ReadonlySet<string> = new Set([
164164 "account.email_verified",
165165 "account.allowed",
166166 "account.declined",
167 "account.let_in",
167168 "account.recovered",
168169 "limb.replan",
169170 "limb.replan_taken_back",
src/core/migration-pins/20261206190000-membership-ask-is-build.pin added +1
@@ -0,0 +1,1 @@
1 8cdadda0c108cc374fcb33d010a15f46eec43cd0f4976c88d18cf16afd8194f3
src/core/migrations/20261206190000-membership-ask-is-build.ts added +8
@@ -0,0 +1,8 @@
1 // The ask "membership" and the ask "build" were one thing, a person made a member (#18477): the
2 // waiting rows of the first become the second, so People has an Approve for them. A person who
3 // already has a "build" row for the same subject keeps that one and the older row goes.
4 export default `
5 DELETE FROM admin_ask WHERE want = 'membership'
6 AND EXISTS (SELECT 1 FROM admin_ask b WHERE b.user_id = admin_ask.user_id AND b.want = 'build' AND b.subject = admin_ask.subject);
7 UPDATE admin_ask SET want = 'build' WHERE want = 'membership';
8 `;
src/core/verify.ts +5 −2
@@ -52,8 +52,11 @@ export function markVerified(
5252 db: Database,
5353 userId: string,
5454 at: string,
55 /** Who vouched and how, when it was not a link followed: an invite's maker, `invite`. */
56 proof?: { readonly by: string; readonly how: "invite" },
55 /**
56 * Who vouched and how, when it was not a link followed: an invite's maker, `invite`; an admin's
57 * Let in, `let_in`.
58 */
59 proof?: { readonly by: string; readonly how: "invite" | "let_in" },
5760 ): void {
5861 db.transaction(() => {
5962 db.query(
src/http/lazy_lists.ts +3 −1
@@ -191,12 +191,14 @@ export const SETTINGS_ROUTES = [
191191 ["POST", "/settings/backups/mirror/clear"],
192192 ["POST", "/settings/backups/mirror/now"],
193193 ["GET", "/settings/accounts"],
194 ["POST", "/settings/accounts/:username/allow"],
195194 ["POST", "/settings/accounts/:username/decline"],
196195 ["GET", "/settings/people"],
197196 ["GET", "/settings/people/row/:username"],
198197 ["POST", "/settings/people/:username/role"],
199198 ["POST", "/settings/people/:username/take"],
199 ["POST", "/settings/people/:username/let-in"],
200 ["POST", "/settings/people/asks/:want/:username/approve"],
201 ["POST", "/settings/people/asks/:want/:username/decline"],
200202 ["POST", "/settings/people/invites/:id/again"],
201203 ["POST", "/settings/people/invites/:id/revoke"],
202204 ["GET", "/settings/model"],
src/http/marks/settings.json +3 −1
@@ -152,12 +152,14 @@
152152 "/settings/backups/mirror/clear": "admin",
153153 "/settings/backups/mirror/now": "admin",
154154 "/settings/accounts": "admin",
155 "/settings/accounts/:username/allow": "admin",
156155 "/settings/accounts/:username/decline": "admin",
157156 "/settings/people": "admin",
158157 "/settings/people/:username/role": "admin",
159158 "/settings/people/row/:username": "admin",
160159 "/settings/people/:username/take": "admin",
160 "/settings/people/:username/let-in": "admin",
161 "/settings/people/asks/:want/:username/approve": "admin",
162 "/settings/people/asks/:want/:username/decline": "admin",
161163 "/settings/people/invites/:id/again": "admin",
162164 "/settings/people/invites/:id/revoke": "admin",
163165 "/settings/model": "open",
src/http/settings_routes.ts +6 −3
@@ -35,7 +35,8 @@ import { securityPage, securityShieldSet } from "../web/pages/security.ts";
3535 import { trafficPage } from "../web/pages/traffic.ts";
3636 import { returningSet } from "../web/pages/visitors.ts";
3737 import { sourcesPage } from "../web/pages/sources.ts";
38 import { requestAct } from "../web/requests_card.ts";
38 import { declineRequestAct } from "../web/requests_card.ts";
39 import { askAnswerAct, letInAct } from "../web/let_in_card.ts";
3940 import { captureStart, captureStop, networksImport, scrapesExport, scrapesPage } from "../web/pages/scrapes.ts";
4041 import {
4142 accessAct,
@@ -352,12 +353,14 @@ export function settingsRoutes(router: Router<Handler>, knownPatterns: () => rea
352353 router.add("POST", "/settings/backups/mirror/clear", backupsMirrorClear);
353354 router.add("POST", "/settings/backups/mirror/now", backupsMirrorNow);
354355 router.add("GET", "/settings/accounts", (ctx) => redirect("/settings/people", { url: ctx.url, forgeUrl: ctx.app.config.url }));
355 router.add("POST", "/settings/accounts/:username/allow", requestAct("allow"));
356 router.add("POST", "/settings/accounts/:username/decline", requestAct("decline"));
356 router.add("POST", "/settings/accounts/:username/decline", declineRequestAct);
357357 router.add("GET", "/settings/people", peoplePage);
358358 router.add("GET", "/settings/people/row/:username", personFragment);
359359 router.add("POST", "/settings/people/:username/role", roleAct);
360360 router.add("POST", "/settings/people/:username/take", takeAct);
361 router.add("POST", "/settings/people/:username/let-in", letInAct);
362 router.add("POST", "/settings/people/asks/:want/:username/approve", askAnswerAct("approve"));
363 router.add("POST", "/settings/people/asks/:want/:username/decline", askAnswerAct("decline"));
361364 router.add("POST", "/settings/people/invites/:id/again", inviteAgain);
362365 router.add("POST", "/settings/people/invites/:id/revoke", inviteRevoke);
363366 router.add("GET", "/settings/model", modelPage);
src/tui/screens/people.ts +55 −2
@@ -8,7 +8,9 @@
88 * with the action MCP `account_verify` uses. Without mail a line above the
99 * list says so, as the accounts page's card does. `x` takes one thing away
1010 * from a person (`actions/take_away.ts`, what the web page's Remove does; `x ada app notes`
11 * removes the app notes that ada was let into).
11 * removes the app notes that ada was let into). `l` lets a person in with a bundle (Use, Build
12 * or Host; proves the account, sends no mail), `a` and `d` approve or decline a person's ask for
13 * Host or Build (`actions/let_in.ts`, what the web page's Let in, Approve and Decline do).
1214 */
1315
1416 import { suspendAccount, unsuspendAccount, verifyAccount } from "../../actions/accounts.ts";
@@ -19,6 +21,9 @@ import { getUserByName } from "../../core/users.ts";
1921 import { setRole } from "../../actions/roles.ts";
2022 import { takeAway, TAKE_AWAY_WORDS } from "../../actions/take_away.ts";
2123 import { appLetInto, REMOVABLE_WORDS } from "../../core/grant_removal.ts";
24 import { HOST_DEFAULTS } from "../../core/bundles.ts";
25 import { hostMachines } from "../../actions/invites.ts";
26 import { approveAsk, bundleAsks, declineAsk, letIn, LET_IN_WORDS } from "../../actions/let_in.ts";
2227 import { AMOUNT_REFUSED } from "../../actions/model_words.ts";
2328 import { peopleByActivity, WORDS, type PersonRow, type RoleWord } from "../../core/people_rows.ts";
2429 import type { Ctx, Screen } from "../app/app.ts";
@@ -49,10 +54,16 @@ export const FILTERS: readonly (RoleWord | null)[] = [null, ...WORDS];
4954 export const filterLine = (only: RoleWord | null): string =>
5055 `Show: ${FILTERS.map((w) => (w === only ? `[${w ?? "everyone"}]` : (w ?? "everyone"))).join(" · ")} (f changes)`;
5156
57 /** The asks for Host or Build waiting for an answer, in one line. */
58 export const asksLine = (asks: readonly { username: string; bundle: string }[]): string =>
59 `Asks: ${asks.map((a) => `${a.username} ${a.bundle}`).join(", ")} (a approves, d declines)`;
60
5261 export function peopleScreen(f: Session, ctx: Ctx): Screen {
5362 const list = new ListState();
5463 let only: RoleWord | null = null;
5564 const people = (): PersonRow[] => peopleByActivity(f.app.db, only);
65 // The asks for Host or Build: read when the screen opens and again at each key, not at each draw.
66 let asks = bundleAsks(f.app, f.user);
5667 // Read once per open: the answer lists the forge's secrets.
5768 const noMail = !mailConfigured(f.app);
5869 const verify = (name: string): void => {
@@ -96,7 +107,7 @@ export function peopleScreen(f: Session, ctx: Ctx): Screen {
96107 };
97108 const screen: Screen = {
98109 title: "People",
99 keys: [binding(["f"], "filter"), binding(["r"], "change a role"), binding(["s"], "suspend or lift"), binding(["v"], "verify"), binding(["x"], "take one thing away"), binding(["esc"], "back")],
110 keys: [binding(["f"], "filter"), binding(["r"], "change a role"), binding(["s"], "suspend or lift"), binding(["v"], "verify"), binding(["x"], "take one thing away"), binding(["l"], "let in"), binding(["a"], "approve an ask"), binding(["d"], "decline an ask"), binding(["esc"], "back")],
100111 render(area, s) {
101112 const rows: ListRow[] = people().map((p) => ({
102113 title: rowOf(p),
@@ -107,6 +118,10 @@ export function peopleScreen(f: Session, ctx: Ctx): Screen {
107118 s.text(area.x, area.y, truncate(NO_MAIL_LINE, area.w), style(c.attn, c.bg), area.x + area.w);
108119 area = { ...area, y: area.y + 2, h: Math.max(0, area.h - 2) };
109120 }
121 if (asks.length > 0 && area.h > 1) {
122 s.text(area.x, area.y, truncate(asksLine(asks), area.w), style(c.attn, c.bg), area.x + area.w);
123 area = { ...area, y: area.y + 2, h: Math.max(0, area.h - 2) };
124 }
110125 if (area.h > 1) {
111126 s.text(area.x, area.y, truncate(filterLine(only), area.w), style(c.mutedFg, c.bg), area.x + area.w);
112127 area = { ...area, y: area.y + 2, h: Math.max(0, area.h - 2) };
@@ -114,6 +129,7 @@ export function peopleScreen(f: Session, ctx: Ctx): Screen {
114129 drawList(s, area, c, list, rows);
115130 },
116131 key(e) {
132 asks = bundleAsks(f.app, f.user);
117133 const shown = people();
118134 if (list.key(e, shown.length)) return true;
119135 if (e.ctrl || e.alt) return false;
@@ -159,6 +175,43 @@ export function peopleScreen(f: Session, ctx: Ctx): Screen {
159175 );
160176 return true;
161177 }
178 if (e.key === "l") {
179 ctx.push(
180 promptScreen(ctx, screen, {
181 title: "Let in",
182 label: "account name, then use, build or host (use by default)",
183 onSubmit: (raw) => {
184 const [name, bundle, ...rest] = raw.trim().toLowerCase().split(/\s+/);
185 if (name === undefined || name === "" || rest.length > 0) return "name, then use, build or host.";
186 const machine = hostMachines(f.app, f.user)[0];
187 const done = letIn(f.app, f.user, name, { bundle: bundle ?? "use", ...(machine === undefined ? {} : { machine, ...HOST_DEFAULTS }) });
188 if (!done.ok) return done.error === "not_found" ? "No such person." : LET_IN_WORDS[done.error];
189 ctx.toast(`${done.value.username} is in, with ${done.value.bundle}.`);
190 return undefined;
191 },
192 }),
193 );
194 return true;
195 }
196 if (e.key === "a" || e.key === "d") {
197 const approve = e.key === "a";
198 ctx.push(
199 promptScreen(ctx, screen, {
200 title: approve ? "Approve an ask" : "Decline an ask",
201 label: "build or host, then the account name",
202 onSubmit: (raw) => {
203 const [want, name, ...rest] = raw.trim().toLowerCase().split(/\s+/);
204 if (want === undefined || name === undefined || rest.length > 0) return "build or host, then the name.";
205 const done = approve ? approveAsk(f.app, f.user, name, want) : declineAsk(f.app, f.user, name, want);
206 if (!done.ok) return done.error === "not_found" ? "No such person or ask." : done.error === "gone" ? "That ask was already answered." : LET_IN_WORDS[done.error];
207 asks = bundleAsks(f.app, f.user);
208 ctx.toast(approve ? `${name} has ${want}.` : `${name}'s ask for ${want} is gone.`);
209 return undefined;
210 },
211 }),
212 );
213 return true;
214 }
162215 if (e.key === "x") {
163216 ctx.push(
164217 promptScreen(ctx, screen, {
src/tui/screens/requests.ts +12 −11
@@ -1,12 +1,13 @@
11 /**
22 * The Waiting list in the terminal, a forge admin's (#10928): strangers who
3 * asked for an account, oldest first, as the Waiting card on /settings/accounts
4 * has them. `a` allows the selected one and `d` declines it, both through
5 * `actions/requests.ts`, so the gate is theirs (an admin who is a person;
3 * asked for an account, oldest first, as the Waiting card on /settings/people
4 * has them. `l` lets the selected one in with Use (`actions/let_in.ts`) and `d` declines it
5 * (`actions/requests.ts`), so the gate is theirs (an admin who is a person;
66 * anyone else sees nothing) and the write reaches web viewers on the bus.
77 */
88
9 import { allowRequest, declineRequest, listRequests } from "../../actions/requests.ts";
9 import { letIn } from "../../actions/let_in.ts";
10 import { declineRequest, listRequests } from "../../actions/requests.ts";
1011 import type { Ctx, Screen } from "../app/app.ts";
1112 import { binding } from "../app/keys.ts";
1213 import { style } from "../term/style.ts";
@@ -32,12 +33,12 @@ export function requestsScreen(f: Session, ctx: Ctx): Screen {
3233 meta: `asked ${r.askedAt.slice(0, 16)} from ${r.source === "" ? "the web" : r.source}`,
3334 }));
3435
35 const answer = (act: "allow" | "decline"): boolean => {
36 const answer = (act: "letin" | "decline"): boolean => {
3637 const row = items()[state.index];
3738 if (row === undefined) return false;
38 const done = (act === "allow" ? allowRequest : declineRequest)(f.app, f.user, row.username);
39 const done = act === "letin" ? letIn(f.app, f.user, row.username, { bundle: "use" }) : declineRequest(f.app, f.user, row.username);
3940 note = done.ok
40 ? `${row.username} ${act === "allow" ? "is in" : "was declined, politely"}.`
41 ? `${row.username} ${act === "letin" ? "is in, with Use" : "was declined, politely"}.`
4142 : `${row.username} is not waiting any more.`;
4243 ctx.invalidate();
4344 return true;
@@ -45,7 +46,7 @@ export function requestsScreen(f: Session, ctx: Ctx): Screen {
4546
4647 const screen: Screen = {
4748 title: "Waiting",
48 keys: [binding(["j", "k"], "move cursor"), binding(["a"], "allow"), binding(["d"], "decline")],
49 keys: [binding(["j", "k"], "move cursor"), binding(["l"], "let in"), binding(["d"], "decline")],
4950 render(area, s) {
5051 const c = ctx.theme.c;
5152 const r = read();
@@ -57,7 +58,7 @@ export function requestsScreen(f: Session, ctx: Ctx): Screen {
5758 ? "The Waiting list is a forge admin's."
5859 : r.value.length === 0
5960 ? "Nobody is waiting."
60 : "a allows the selected request, d declines it.";
61 : "l lets the selected person in with Use, d declines; People gives Build or Host.";
6162 s.text(head!.x, head!.y, truncate(text, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w);
6263 drawList(s, body!, c, state, rows());
6364 },
@@ -65,7 +66,7 @@ export function requestsScreen(f: Session, ctx: Ctx): Screen {
6566 note = "";
6667 if (state.key(e, items().length)) return true;
6768 if (e.ctrl || e.alt || !read().ok) return false;
68 if (e.key === "a") return answer("allow");
69 if (e.key === "l") return answer("letin");
6970 if (e.key === "d") return answer("decline");
7071 return false;
7172 },
@@ -78,7 +79,7 @@ export const entry: PaletteEntry = {
7879 rank: 810,
7980 id: "requests",
8081 title: "Waiting",
81 hint: "strangers who asked for an account: allow or decline",
82 hint: "strangers who asked for an account: let in or decline",
8283 after: ["invites", "teams", "limits", "quotas", "people", "can"],
8384 asks: "forge.administer",
8485 for: "person",
src/web/host_ask.ts added +23
@@ -0,0 +1,23 @@
1 /**
2 * On a person's own settings: Host (running containers on one of this forge's machines) is theirs
3 * to ask for when the forge offers a machine and they have none; the button adds one row to People
4 * for an admin to Approve or Decline (`actions/let_in.ts`). Nothing is shown to an admin, who
5 * needs no asking, nor on a forge with no machine to offer.
6 */
7
8 import { machinesOffered } from "../actions/invites.ts";
9 import { noHostBlocked } from "../actions/blocked_words.ts";
10 import { hostGrantOf } from "../core/bundle_grants.ts";
11 import type { Ctx } from "../http/context.ts";
12 import { blockedWay } from "./blocked.ts";
13 import { html, type Html } from "./html.ts";
14
15 export function hostAsk(ctx: Ctx): Html | null {
16 const user = ctx.auth.user;
17 if (user === undefined || user.kind !== "user" || user.isAdmin) return null;
18 if (hostGrantOf(ctx.app.db, user.id) !== undefined || machinesOffered(ctx.app).length === 0) return null;
19 return html`<section class="settings-block" id="host">
20 <h2>Host</h2>
21 <p class="small">${blockedWay(noHostBlocked(ctx.app, user))}</p>
22 </section>`;
23 }
src/web/let_in_card.ts added +105
@@ -0,0 +1,105 @@
1 /**
2 * Let in and the asks for Host or Build, on People. A person who waits (they asked for an account,
3 * or their account is not proved) has one button, Let in, beside the bundle to give them; with
4 * mail or without, since it sends none (`actions/let_in.ts`). A person a page stopped for lack of
5 * Host or Build asked for it: that is one row under Asks with Approve and Decline. The rules are
6 * the action's; this draws the forms and answers them.
7 */
8
9 import { approveAsk, bundleAsks, declineAsk, letIn, LET_IN_WORDS, type BundleAsk } from "../actions/let_in.ts";
10 import { hostMachines } from "../actions/invites.ts";
11 import type { App } from "../app.ts";
12 import { BUNDLE, BUNDLES, HOST_DEFAULTS } from "../core/bundles.ts";
13 import type { User } from "../core/users.ts";
14 import type { Ctx } from "../http/context.ts";
15 import { notFoundPage } from "./chrome.ts";
16 import { adminForm, field as formField } from "./form.ts";
17 import { html, type Html } from "./html.ts";
18 import { flashOrJson } from "./layout.ts";
19 import { btn, row, rowList, selectField, time } from "./ui.ts";
20
21 const PEOPLE = "/settings/people";
22 const rowAt = (username: string): string => `${PEOPLE}/row/${encodeURIComponent(username)}`;
23
24 /**
25 * The one button and the bundle beside it. `inPlace` redraws the person's row instead of the page.
26 */
27 export function letInForm(app: App, viewer: User | undefined, username: string, o: { inPlace?: boolean; back?: string } = {}): Html {
28 const machines = hostMachines(app, viewer);
29 const id = `let-in-${username}`;
30 return html`<form class="row-fields" method="post" action="${PEOPLE}/${encodeURIComponent(username)}/let-in${o.back === undefined ? "" : `?back=${o.back}`}"${o.inPlace === true ? html` data-in-place` : null}>
31 ${machines.length === 0 ? null : html`<input type="hidden" name="machine" value="${machines[0]}" /><input type="hidden" name="containers" value="${HOST_DEFAULTS.containers}" /><input type="hidden" name="memoryMb" value="${HOST_DEFAULTS.memoryMb}" />`}
32 ${selectField({
33 name: "bundle",
34 id,
35 label: "Give them",
36 options: BUNDLES.filter((b) => b !== "host" || machines.length > 0).map((b) => ({
37 value: b,
38 label: `${BUNDLE[b].label}${b === "host" ? ` (${machines[0]}, ${HOST_DEFAULTS.containers} containers, ${HOST_DEFAULTS.memoryMb} MB)` : ""}`,
39 selected: b === "use",
40 })),
41 })}
42 ${btn("Let in", { type: "submit", size: "sm", variant: "primary", label: `Let ${username} in` })}
43 </form>`;
44 }
45
46 const askRow = (a: BundleAsk): Html => {
47 const at = `${PEOPLE}/asks/${a.bundle}/${encodeURIComponent(a.username)}`;
48 return row({
49 title: html`<strong>${a.username}</strong> asks for ${BUNDLE[a.bundle].label}`,
50 meta: html`asked ${time(a.askedAt)} · ${BUNDLE[a.bundle].says}`,
51 after: html`<form method="post" action="${at}/approve">${btn("Approve", { type: "submit", size: "sm", variant: "primary", label: `Approve ${BUNDLE[a.bundle].label} for ${a.username}` })}</form>
52 <form method="post" action="${at}/decline">${btn("Decline", { type: "submit", size: "sm", variant: "outline", label: `Decline ${BUNDLE[a.bundle].label} for ${a.username}` })}</form>`,
53 });
54 };
55
56 /** The Asks block: a row for each person waiting on Host or Build, or nothing. */
57 export function bundleAsksCard(ctx: Ctx): Html | null {
58 const asks = bundleAsks(ctx.app, ctx.auth.user);
59 if (asks.length === 0) return null;
60 return html`<section class="settings-block" id="asks" aria-label="Asks">
61 <h2>Asks <span class="muted">${asks.length}</span></h2>
62 ${rowList(asks.map(askRow))}
63 </section>`;
64 }
65
66 // POST /settings/people/:username/let-in
67 export async function letInAct(ctx: Ctx): Promise<Response> {
68 const form = await adminForm(ctx);
69 if (form instanceof Response) return form;
70 const username = ctx.params.username ?? "";
71 const done = letIn(ctx.app, ctx.auth.user, username, {
72 bundle: formField(form, "bundle"),
73 machine: formField(form, "machine"),
74 containers: formField(form, "containers"),
75 memoryMb: formField(form, "memoryMb"),
76 });
77 if (!done.ok && done.error === "not_found") return notFoundPage(ctx);
78 const to = ctx.url.searchParams.get("back") === "home" ? "/" : PEOPLE;
79 return flashOrJson(
80 ctx,
81 to,
82 done.ok ? { message: `${done.value.username} is in, with ${BUNDLE[done.value.bundle].label}.` } : { tone: "danger", message: done.error === "not_found" ? "" : LET_IN_WORDS[done.error] },
83 { redraw: [rowAt(username)] },
84 );
85 }
86
87 /** POST /settings/people/asks/:want/:username/approve and /decline. */
88 export function askAnswerAct(act: "approve" | "decline") {
89 return async (ctx: Ctx): Promise<Response> => {
90 const form = await adminForm(ctx);
91 if (form instanceof Response) return form;
92 const username = ctx.params.username ?? "";
93 const want = ctx.params.want ?? "";
94 const done = act === "approve" ? approveAsk(ctx.app, ctx.auth.user, username, want) : declineAsk(ctx.app, ctx.auth.user, username, want);
95 if (!done.ok && done.error === "not_found") return notFoundPage(ctx);
96 const word = BUNDLE[want === "host" ? "host" : "build"].label;
97 return flashOrJson(
98 ctx,
99 PEOPLE,
100 done.ok
101 ? { message: act === "approve" ? `${username} has ${word}.` : `${username}'s ask for ${word} is gone.` }
102 : { tone: "danger", message: done.error === "gone" ? "That ask was already answered." : LET_IN_WORDS[done.error as keyof typeof LET_IN_WORDS] },
103 );
104 };
105 }
src/web/pages/account.ts +2 −1
@@ -41,6 +41,7 @@ import { LAST_WAY_IN, linkedParent, parentIssuerOf, unlinkParent } from "../../c
4141 import { activeEdgeToken, edgeIdentity } from "../../http/edge.ts";
4242 import { listKeys } from "../../core/keys.ts";
4343 import { identitiesBlock } from "./proven_identities.ts";
44 import { hostAsk } from "../host_ask.ts";
4445 import { listTokensWithClients } from "../../core/oauth.ts";
4546 import {
4647 PROFILE_FALLBACK,
@@ -493,7 +494,7 @@ function profileView(ctx: Ctx, values: ProfileForm): Html {
493494 </div>
494495 ${refusal(values.refused?.errors.form)}
495496 </form>`,
496 )}${identitiesBlock(ctx)}`;
497 )}${identitiesBlock(ctx)}${hostAsk(ctx)}`;
497498 }
498499
499500 /** A reading the cell may not give: a dash, never a zero that says "idle". */
src/web/pages/people.ts +10 −4
@@ -37,6 +37,8 @@ import { flashOrJson, flashTo, fragment, page } from "../layout.ts";
3737 import { badge, btn, empty, field, row, rowList, time, userLink } from "../ui.ts";
3838 import { emptyList } from "../empty_words.ts";
3939 import { accountSections } from "./origins.ts";
40 import { waitsToBeLetIn } from "../../actions/let_in.ts";
41 import { letInForm } from "../let_in_card.ts";
4042 import { peopleCards } from "./people_cards.ts";
4143 import { inviteSection } from "./people_invites.ts";
4244
@@ -101,7 +103,7 @@ function proofFacts(a: AccountRow, mc: readonly Identity[]): { label: string; va
101103 * One person: a row with who they are and how they were proved, and under it one line for each
102104 * thing they can do.
103105 */
104 function personRow(r: PersonRow, f: Facts): Html {
106 function personRow(r: PersonRow, f: Facts, ctx: Ctx): Html {
105107 const a = f.accounts.get(r.username);
106108 const owner = r.word === "owner";
107109 const crew = r.word === "crew member";
@@ -145,7 +147,11 @@ function personRow(r: PersonRow, f: Facts): Html {
145147 }),
146148 ]
147149 : [];
148 const children = owner ? [row({ title: "Everything. An owner keeps it, so the forge always has one." })] : [...promote, ...lines];
150 const letIn =
151 a !== undefined && !owner && !crew && waitsToBeLetIn(a)
152 ? [row({ title: a.waiting ? "Asked for an account" : "Not proved", trail: letInForm(ctx.app, ctx.auth.user, r.username, { inPlace: true }) })]
153 : [];
154 const children = owner ? [row({ title: "Everything. An owner keeps it, so the forge always has one." })] : [...letIn, ...promote, ...lines];
149155 return row({
150156 nav: true,
151157 data: { fragment: rowAt(r.username) },
@@ -207,7 +213,7 @@ export function peopleView(ctx: Ctx, notice?: Html, status = 200): Response {
207213 ? only === null
208214 ? emptyList("people")
209215 : empty({ icon: "users", title: "Nobody here." })
210 : html`<div data-people>${rowList(rows.slice(0, MAX_SHOWN).map((r) => personRow(r, facts)))}</div>
216 : html`<div data-people>${rowList(rows.slice(0, MAX_SHOWN).map((r) => personRow(r, facts, ctx)))}</div>
211217 ${rows.length > MAX_SHOWN ? html`<p class="small muted">${rows.length - MAX_SHOWN} more: narrow it with a filter.</p>` : null}
212218 <p class="small muted">Allowances go up to $${GRANT_MAX_USD} a month. ${roleLimits()}</p>`
213219 }
@@ -228,7 +234,7 @@ export function personFragment(ctx: Ctx): Response {
228234 const name = ctx.params.username ?? "";
229235 const r = peopleByActivity(ctx.app.db).find((p) => p.username === name);
230236 if (r === undefined) return fragment(html``, { status: 404 });
231 return fragment(personRow(r, readFacts(ctx, name)), { request: ctx.request });
237 return fragment(personRow(r, readFacts(ctx, name), ctx), { request: ctx.request });
232238 }
233239
234240 // POST /settings/people/:username/take: Remove one line.
src/web/pages/people_cards.ts +2 −1
@@ -12,6 +12,7 @@ import { OWNERS_TEAM, ownerlessOrgs } from "../../core/orgs.ts";
1212 import { timePhase } from "../../core/route_timing.ts";
1313 import type { Ctx } from "../../http/context.ts";
1414 import { html, type Html } from "../html.ts";
15 import { bundleAsksCard } from "../let_in_card.ts";
1516 import { requestsCard } from "../requests_card.ts";
1617 import { btn, userLink } from "../ui.ts";
1718
@@ -76,5 +77,5 @@ export function peopleCards(ctx: Ctx): Html {
7677 </p>
7778 ${wayBackForms(ctx)}
7879 </section>`;
79 return html`${mailLine(mail)}${requestsCard(ctx)}${ownerless}${edgeOnly}`;
80 return html`${mailLine(mail)}${requestsCard(ctx)}${bundleAsksCard(ctx)}${ownerless}${edgeOnly}`;
8081 }
src/web/requests_card.ts +20 −22
@@ -1,16 +1,17 @@
11 /**
22 * The Waiting list: strangers who asked for an account (#10928), each with
3 * the note they left, when, and from where, and Allow and Decline one tap
3 * the note they left, when, and from where, and Let in and Decline one tap
44 * apart. Shown on top of the accounts page and in home's "Needs you", for a
55 * forge admin; both answer through `actions/requests.ts`.
66 */
77
8 import { allowRequest, declineRequest, listRequests } from "../actions/requests.ts";
8 import { declineRequest, listRequests } from "../actions/requests.ts";
99 import type { Ctx } from "../http/context.ts";
1010 import { notFoundPage, signInFirst } from "./chrome.ts";
1111 import { readForm } from "./form.ts";
1212 import { html, type Html } from "./html.ts";
1313 import { flashTo } from "./layout.ts";
14 import { letInForm } from "./let_in_card.ts";
1415 import { btn, row, time } from "./ui.ts";
1516 import { adminPage } from "../http/page_may.ts";
1617
@@ -29,9 +30,7 @@ export function requestsCard(ctx: Ctx, back = ""): Html | null {
2930 meta: html`asked ${time(r.askedAt)} · from ${r.source === "" ? "the web" : r.source}${r.note === ""
3031 ? null
3132 : html`<br />${r.note}`}`,
32 after: html`<form method="post" action="${at}/allow${to}">
33 ${btn("Allow", { type: "submit", variant: "primary" })}
34 </form>
33 after: html`${letInForm(ctx.app, ctx.auth.user, r.username, back === "" ? {} : { back })}
3534 <form method="post" action="${at}/decline${to}">
3635 ${btn("Decline", { type: "submit", variant: "outline" })}
3736 </form>`,
@@ -41,21 +40,20 @@ export function requestsCard(ctx: Ctx, back = ""): Html | null {
4140 </section>`;
4241 }
4342
44 /** POST /settings/accounts/:username/allow and /decline. */
45 export function requestAct(act: "allow" | "decline") {
46 return async (ctx: Ctx): Promise<Response> => {
47 if (!ctx.auth.user) return signInFirst(ctx);
48 if (!adminPage(ctx)) return notFoundPage(ctx);
49 const form = await readForm(ctx, "admin");
50 if (form instanceof Response) return form;
51 const username = ctx.params.username ?? "";
52 const done = (act === "allow" ? allowRequest : declineRequest)(ctx.app, ctx.auth.user, username);
53 if (!done.ok && done.error === "not_found") return notFoundPage(ctx);
54 const to = ctx.url.searchParams.get("back") === "home" ? "/" : "/settings/people";
55 return flashTo(ctx, to, {
56 message: done.ok
57 ? `${username} ${act === "allow" ? "is in" : "was declined, politely"}.`
58 : `${username} is not waiting any more.`,
59 });
60 };
43 /**
44 * POST /settings/accounts/:username/decline. Allow is Let in (`let_in_card.ts`): one button that
45 * proves the account and gives a bundle, so this page has no second way to say yes.
46 */
47 export async function declineRequestAct(ctx: Ctx): Promise<Response> {
48 if (!ctx.auth.user) return signInFirst(ctx);
49 if (!adminPage(ctx)) return notFoundPage(ctx);
50 const form = await readForm(ctx, "admin");
51 if (form instanceof Response) return form;
52 const username = ctx.params.username ?? "";
53 const done = declineRequest(ctx.app, ctx.auth.user, username);
54 if (!done.ok && done.error === "not_found") return notFoundPage(ctx);
55 const to = ctx.url.searchParams.get("back") === "home" ? "/" : "/settings/people";
56 return flashTo(ctx, to, {
57 message: done.ok ? `${username} was declined, politely.` : `${username} is not waiting any more.`,
58 });
6159 }
test/guest-contribute.test.ts +1 −1
@@ -669,7 +669,7 @@ describe("a stranger's first pull starts from the app's page", () => {
669669 expect(offer).toContain(HELP_BUILD);
670670 expect(offer).toContain(BECOME_A_MEMBER);
671671 // With the one button that asks an admin, and the form it submits (`web/blocked.ts`).
672 expect(offer).toContain('value="membership ');
672 expect(offer).toContain('value="build ');
673673 expect(offer).toContain('action="/asks/admin" id="ask-who-can"');
674674 expect(BECOME_A_MEMBER).toBe("A link to an app does not make you a member. An admin of this forge can make you one.");
675675 expect(NOT_A_MEMBER).toContain(BECOME_A_MEMBER);
test/let-in.test.ts added +232
@@ -0,0 +1,232 @@
1 /**
2 * Let in and the asks for Host or Build (#18477). One button proves the account and applies the
3 * bundle beside it, with mail or without; a person a page stopped asks, the ask adds one row to
4 * People, and only an administrator's Approve (decided by `may()`) gives anything.
5 */
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { mailConfigured } from "../src/actions/verify.ts";
12 import { askAdmin } from "../src/actions/ask_admin.ts";
13 import { approveAsk, bundleAsks, declineAsk, letIn } from "../src/actions/let_in.ts";
14 import { notMemberBlocked } from "../src/actions/blocked_words.ts";
15 import { insertPinned } from "../src/core/pinned.ts";
16 import { hostGrantOf } from "../src/core/bundle_grants.ts";
17 import { HOST_DEFAULTS } from "../src/core/bundles.ts";
18 import { adminAsksOf } from "../src/core/admin_ask.ts";
19 import { createSession } from "../src/core/sessions.ts";
20 import { roleOf } from "../src/core/roles.ts";
21 import { createUser, getUserById, type User } from "../src/core/users.ts";
22 import { emailVerified } from "../src/core/verify.ts";
23 import { serve, type Servers } from "../src/http/server.ts";
24 import { seedAdmin } from "./helpers/admin.ts";
25 import { quietLogs } from "./helpers/globals.ts";
26
27 quietLogs();
28
29 describe("let in, and asks for Host or Build", () => {
30 let dir = "";
31 let app: App;
32 let admin: User;
33 let servers: Servers;
34 let cookie = "";
35 let n = 0;
36
37 beforeAll(async () => {
38 dir = await mkdtemp(join(tmpdir(), "forge-let-in-"));
39 app = createApp({ dataDir: dir, port: 0 });
40 const made = await seedAdmin(app, { username: "olive", email: "[email protected]", password: "an-admin-passphrase" });
41 if (!made.ok) throw new Error(made.error);
42 admin = made.value;
43 servers = await serve(app);
44 cookie = `forge_session=${createSession(app.db, admin.id).token}`;
45 });
46 afterAll(async () => {
47 await servers.stop();
48 app.close();
49 await rm(dir, { recursive: true, force: true });
50 });
51
52 /** A person whose email is not proved, as a sign-up with no mail leaves them. */
53 const unproven = async (): Promise<User> => {
54 const name = `pal${++n}`;
55 const made = await createUser(app.db, { username: name, email: `${name}@f.dev`, password: "a-fine-passphrase", origin: "seed" });
56 if (!made.ok) throw new Error(made.error);
57 return made.value;
58 };
59 const asking = async (): Promise<User> => {
60 const u = await unproven();
61 app.db.run("UPDATE user SET waiting_at = '2026-01-01T00:00:00Z' WHERE id = ?1", [u.id]);
62 app.db.run("INSERT INTO account_request (user_id, note, source, state, asked_at) VALUES (?1, 'hi', '', 'waiting', '2026-01-01T00:00:00Z')", [u.id]);
63 return getUserById(app.db, u.id)!;
64 };
65 const events = (kind: string): number => app.db.query<{ n: number }, [string]>("SELECT count(*) AS n FROM event WHERE kind = ?1").get(kind)!.n;
66 const post = (path: string, body = "") =>
67 fetch(`${servers.url}${path}`, { method: "POST", redirect: "manual", headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" }, body });
68
69 test("this forge sends no mail, and Let in proves the account all the same", async () => {
70 expect(mailConfigured(app)).toBe(false);
71 const u = await unproven();
72 expect(emailVerified(app.db, u.id)).toBe(false);
73 const done = letIn(app, admin, u.username, { bundle: "use" });
74 expect(done.ok).toBe(true);
75 expect(emailVerified(app.db, u.id)).toBe(true);
76 expect(roleOf(app.db, getUserById(app.db, u.id)!)).toBe("guest");
77 expect(events("account.let_in")).toBe(1);
78 });
79
80 test("an asking person is let in and gets the bundle picked: Build makes a member", async () => {
81 const u = await asking();
82 expect(u.waitingAt).not.toBeNull();
83 const done = letIn(app, admin, u.username, { bundle: "build" });
84 expect(done.ok).toBe(true);
85 const after = getUserById(app.db, u.id)!;
86 expect(after.waitingAt).toBeNull();
87 expect(emailVerified(app.db, u.id)).toBe(true);
88 expect(roleOf(app.db, after)).toBe("member");
89 });
90
91 test("Let in is an administrator's: a guest, an agent's target and a bad bundle get nothing", async () => {
92 const u = await unproven();
93 const other = await unproven();
94 expect(letIn(app, getUserById(app.db, other.id), u.username, { bundle: "build" }).ok).toBe(false);
95 expect(emailVerified(app.db, u.id)).toBe(false);
96 const bad = letIn(app, admin, u.username, { bundle: "root" });
97 expect(bad.ok ? "" : bad.error).toBe("invalid_bundle");
98 expect(emailVerified(app.db, u.id)).toBe(false);
99 const host = letIn(app, admin, u.username, { bundle: "host" });
100 expect(host.ok ? "" : host.error).toBe("no_machine");
101 expect(emailVerified(app.db, u.id)).toBe(false);
102 });
103
104 test("People shows Let in for a waiting or unproven person, and the button works", async () => {
105 const u = await asking();
106 const text = await (await fetch(`${servers.url}/settings/people`, { headers: { cookie } })).text();
107 expect(text).toContain(`action="/settings/people/${u.username}/let-in"`);
108 expect(text).toContain("Let in");
109 expect(text).not.toContain(">Allow<");
110 const res = await post(`/settings/people/${u.username}/let-in`, "bundle=build");
111 expect(res.status).toBe(303);
112 expect(roleOf(app.db, getUserById(app.db, u.id)!)).toBe("member");
113 });
114
115 test("a guest stopped by a page is offered Ask for Build, and the ask adds one row with Approve and Decline", async () => {
116 const guest = await unproven();
117 const blocked = notMemberBlocked(app, guest, "Forks are for members.");
118 expect(blocked.ask?.label).toBe("Ask for Build");
119 const asked = askAdmin(app, guest, { want: blocked.ask!.body["want"] as string, subject: blocked.ask!.body["subject"] as string });
120 expect(asked.ok).toBe(true);
121 // A request grants nothing.
122 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("guest");
123 expect(bundleAsks(app, guest)).toEqual([]);
124 expect(bundleAsks(app, admin).map((a) => `${a.username} ${a.bundle}`)).toContain(`${guest.username} build`);
125 const text = await (await fetch(`${servers.url}/settings/people`, { headers: { cookie } })).text();
126 expect(text).toContain(`${guest.username}</strong> asks for Build`);
127 expect(text).toContain(`/settings/people/asks/build/${guest.username}/approve`);
128 expect(text).toContain(`/settings/people/asks/build/${guest.username}/decline`);
129 });
130
131 test("Approve applies the bundle and is audited; only an administrator can", async () => {
132 const guest = await unproven();
133 askAdmin(app, guest, { want: "build", subject: guest.username });
134 const before = events("ask.approved");
135 // A guest cannot approve their own ask.
136 expect(approveAsk(app, getUserById(app.db, guest.id), guest.username, "build").ok).toBe(false);
137 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("guest");
138 const over = await post(`/settings/people/asks/build/${guest.username}/approve`);
139 expect(over.status).toBe(303);
140 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("member");
141 expect(events("ask.approved")).toBe(before + 1);
142 expect(bundleAsks(app, admin).some((a) => a.username === guest.username)).toBe(false);
143 // Answered once.
144 const again = approveAsk(app, admin, guest.username, "build");
145 expect(again.ok ? "" : again.error).toBe("gone");
146 });
147
148 test("Decline removes the row, gives nothing and is audited", async () => {
149 const guest = await unproven();
150 askAdmin(app, guest, { want: "build", subject: guest.username });
151 const before = events("ask.declined");
152 const res = await post(`/settings/people/asks/build/${guest.username}/decline`);
153 expect(res.status).toBe(303);
154 expect(adminAsksOf(app.db, guest.id).filter((a) => a.want === "build")).toEqual([]);
155 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("guest");
156 expect(events("ask.declined")).toBe(before + 1);
157 expect(declineAsk(app, admin, guest.username, "build").ok).toBe(false);
158 });
159
160 test("a want that is not a bundle cannot be approved through this door, and membership is no want any more", async () => {
161 const guest = await unproven();
162 expect(askAdmin(app, guest, { want: "membership", subject: guest.username }).ok).toBe(false);
163 const done = approveAsk(app, admin, guest.username, "telemetry_grant");
164 expect(done.ok ? "" : done.error).toBe("not_found");
165 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("guest");
166 });
167
168 test("the migration turns a waiting membership ask into a Build ask that People can Approve", async () => {
169 const guest = await unproven();
170 app.db.run("INSERT INTO admin_ask (user_id, want, subject, repo_id, asked_at, last_at) VALUES (?1, 'membership', ?2, NULL, '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z')", [guest.id, guest.username]);
171 const { default: sql } = await import("../src/core/migrations/20261206190000-membership-ask-is-build.ts");
172 app.db.exec(sql);
173 expect(adminAsksOf(app.db, guest.id).map((a) => a.want)).toEqual(["build"]);
174 expect(approveAsk(app, admin, guest.username, "build").ok).toBe(true);
175 expect(roleOf(app.db, getUserById(app.db, guest.id)!)).toBe("member");
176 });
177
178 describe("Host, with a machine on offer", () => {
179 beforeAll(() => {
180 insertPinned(
181 app.db,
182 { name: "shop-1", target: "digitalocean", account: "main", app: "ada/shop", source: "", version: "v1", config: {}, host: "shop-1.example.com", claimHash: "", claimExpires: "", datacenter: "fra1", size: "s-1vcpu-1gb" },
183 "ada",
184 );
185 app.db.query("UPDATE pinned_forge SET state = 'online', remote = 'r-1' WHERE name = ?1").run("shop-1");
186 });
187
188 test("Let in with Host writes the machine and caps, and proves the account", async () => {
189 const u = await unproven();
190 const done = letIn(app, admin, u.username, { bundle: "host", machine: "shop-1", containers: "2", memoryMb: "512" });
191 expect(done.ok).toBe(true);
192 expect(hostGrantOf(app.db, u.id)).toEqual({ machine: "shop-1", containers: 2, memoryMb: 512 });
193 expect(emailVerified(app.db, u.id)).toBe(true);
194 expect(roleOf(app.db, getUserById(app.db, u.id)!)).toBe("guest");
195 // A machine this forge does not offer, or a bad cap, grants and proves nothing.
196 const other = await unproven();
197 expect(letIn(app, admin, other.username, { bundle: "host", machine: "elsewhere", containers: 2, memoryMb: 512 }).ok).toBe(false);
198 expect(letIn(app, admin, other.username, { bundle: "host", machine: "shop-1", containers: 0, memoryMb: 512 }).ok).toBe(false);
199 expect(hostGrantOf(app.db, other.id)).toBeUndefined();
200 expect(emailVerified(app.db, other.id)).toBe(false);
201 });
202
203 test("People's Let in form carries the first machine at the default caps for Host", async () => {
204 const u = await asking();
205 const text = await (await fetch(`${servers.url}/settings/people`, { headers: { cookie } })).text();
206 expect(text).toContain("Host (shop-1,");
207 const res = await post(`/settings/people/${u.username}/let-in`, `bundle=host&machine=shop-1&containers=${HOST_DEFAULTS.containers}&memoryMb=${HOST_DEFAULTS.memoryMb}`);
208 expect(res.status).toBe(303);
209 expect(hostGrantOf(app.db, u.id)).toEqual({ machine: "shop-1", ...HOST_DEFAULTS });
210 });
211
212 test("a guest with no Host sees Ask for Host on their settings; asking adds a row; Approve gives the first machine at the default caps", async () => {
213 const guest = await unproven();
214 const mine = `forge_session=${createSession(app.db, guest.id).token}`;
215 const page = await (await fetch(`${servers.url}/settings`, { headers: { cookie: mine } })).text();
216 expect(page).toContain('id="host"');
217 expect(page).toContain("Ask for Host");
218 expect(askAdmin(app, guest, { want: "host", subject: guest.username }).ok).toBe(true);
219 expect(hostGrantOf(app.db, guest.id)).toBeUndefined();
220 expect(bundleAsks(app, admin).map((a) => `${a.username} ${a.bundle}`)).toContain(`${guest.username} host`);
221 const people = await (await fetch(`${servers.url}/settings/people`, { headers: { cookie } })).text();
222 expect(people).toContain(`${guest.username}</strong> asks for Host`);
223 const res = await post(`/settings/people/asks/host/${guest.username}/approve`);
224 expect(res.status).toBe(303);
225 expect(hostGrantOf(app.db, guest.id)).toEqual({ machine: "shop-1", ...HOST_DEFAULTS });
226 expect(bundleAsks(app, admin).some((a) => a.username === guest.username)).toBe(false);
227 // Once given, the settings page stops offering it.
228 const after = await (await fetch(`${servers.url}/settings`, { headers: { cookie: mine } })).text();
229 expect(after).not.toContain('id="host"');
230 });
231 });
232 });
test/palette-roster.test.ts +1 −1
@@ -216,7 +216,7 @@ test("a site-admin person is offered the whole roster", () => {
216216 ["agents", "Crew agents", "each agent's model, budget and brief"],
217217 ["invites", "Invite links", "make a single-use link, see which are open, revoke one"],
218218 ["claim-start", "Take an agent's work", "claim the repositories an agent started, from its one-time link"],
219 ["requests", "Waiting", "strangers who asked for an account: allow or decline"],
219 ["requests", "Waiting", "strangers who asked for an account: let in or decline"],
220220 ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"],
221221 ["subscriptions", "Crew subscriptions", "each account's budget and rest; wake one, set its budget, add or remove one"],
222222 ["crewkey", "Crew key", "what the crew runs on; add your own model key"],
test/people-let-in-door.test.ts added +109
@@ -0,0 +1,109 @@
1 /**
2 * The terminal side of the People page (#18476, #18477): `l` lets a person in, `a` and `d` approve
3 * or decline an ask for Build; `x` takes one thing away (and refuses an owner), `x name app repo`
4 * takes an app a person was let into, and the Invite links screen shows a waiting link again (`c`)
5 * and makes a new one like it (`n`).
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App as Forge } from "../src/app.ts";
12 import { askAdmin } from "../src/actions/ask_admin.ts";
13 import { roleOf } from "../src/core/roles.ts";
14 import { emailVerified } from "../src/core/verify.ts";
15 import { createUser, getUserByName } from "../src/core/users.ts";
16 import { createForgeApp } from "../src/tui/forge.ts";
17 import { headlessTerminal } from "../src/tui/term/terminal.ts";
18 import { quietLogs } from "./helpers/globals.ts";
19 import { settleApp, settlePalette } from "./helpers/tui.ts";
20
21 quietLogs();
22 let dir = "";
23 let forge: Forge;
24
25 const seed = async (username: string, admin = false) => {
26 const u = await createUser(forge.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: admin });
27 if (!u.ok) throw new Error(u.error);
28 return u.value;
29 };
30
31 beforeAll(async () => {
32 dir = await mkdtemp(join(tmpdir(), "forge-people-letin-"));
33 forge = createApp({ dataDir: dir, port: 0 });
34 await seed("alice", true);
35 const bob = await seed("bobby");
36 forge.db.run("INSERT INTO member (user_id, promoted_by, promoted_at) VALUES (?1, ?1, '2026-01-01T00:00:00Z')", [bob.id]);
37 await seed("carol");
38 await seed("dave");
39 forge.db.run("INSERT INTO repo (id, owner_id, name, visibility) VALUES ('r-notes', ?1, 'notes', 'private')", [bob.id]);
40 forge.db.run("INSERT INTO app (id, repo_id, slug, access) VALUES ('a-notes', 'r-notes', 'notes', 'private')");
41 forge.db.run("INSERT INTO app_member (app_id, user_id, added_by) VALUES ('a-notes', ?1, ?1)", [bob.id]);
42 });
43 afterAll(async () => {
44 forge.close();
45 await rm(dir, { recursive: true, force: true });
46 });
47
48 function boot(screen: string) {
49 const terminal = headlessTerminal(140, 32);
50 const { app } = createForgeApp(forge, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: getUserByName(forge.db, "alice")! }, { terminal, exitHooks: false, toastMs: 10 * 60_000 });
51 app.start();
52 const press = async (...keys: string[]) => {
53 for (const key of keys) app.dispatch({ type: "key", key, ctrl: false, alt: false, shift: false });
54 await settleApp(app);
55 };
56 const type = async (t: string) => {
57 for (const ch of t) app.dispatch({ type: "key", key: ch, ctrl: false, alt: false, shift: false });
58 await settleApp(app);
59 };
60 return {
61 app,
62 press,
63 type,
64 text: () => app.screen.toText(),
65 open: async () => {
66 await settleApp(app);
67 app.dispatch({ type: "key", key: "k", ctrl: true, alt: false, shift: false });
68 await settleApp(app);
69 await type(screen);
70 await settlePalette(app);
71 await press("enter");
72 },
73 };
74 }
75
76 describe("People in the terminal: let in, approve, decline", () => {
77 test("l lets a person in with the bundle named, proving the account without mail", async () => {
78 const h = boot("People");
79 await h.open();
80 await h.press("l");
81 await h.type("carol build");
82 await h.press("enter");
83 expect(h.text()).toContain("carol is in, with build.");
84 const carol = getUserByName(forge.db, "carol")!;
85 expect(emailVerified(forge.db, carol.id)).toBe(true);
86 expect(roleOf(forge.db, carol)).toBe("member");
87 h.app.stop();
88 }, 30_000);
89
90 test("a approves an ask for Build and d declines one; the line above the list names who asks", async () => {
91 const dave = getUserByName(forge.db, "dave")!;
92 askAdmin(forge, dave, { want: "build", subject: "dave" });
93 const h = boot("People");
94 await h.open();
95 expect(h.text()).toContain("Asks: dave build");
96 await h.press("d");
97 await h.type("build dave");
98 await h.press("enter");
99 expect(h.text()).toContain("dave's ask for build is gone.");
100 expect(roleOf(forge.db, getUserByName(forge.db, "dave")!)).toBe("guest");
101 askAdmin(forge, dave, { want: "build", subject: "dave" });
102 await h.press("a");
103 await h.type("build dave");
104 await h.press("enter");
105 expect(h.text()).toContain("dave has build.");
106 expect(roleOf(forge.db, getUserByName(forge.db, "dave")!)).toBe("member");
107 h.app.stop();
108 }, 30_000);
109 });
test/request-access-limits.test.ts +3 −3
@@ -218,7 +218,7 @@ describe("the terminal answers requests", () => {
218218 };
219219 };
220220
221 test("Allow and Decline on the selected row, through the same action", async () => {
221 test("Let in and Decline on the selected row, through the same action", async () => {
222222 clearFill();
223223 app.db.query("DELETE FROM account_request WHERE state = 'waiting'").run();
224224 expect((await api("tuia")).status).toBe(202);
@@ -227,8 +227,8 @@ describe("the terminal answers requests", () => {
227227 await h.palette();
228228 expect(h.text()).toContain("tuia");
229229 expect(h.text()).toContain("tuib");
230 await h.press("a");
231 expect(h.text()).toContain("tuia is in.");
230 await h.press("l");
231 expect(h.text()).toContain("tuia is in, with Use.");
232232 expect(getUserByName(app.db, "tuia")?.waitingAt).toBeNull();
233233 await h.press("d");
234234 expect(h.text()).toContain("tuib was declined");
test/request-access.test.ts +3 −3
@@ -110,16 +110,16 @@ describe("request access", () => {
110110 expect(ok.status).toBe(200);
111111 });
112112
113 test("by page: Waiting shows name, note and source with Allow; allowing makes the next load say You're in, once", async () => {
113 test("by page: Waiting shows name, note and source with Let in; letting in makes the next load say You're in, once", async () => {
114114 const accounts = await fetch(`${base}/settings/people`, { headers: { cookie: admin } }).then((r) => r.text());
115115 expect(accounts).toContain('id="waiting"');
116116 expect(accounts).toContain("pagey");
117117 expect(accounts).toContain("a &lt;b&gt;shop&lt;/b&gt; page");
118 expect(accounts).toContain("/settings/accounts/pagey/allow");
118 expect(accounts).toContain("/settings/people/pagey/let-in");
119119 expect(accounts.indexOf('id="waiting"')).toBeLessThan(accounts.indexOf('id="people"'));
120120 // Only an admin, from this origin, may answer.
121121 expect(getUserByName(app.db, "pagey")?.waitingAt).not.toBeNull();
122 const allow = await form("/settings/accounts/pagey/allow?back=home", {}, admin);
122 const allow = await form("/settings/people/pagey/let-in?back=home", { bundle: "use" }, admin);
123123 expect(allow.status).toBe(303);
124124 const signedIn = await signIn("pagey");
125125 expect(signedIn.status).toBe(303);

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

Keyboard shortcuts

Docs