Public: anyone can read this; the crew can change it.
A new contributor hears they were invited, and the exports name contributors #16396
Check · Review · Land · Live done — Landed and live in production.
talk/invite-notice → main 0 commits
6 files
changed +83
−7
docs/features/contributors.md +2 −1
| @@ -6,8 +6,9 @@ row: Invite someone to work on an app: they ask its crew, you land | ||
| 6 | 6 | |
| 7 | 7 | The repository's admin invites a person as a **contributor**. A contributor reads the repository, enters its app and previews, and asks its crew for changes from their own Talk. What they ask lands as pulls the owner lands: a contributor merges nothing, changes no setting, sees no variable or webhook, opens no terminal on the app, and invites nobody. Their asks run on the owner's crew and subscription, so the week's cap holds them as it holds the crew's own work: a run passes the cap only for someone who writes the repository, and that holds for an outsider's run too. |
| 8 | 8 | |
| 9 | - **Talk and MCP**: `invite { repo, who }`, one confirm, makes a person with an account a contributor at once; their Talk works on the app from then on. `invite { repo, who, remove: true }` takes them off; `invite { repo }` lists who works on it (a read, never held). The repository's admin only: a contributor is told it is the admin's, anyone else gets not found. | |
| 9 | - **Talk and MCP**: `invite { repo, who }`, one confirm, makes a person with an account a contributor at once; they hear it on their notice path (`crew/notify.ts`), with a link to their Talk on the app. `invite { repo, who, remove: true }` takes them off; `invite { repo }` lists who works on it (a read, never held). The repository's admin only: a contributor is told it is the admin's, anyone else gets not found. | |
| 10 | 10 | - **The terminal**: on an app's deploys screen, `W` lists who works on it; `a` invites a person by username and `d` takes the one under the cursor off, each after a confirm. |
| 11 | - **Exports**: the owner's account export names who contributes to each repository, by username only; a contributor's names the repositories they contribute to. | |
| 11 | 12 | - **Taking someone off** is at once: every read, app entry and crew direction asks the row on its request. |
| 12 | 13 | |
| 13 | 14 | Someone without an account cannot be invited yet: a one-use link for them is the next step. |
src/actions/invites.ts +18 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | import type { App } from "../app.ts"; |
| 7 | 7 | import { |
| 8 | 8 | addContributor, |
| 9 | contributedSince, | |
| 9 | 10 | listContributors, |
| 10 | 11 | listInvites, |
| 11 | 12 | mintInvite, |
| @@ -14,7 +15,7 @@ import { | ||
| 14 | 15 | revokeInvite, |
| 15 | 16 | type Invite, |
| 16 | 17 | } from "../core/invites.ts"; |
| 17 | import { canRead, canWrite, type Repo } from "../core/repos.ts"; | |
| 18 | import { canRead, canWrite, getRepoById, type Repo } from "../core/repos.ts"; | |
| 18 | 19 | import { getUserByName } from "../core/users.ts"; |
| 19 | 20 | import { requireRepoAdmin, type AccessError } from "./access.ts"; |
| 20 | 21 | import { err, ok, type Result } from "../kernel/result.ts"; |
| @@ -133,3 +134,19 @@ export function removeContributorFrom(app: App, actor: User | undefined, repo: R | ||
| 133 | 134 | app.bus.append({ kind: "repo.contributor_removed", repoId: repo.id, actorId: admin.value.id, payload: { username: person.username } }); |
| 134 | 135 | return ok(undefined); |
| 135 | 136 | } |
| 137 | ||
| 138 | /** | |
| 139 | * The notice a new contributor hears (`crew/notify.ts`, the forge's one notice path): who let them | |
| 140 | * in where, and their Talk on it. Each is said once, for a week after. | |
| 141 | */ | |
| 142 | export function contributorLines(app: App, user: User, now: number = Date.now()): { id: string; line: string; items: readonly string[]; link: string }[] { | |
| 143 | if (user.kind !== "user") return []; | |
| 144 | const since = new Date(now - 7 * 86_400_000).toISOString(); | |
| 145 | return contributedSince(app.db, user.id, since).flatMap((c) => { | |
| 146 | const repo = getRepoById(app.db, c.repoId); | |
| 147 | if (repo === undefined) return []; | |
| 148 | const name = `${repo.ownerName}/${repo.name}`; | |
| 149 | const id = `contributor:${repo.id}@${c.at}`; | |
| 150 | return [{ id, line: `${c.by ?? "Its owner"} invited you to work on ${name}: ask Talk for a change.`, items: [id], link: `/talk?about=${encodeURIComponent(name)}` }]; | |
| 151 | }); | |
| 152 | } |
src/core/account_export.ts +25 −4
| @@ -96,9 +96,19 @@ export function accountExport(db: Database, userId: string, extras: ExportExtras | ||
| 96 | 96 | const rows = (table: string) => |
| 97 | 97 | db.query<Record<string, unknown>, [string]>(`SELECT ${cols(table)} FROM ${table} WHERE user_id = ?1 ORDER BY created_at`).all(userId); |
| 98 | 98 | const origin = extras.origin.replace(/\/+$/, ""); |
| 99 | const repositories = db | |
| 100 | .query<{ owner: string; name: string; visibility: string; owns: number }, [string]>( | |
| 101 | `SELECT owner.username AS owner, repo.name, repo.visibility, repo.owner_id = ?1 AS owns | |
| 99 | // Who works on each repository they write, by username only: nothing else of a contributor's. | |
| 100 | const contributors = new Map<string, string[]>(); | |
| 101 | for (const c of db | |
| 102 | .query<{ repo: string; username: string }, [string]>( | |
| 103 | `SELECT rc.repo_id AS repo, person.username AS username | |
| 104 | FROM repo_contributor rc JOIN repo ON repo.id = rc.repo_id JOIN user AS person ON person.id = rc.user_id | |
| 105 | WHERE ${WRITES} ORDER BY person.username`, | |
| 106 | ) | |
| 107 | .all(userId)) | |
| 108 | contributors.set(c.repo, [...(contributors.get(c.repo) ?? []), c.username]); | |
| 109 | const writes = db | |
| 110 | .query<{ id: string; owner: string; name: string; visibility: string; owns: number }, [string]>( | |
| 111 | `SELECT repo.id, owner.username AS owner, repo.name, repo.visibility, repo.owner_id = ?1 AS owns | |
| 102 | 112 | FROM repo JOIN user AS owner ON owner.id = repo.owner_id |
| 103 | 113 | WHERE ${WRITES} ORDER BY owner.username, repo.name`, |
| 104 | 114 | ) |
| @@ -108,11 +118,22 @@ export function accountExport(db: Database, userId: string, extras: ExportExtras | ||
| 108 | 118 | visibility: r.visibility, |
| 109 | 119 | role: r.owns ? "owner" : "writer", |
| 110 | 120 | cloneUrl: `${origin}/${r.owner}/${r.name}.git`, |
| 121 | ...(contributors.has(r.id) ? { contributors: contributors.get(r.id)! } : {}), | |
| 111 | 122 | })); |
| 123 | // The repositories they were invited to work on: theirs to know, as a name and a role. | |
| 124 | const contributes = db | |
| 125 | .query<{ owner: string; name: string; visibility: string }, [string]>( | |
| 126 | `SELECT owner.username AS owner, repo.name, repo.visibility | |
| 127 | FROM repo_contributor rc JOIN repo ON repo.id = rc.repo_id JOIN user AS owner ON owner.id = repo.owner_id | |
| 128 | WHERE rc.user_id = ?1 ORDER BY owner.username, repo.name`, | |
| 129 | ) | |
| 130 | .all(userId) | |
| 131 | .map((r) => ({ name: `${r.owner}/${r.name}`, visibility: r.visibility, role: "contributor", cloneUrl: `${origin}/${r.owner}/${r.name}.git` })); | |
| 132 | const repositories = [...writes, ...contributes]; | |
| 112 | 133 | return { |
| 113 | 134 | about: |
| 114 | 135 | "Everything this forge holds about you: profile (with your email and which address your commits use), SSH key names and fingerprints, token names and scopes, " + |
| 115 | "signed-in devices, the repositories you own or write, your forges and payments. No password, token, session id or secret is in it.", | |
| 136 | "signed-in devices, the repositories you own or write (with who contributes to each, by name) or contribute to, your forges and payments. No password, token, session id or secret is in it.", | |
| 116 | 137 | exportedAt: new Date().toISOString(), |
| 117 | 138 | profile, |
| 118 | 139 | sshKeys: rows("user_key"), |
src/core/invites.ts +15
| @@ -186,3 +186,18 @@ export function listContributors( | ||
| 186 | 186 | ) |
| 187 | 187 | .all(repoId); |
| 188 | 188 | } |
| 189 | ||
| 190 | /** The repositories `userId` was made a contributor to since `since`, newest first. */ | |
| 191 | export function contributedSince( | |
| 192 | db: Database, | |
| 193 | userId: string, | |
| 194 | since: string, | |
| 195 | ): { repoId: string; at: string; by: string | null }[] { | |
| 196 | return db | |
| 197 | .query<{ repoId: string; at: string; by: string | null }, [string, string]>( | |
| 198 | `SELECT c.repo_id AS repoId, c.at AS at, b.username AS by | |
| 199 | FROM repo_contributor c INDEXED BY repo_contributor_user LEFT JOIN user b ON b.id = c.by_id | |
| 200 | WHERE c.user_id = ?1 AND c.at >= ?2 ORDER BY c.at DESC LIMIT 20`, | |
| 201 | ) | |
| 202 | .all(userId, since); | |
| 203 | } |
src/crew/notify.ts +2
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | import { blockedLines } from "../actions/egress_refused.ts"; |
| 24 | 24 | import { scheduleLines } from "../actions/schedules.ts"; |
| 25 | 25 | import { newAccountLines } from "../actions/accounts.ts"; |
| 26 | import { contributorLines } from "../actions/invites.ts"; | |
| 26 | 27 | import { requestLines } from "../actions/requests.ts"; |
| 27 | 28 | import { mailCeilingLines } from "../actions/mail.ts"; |
| 28 | 29 | import { forgetOnboarding, onboardedLines } from "../apps/onboarding.ts"; |
| @@ -532,6 +533,7 @@ export function startNotifier(app: App, options: NotifyOptions): Notifier { | ||
| 532 | 533 | ...onboardedLines(app.db, user, now()), |
| 533 | 534 | ...blockedLines(app, user, now()), |
| 534 | 535 | ...scheduleLines(app, user), |
| 536 | ...contributorLines(app, user, now()), | |
| 535 | 537 | ]; |
| 536 | 538 | const before = seen.get(userId); |
| 537 | 539 | // What is gone may ask again later, and then it is new again. Seen by |
test/invite-contributors.test.ts +21 −1
| @@ -39,6 +39,8 @@ import { createToken } from "../src/core/tokens.ts"; | ||
| 39 | 39 | import { createUser, type User } from "../src/core/users.ts"; |
| 40 | 40 | import { createWebhook } from "../src/core/webhooks.ts"; |
| 41 | 41 | import { mayDirectCrew } from "../src/crew/direct.ts"; |
| 42 | import { accountExport } from "../src/core/account_export.ts"; | |
| 43 | import { contributorLines } from "../src/actions/invites.ts"; | |
| 42 | 44 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 43 | 45 | import { contributorsScreen } from "../src/tui/screens/deploys.ts"; |
| 44 | 46 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| @@ -196,7 +198,7 @@ beforeAll(async () => { | ||
| 196 | 198 | afterAll(() => stopStandInCrew(standIn), 30_000); |
| 197 | 199 | |
| 198 | 200 | describe("a contributor: reads, enters, directs; nothing outside the repository", () => { |
| 199 | test("a contributor reads the repository, enters its app but never its terminal, directs its crew", async () => { | |
| 201 | test("a contributor reads the repository, enters its app but never its terminal, directs its crew, and hears it", async () => { | |
| 200 | 202 | const { app } = standIn; |
| 201 | 203 | expect([ |
| 202 | 204 | canRead(app.db, fresh(), ben), |
| @@ -219,6 +221,24 @@ describe("a contributor: reads, enters, directs; nothing outside the repository" | ||
| 219 | 221 | ); |
| 220 | 222 | expect(readableRepoIds(app.db, ben, [repo.id]).has(repo.id)).toBe(true); |
| 221 | 223 | expect((await page(ben, `/${name()}`)).status).toBe(200); |
| 224 | // The notice path says it, with his Talk on the app. | |
| 225 | expect(contributorLines(app, ben)).toEqual([ | |
| 226 | expect.objectContaining({ | |
| 227 | line: "alice invited you to work on alice/garden: ask Talk for a change.", | |
| 228 | link: "/talk?about=alice%2Fgarden", | |
| 229 | }), | |
| 230 | ]); | |
| 231 | }); | |
| 232 | ||
| 233 | test("each one's export says it: the owner's names who contributes and nothing else of theirs; ben's names the repository", () => { | |
| 234 | const { app } = standIn; | |
| 235 | const of = (who: User) => accountExport(app.db, who.id, { origin: url, forges: [], payments: [] })!; | |
| 236 | const owners = of(alice).repositories.find((r) => r.name === name())!; | |
| 237 | expect(owners).toMatchObject({ role: "owner", contributors: ["ben"] }); | |
| 238 | expect(JSON.stringify(of(alice))).not.toContain("[email protected]"); | |
| 239 | expect(of(ben).repositories).toContainEqual(expect.objectContaining({ name: name(), role: "contributor" })); | |
| 240 | // Nobody contributes to the other repository: it names nobody. | |
| 241 | expect(of(alice).repositories.find((r) => r.name === "alice/vault")).not.toHaveProperty("contributors"); | |
| 222 | 242 | }); |
| 223 | 243 | |
| 224 | 244 | test("a contributor walks every Talk tool and nothing the owner alone is told answers: no other repository, no subscription", async () => { |
new above
offline