Public: anyone can read this; the crew can change it.
A report an outsider files shows up for the owner as one row with who sent it and what it asks, in the inbox #15881
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15840-a-report-an-outsider-files-shows-up-for → main 0 commits fork 5 threads · 5 unresolved
docs/design/areas/next-up.md +4
| @@ -11,3 +11,7 @@ The head is `pageHead("Next up")` with one sentence: the crew builds strictly fr | ||
| 11 | 11 | ## One numbered queue, folded (#11619) |
| 12 | 12 | |
| 13 | 13 | `/:owner/:name/next` is the dispatcher's whole order as one numbered list: each row's lead is its position (1 at the top, continuing across folds), and its meta reads `#N · <state> · <who or "next">`. The state is one word from `web/pages/next_state.ts`: building, checking, in review, landing, waiting on #N, held or ready. The rows sit in three native `<details>` (no script, no new class): "Up next" (the first ten, open), "After" (the rest, closed) and "Later" (behind the Later gate, closed), each heading carrying its count. `?all=1` is gone; every fold is already in the page. |
| 14 | ||
| 15 | ## From outside (#15840) | |
| 16 | ||
| 17 | `.outsider-acts` is the Adopt and Decline pair under a waiting report's row in /next: two 44px buttons, and the one-line reason on its own line below them, so it holds at 360px with JS off. |
docs/features/next-up.md +2
| @@ -36,3 +36,5 @@ The subscription's weekly reset is the sprint boundary; what the crew may still | ||
| 36 | 36 | - **Live:** a drag posts the move and the page reloads itself from the server, which redraws the line; there is no manual reload, but it is a reload, not a client-side recompute. |
| 37 | 37 | - **Terminal:** Next up shows each row's range and a muted "this week ends here" line under the last issue that fits (by pace, "by pace: this week ends here"), with the projection in the header. "The week in a repository" (palette) shows the retrospective; `j`/`k` choose a proposal and `enter` or `a` takes it, through the same `takeProposal`. A reader or an agent sees it and the key does nothing; a new retrospective (`week.retro`) or a proposal taken anywhere updates the open screen. MCP `next_up` rows carry `estimate` and `thisWeek` (above the pace line when the line is by pace), with a `projection` sentence. |
| 38 | 38 | - Sealed issues are left out of history and of the retrospective, so their cost never shapes a visible range. |
| 39 | ||
| 40 | **From outside (#15840):** above the list, a writer sees each waiting report from an outsider as one row: who sent it (`@name`, "claims to be x, unproven" or "anonymous"), the one-line ask (its title, escaped, at most 140 characters) and two plain forms. *Adopt* opens the report as an issue behind the outside marker (`acceptReport`); *Decline* closes it with one line of why (`dismissReport`; empty says "Not something we will take up right now."), which the sender reads as `reason` at their status link. Both post to `POST /:owner/:name/next` (`report`, `decision` = `adopt` or `decline`, `reason`) and come back to the same page. Offers (outside pulls) are not rows here: they stay on the pulls list (a follow-up, not this change). At 360px the reason takes its own line under the buttons. **Terminal:** the reports screen's `d` opens a prompt for one line of why (empty says the same default) and sends it to the sender's status link; the words come from `actions/outsider_decision.ts`. Pinned by `test/next-outsider-report.test.ts`. |
docs/features/report-status.md +1 −1
| @@ -17,7 +17,7 @@ account and says what became of the report in four words: | ||
| 17 | 17 | An issue closed for any other reason (split, parked, or a reason added later) reads as `being worked`: it was taken |
| 18 | 18 | up and is neither fixed nor turned down. |
| 19 | 19 | |
| 20 | Only `{id, status, message}` leaves: no title, no author, no issue number. An unknown id, a malformed one, another | |
| 20 | Only `{id, status, message}` leaves, plus `reason` on a declined report when the person who declined it wrote one (the owner's one line, up to 200 characters, from the Decline on `/next`): no title, no author, no issue number. An unknown id, a malformed one, another | |
| 21 | 21 | repository's and a private repository's all answer the same 404. |
| 22 | 22 | |
| 23 | 23 | - **JSON:** `GET /api/v1/repos/:owner/:name/reports/:id/status`, the `statusUrl` of the receipt (also its `Location`). |
src/actions/outsider_decision.ts added +88
| @@ -0,0 +1,88 @@ | ||
| 1 | /** | |
| 2 | * An outsider's report decided from the owner's queue (#15840): one row each (who sent it, what it | |
| 3 | * asks) and two answers, Adopt and Decline. Adopt is `acceptReport` (an issue in the plan, behind | |
| 4 | * the outside marker); Decline is `dismissReport` with one line of why, which the sender reads at | |
| 5 | * their status link. The page and the terminal share these words and this gate. | |
| 6 | */ | |
| 7 | import type { App } from "../app.ts"; | |
| 8 | import { countWaiting, filerWords } from "../core/reports.ts"; | |
| 9 | import type { Repo } from "../core/repos.ts"; | |
| 10 | import type { User } from "../core/users.ts"; | |
| 11 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 12 | import { acceptReport, dismissReport, waitingReports } from "./reports.ts"; | |
| 13 | ||
| 14 | /** What a decline says when the owner types nothing: a tap is enough. */ | |
| 15 | export const DEFAULT_DECLINE = "Not something we will take up right now."; | |
| 16 | ||
| 17 | /** The longest ask a row shows; the report page has the rest. */ | |
| 18 | const ASK_MAX = 140; | |
| 19 | ||
| 20 | export interface OutsiderRow { | |
| 21 | readonly id: string; | |
| 22 | /** `@name`, `claims to be name, unproven` or `anonymous`. */ | |
| 23 | readonly sender: string; | |
| 24 | /** The report's title, one line. */ | |
| 25 | readonly ask: string; | |
| 26 | readonly createdAt: string; | |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * The most rows the queue shows; the rest wait on the reports page, so filing cannot grow /next. | |
| 31 | */ | |
| 32 | export const OUTSIDER_ROWS_MAX = 20; | |
| 33 | ||
| 34 | /** The oldest waiting reports as rows, and how many wait in all. */ | |
| 35 | export interface OutsiderShelf { | |
| 36 | readonly rows: readonly OutsiderRow[]; | |
| 37 | readonly total: number; | |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * The oldest `OUTSIDER_ROWS_MAX` waiting reports and the total; nothing for anyone who may not | |
| 42 | * decide them. | |
| 43 | */ | |
| 44 | export function outsiderRows(app: App, actor: User | undefined, repo: Repo): OutsiderShelf { | |
| 45 | const waiting = waitingReports(app, actor, repo, OUTSIDER_ROWS_MAX); | |
| 46 | if (!waiting.ok) return { rows: [], total: 0 }; | |
| 47 | const rows = waiting.value.map((r) => ({ | |
| 48 | id: r.id, | |
| 49 | sender: filerWords(r.filedBy), | |
| 50 | ask: r.title.length > ASK_MAX ? `${r.title.slice(0, ASK_MAX - 1)}…` : r.title, | |
| 51 | createdAt: r.createdAt, | |
| 52 | })); | |
| 53 | return { rows, total: rows.length < OUTSIDER_ROWS_MAX ? rows.length : countWaiting(app.db, repo.id) }; | |
| 54 | } | |
| 55 | ||
| 56 | export type Decision = "adopt" | "decline"; | |
| 57 | ||
| 58 | /** `adopt` or `decline`, else undefined. */ | |
| 59 | export const decisionOf = (raw: string): Decision | undefined => | |
| 60 | raw === "adopt" || raw === "decline" ? raw : undefined; | |
| 61 | ||
| 62 | /** Why a decision did not happen: nothing to see for this person, or a sentence to show. */ | |
| 63 | export type DecisionError = { readonly kind: "not_found" } | { readonly kind: "refused"; readonly message: string }; | |
| 64 | ||
| 65 | const NOT_FOUND: DecisionError = { kind: "not_found" }; | |
| 66 | const refused = (message: string): DecisionError => ({ kind: "refused", message }); | |
| 67 | ||
| 68 | /** The sentence the owner reads after the move, or the typed refusal. */ | |
| 69 | export async function decideOutsider( | |
| 70 | app: App, | |
| 71 | actor: User | undefined, | |
| 72 | repo: Repo, | |
| 73 | reportId: string, | |
| 74 | decision: Decision, | |
| 75 | reason = "", | |
| 76 | ): Promise<Result<string, DecisionError>> { | |
| 77 | if (decision === "adopt") { | |
| 78 | const done = await acceptReport(app, actor, repo, reportId); | |
| 79 | if (done.ok) return ok(`Adopted as issue #${done.value.number}.`); | |
| 80 | if (done.error === "decided") return err(refused("Someone already decided that report.")); | |
| 81 | if (done.error === "not_found" || done.error === "forbidden" || done.error === "unauthorized") return err(NOT_FOUND); | |
| 82 | return err(refused("That report could not become an issue.")); | |
| 83 | } | |
| 84 | const done = dismissReport(app, actor, repo, reportId, reason.trim() === "" ? DEFAULT_DECLINE : reason); | |
| 85 | if (done.ok) return ok("Declined. The sender can read why at their status link."); | |
| 86 | if (done.error === "decided") return err(refused("Someone already decided that report.")); | |
| 87 | return err(NOT_FOUND); | |
| 88 | } |
src/actions/reports.ts +5 −1
| @@ -39,6 +39,7 @@ import { | ||
| 39 | 39 | listWaiting, |
| 40 | 40 | noteIssue, |
| 41 | 41 | outsideTitle, |
| 42 | reasonOf, | |
| 42 | 43 | undecideReport, |
| 43 | 44 | type Report, |
| 44 | 45 | type ReportError, |
| @@ -150,10 +151,11 @@ export function waitingReports( | ||
| 150 | 151 | app: App, |
| 151 | 152 | actor: User | undefined, |
| 152 | 153 | repo: Repo, |
| 154 | limit?: number, | |
| 153 | 155 | ): Result<Report[], DeciderError> { |
| 154 | 156 | const decider = requireDecider(app, actor, repo); |
| 155 | 157 | if (!decider.ok) return decider; |
| 156 | return ok(listWaiting(app.db, repo.id)); | |
| 158 | return ok(listWaiting(app.db, repo.id, limit)); | |
| 157 | 159 | } |
| 158 | 160 | |
| 159 | 161 | /** A report as the API and the MCP answer it. */ |
| @@ -325,6 +327,7 @@ export function dismissReport( | ||
| 325 | 327 | actor: User | undefined, |
| 326 | 328 | repo: Repo, |
| 327 | 329 | reportId: string, |
| 330 | reason = "", | |
| 328 | 331 | ): Result<true, DecideError> { |
| 329 | 332 | const decider = requireDecider(app, actor, repo); |
| 330 | 333 | if (!decider.ok) return decider; |
| @@ -334,6 +337,7 @@ export function dismissReport( | ||
| 334 | 337 | !decideReport(app.db, report.id, { |
| 335 | 338 | state: "dismissed", |
| 336 | 339 | by: decider.value.id, |
| 340 | reason: reasonOf(reason), | |
| 337 | 341 | }) |
| 338 | 342 | ) |
| 339 | 343 | return err("decided"); |
src/core/migration-pins/20261123110000-report-reason.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 124c2f9e2e215029e52dda80f5b437bbd7b11c0968f9a46fb8e447569e38b8ae |
src/core/migrations/20261123110000-report-reason.ts added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | // A person who declines a report from outside writes one line of why (#15840); the sender reads | |
| 2 | // it at their status link. Null for a report decided before this, or dismissed without one. | |
| 3 | export default ` | |
| 4 | ALTER TABLE report ADD COLUMN reason TEXT; | |
| 5 | `; |
src/core/reports.ts +19 −7
| @@ -270,14 +270,14 @@ export function getReport( | ||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** Waiting reports, oldest first: the order they should be read in. */ |
| 273 | export function listWaiting(db: Database, repoId: string): Report[] { | |
| 273 | export function listWaiting(db: Database, repoId: string, limit = WAITING_MAX): Report[] { | |
| 274 | 274 | return ( |
| 275 | 275 | db |
| 276 | 276 | .query( |
| 277 | 277 | `${SELECT_REPORT} WHERE report.repo_id = ?1 AND report.state = 'pending' |
| 278 | 278 | ORDER BY report.id LIMIT ?2`, |
| 279 | 279 | ) |
| 280 | .all(repoId, WAITING_MAX) as ReportRow[] | |
| 280 | .all(repoId, Math.min(limit, WAITING_MAX)) as ReportRow[] | |
| 281 | 281 | ).map(fromRow); |
| 282 | 282 | } |
| 283 | 283 | |
| @@ -321,19 +321,27 @@ export function filerWords(by: FiledBy): string { | ||
| 321 | 321 | export function decideReport( |
| 322 | 322 | db: Database, |
| 323 | 323 | reportId: string, |
| 324 | decision: { state: "accepted" | "dismissed"; by: string }, | |
| 324 | decision: { state: "accepted" | "dismissed"; by: string; reason?: string }, | |
| 325 | 325 | ): boolean { |
| 326 | 326 | return ( |
| 327 | 327 | db |
| 328 | 328 | .query( |
| 329 | `UPDATE report SET state = ?2, decided_by = ?3, | |
| 329 | `UPDATE report SET state = ?2, decided_by = ?3, reason = ?4, | |
| 330 | 330 | decided_at = strftime('%Y-%m-%dT%H:%M:%fZ','now') |
| 331 | 331 | WHERE id = ?1 AND state = 'pending'`, |
| 332 | 332 | ) |
| 333 | .run(reportId, decision.state, decision.by).changes === 1 | |
| 333 | .run(reportId, decision.state, decision.by, decision.reason ?? null).changes === 1 | |
| 334 | 334 | ); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | /** The longest reason a decline carries, in characters. */ | |
| 338 | export const REASON_MAX = 200; | |
| 339 | ||
| 340 | /** A decline's reason as stored: one line of plain text, cut at `REASON_MAX`; empty is none. */ | |
| 341 | export function reasonOf(raw: string): string { | |
| 342 | return plainText(raw).replace(/\s+/g, " ").trim().slice(0, REASON_MAX); | |
| 343 | } | |
| 344 | ||
| 337 | 345 | /** The issue an accepted report became. */ |
| 338 | 346 | export function noteIssue(db: Database, reportId: string, issueNumber: number): void { |
| 339 | 347 | db.query("UPDATE report SET issue_number = ?2 WHERE id = ?1").run( |
| @@ -397,6 +405,8 @@ export interface ReportStatus { | ||
| 397 | 405 | readonly id: string; |
| 398 | 406 | readonly status: PublicStatus; |
| 399 | 407 | readonly message: string; |
| 408 | /** The one line a person gave when they declined it; absent when none was given. */ | |
| 409 | readonly reason?: string; | |
| 400 | 410 | } |
| 401 | 411 | |
| 402 | 412 | /** The shape a receipt id has: what `id()` makes. Anything else is not looked up. */ |
| @@ -410,6 +420,7 @@ interface Row { | ||
| 410 | 420 | readonly issue_state: string | null; |
| 411 | 421 | readonly close_reason: string | null; |
| 412 | 422 | readonly parked: number | null; |
| 423 | readonly reason: string | null; | |
| 413 | 424 | } |
| 414 | 425 | |
| 415 | 426 | export function reportStatus(db: Database, repoId: string, reportId: string): ReportStatus | undefined { |
| @@ -417,14 +428,15 @@ export function reportStatus(db: Database, repoId: string, reportId: string): Re | ||
| 417 | 428 | const row = db |
| 418 | 429 | .query( |
| 419 | 430 | `SELECT report.id, report.state, report.issue_number, |
| 420 | issue.state AS issue_state, issue.close_reason, issue.parked | |
| 431 | issue.state AS issue_state, issue.close_reason, issue.parked, report.reason | |
| 421 | 432 | FROM report LEFT JOIN issue ON issue.repo_id = report.repo_id AND issue.number = report.issue_number |
| 422 | 433 | WHERE report.repo_id = ?1 AND report.id = ?2`, |
| 423 | 434 | ) |
| 424 | 435 | .get(repoId, reportId) as Row | null; |
| 425 | 436 | if (row === null) return undefined; |
| 426 | 437 | const status = statusOf(row); |
| 427 | return { id: row.id, status, message: STATUS_WORDS[status] }; | |
| 438 | const said = status === "declined" && row.state === "dismissed" && row.reason !== null && row.reason !== ""; | |
| 439 | return { id: row.id, status, message: STATUS_WORDS[status], ...(said ? { reason: row.reason! } : {}) }; | |
| 428 | 440 | } |
| 429 | 441 | |
| 430 | 442 | /** |
src/tui/screens/reports.ts +15 −12
| @@ -4,13 +4,14 @@ | ||
| 4 | 4 | * already show. The row is "Reports (N)" and appears only while N > 0 for a |
| 5 | 5 | * person who may decide them — `waitingCount` is 0 to everyone else. `a` |
| 6 | 6 | * accepts the report under the cursor as an issue (its own title, behind the |
| 7 | * "From outside" marker) and says the number; `d` dismisses after a confirm. | |
| 8 | * Every rule is the action's (`actions/reports.ts`). | |
| 7 | * "From outside" marker) and says the number; `d` declines with one line of why (empty says the | |
| 8 | * default), which the sender reads. Every rule is the action's (`actions/reports.ts`). | |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | import { REPORT_ALREADY_DECIDED } from "../../actions/origin_app_words.ts"; |
| 12 | import { DEFAULT_DECLINE } from "../../actions/outsider_decision.ts"; | |
| 12 | 13 | import { acceptReport, dismissReport, waitingCount, waitingReports } from "../../actions/reports.ts"; |
| 13 | import { byFiler, filerWords, isOverdue, type Report } from "../../core/reports.ts"; | |
| 14 | import { byFiler, filerWords, isOverdue, REASON_MAX, type Report } from "../../core/reports.ts"; | |
| 14 | 15 | import type { Repo } from "../../core/repos.ts"; |
| 15 | 16 | import { linkIssue } from "../../actions/dependencies.ts"; |
| 16 | 17 | import { setIssueStateThrough } from "../../actions/issues.ts"; |
| @@ -23,7 +24,7 @@ import { style } from "../term/style.ts"; | ||
| 23 | 24 | import { truncate, wrap } from "../term/width.ts"; |
| 24 | 25 | import type { Session } from "../session.ts"; |
| 25 | 26 | import { beside, fill, len, pct, split } from "../ui/layout.ts"; |
| 26 | import { ListState, ago, confirmScreen, drawList, errorText, promptScreen, runAsync, type ListRow } from "./common.ts"; | |
| 27 | import { ListState, ago, drawList, errorText, promptScreen, runAsync, type ListRow } from "./common.ts"; | |
| 27 | 28 | |
| 28 | 29 | /** The palette row for `repo`: only while reports wait, only to a decider. */ |
| 29 | 30 | export function reportsCommands(f: Session, ctx: Ctx, repo: Repo | undefined): Command[] { |
| @@ -217,15 +218,17 @@ export function reportsScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 217 | 218 | if (e.key === "d") { |
| 218 | 219 | if (picked === undefined) return false; |
| 219 | 220 | ctx.push( |
| 220 | confirmScreen(ctx, screen, { | |
| 221 | title: "Dismiss this report", | |
| 222 | body: [picked.title, "No issue is opened."], | |
| 223 | actions: [{ label: "Keep waiting", variant: "ghost" }, { label: "Dismiss" }], | |
| 224 | onChoose: (i) => { | |
| 225 | if (i < 1) return; | |
| 226 | const done = dismissReport(f.app, f.user, repo, picked.id); | |
| 227 | note = done.ok ? "Dismissed." : refusal(done.error); | |
| 221 | promptScreen(ctx, screen, { | |
| 222 | title: "Decline this report", | |
| 223 | label: "Why, for the sender (empty says the default)", | |
| 224 | placeholder: DEFAULT_DECLINE, | |
| 225 | hint: "The sender reads this at their status link. No issue is opened.", | |
| 226 | onSubmit: (value) => { | |
| 227 | if (value.length > REASON_MAX) return `at most ${REASON_MAX} characters`; | |
outdated
Both doors: the page lets the owner write one line of why; the terminal always sends DEFAULT_DECLINE, so a person at the terminal cannot give the sender a reason. Add a text prompt (or a reason field in the dialog) that feeds dismissReport, and say so in docs/features/next-up.md. Also a screen test that a typed reason reaches the status link. |
||
| 228 | const done = dismissReport(f.app, f.user, repo, picked.id, value.trim() === "" ? DEFAULT_DECLINE : value); | |
| 229 | note = done.ok ? "Declined. The sender can read why." : refusal(done.error); | |
| 228 | 230 | ctx.invalidate(); |
| 231 | return undefined; | |
| 229 | 232 | }, |
| 230 | 233 | }), |
| 231 | 234 | ); |
src/web/pages/next.ts +47 −1
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | * beside each action (`j`/`k` choose the row), which post the same form. |
| 8 | 8 | */ |
| 9 | 9 | import { keyStep } from "./next_keys.ts"; |
| 10 | import { DEFAULT_DECLINE, decideOutsider, decisionOf, outsiderRows } from "../../actions/outsider_decision.ts"; | |
| 11 | import { REASON_MAX } from "../../core/reports.ts"; | |
| 10 | 12 | import { placeOf, rankIssue, rankedWords, stepTo, type Place } from "../../actions/next.ts"; |
| 11 | 13 | import { currentByNumber } from "../../core/estimates.ts"; |
| 12 | 14 | import { estimateLine } from "../../flow/estimate_words.ts"; |
| @@ -26,7 +28,7 @@ import { crumbsFor, loadRepo, notFoundPage, pageHead, repoBase, repoHeader, repo | ||
| 26 | 28 | import { backTo, field, readForm } from "../form.ts"; |
| 27 | 29 | import { html, raw, type Html } from "../html.ts"; |
| 28 | 30 | import { flashOrJson, page } from "../layout.ts"; |
| 29 | import { btn, kbd, listCard, row } from "../ui.ts"; | |
| 31 | import { btn, kbd, listCard, row, time } from "../ui.ts"; | |
| 30 | 32 | import { GROWTH_DAYS, growthLine } from "./next_growth.ts"; |
| 31 | 33 | import { listChapters } from "../../core/chapters.ts"; |
| 32 | 34 | import { chapterLine, chaptersSection } from "./next_chapters.ts"; |
| @@ -213,6 +215,42 @@ function walletRow(ctx: Ctx, repo: Repo, base: string): Html | null { | ||
| 213 | 215 | return listCard([row({ id: "wallet-row", href: `${base}/wallet`, title: html`Raise the monthly cap`, nav: true })]); |
| 214 | 216 | } |
| 215 | 217 | |
| 218 | /** | |
| 219 | * From outside (#15840): each waiting report as one row, who sent it and what it asks, with Adopt | |
| 220 | * and Decline as plain forms that post here and come back here. A decline carries one line of why | |
| 221 | * (the sender reads it at their status link); left empty it says the default. Writers only. | |
| 222 | */ | |
| 223 | function outsiderSection(ctx: Ctx, repo: Repo, base: string, back: string): Html | null { | |
| 224 | const { rows, total } = ctx.auth.user === undefined || ctx.auth.user.kind === "agent" ? { rows: [], total: 0 } : outsiderRows(ctx.app, ctx.auth.user, repo); | |
outdated
Unbounded: outsiderRows returns every waiting report and each renders two forms plus an input. Cap the rows rendered (e.g. 20, oldest first), link the rest to the reports page, and test it. |
||
| 225 | if (rows.length === 0) return null; | |
| 226 | const more = total - rows.length; | |
| 227 | const form = (id: string, decision: string, extra: Html | null, label: Html): Html => html`<form method="post" action="${base}/next" class="form-actions"> | |
| 228 | <input type="hidden" name="report" value="${id}" /> | |
| 229 | <input type="hidden" name="decision" value="${decision}" /> | |
| 230 | <input type="hidden" name="back" value="${back}" /> | |
| 231 | ${extra}${btn(label, { variant: decision === "adopt" ? "primary" : "outline", size: "sm" })} | |
| 232 | </form>`; | |
| 233 | return html`<section class="mt" id="outsiders"> | |
| 234 | <h2>From outside · ${String(total)}</h2> | |
| 235 | ${listCard(rows.map((r) => | |
| 236 | row({ | |
| 237 | href: `${base}/reports`, | |
| 238 | title: html`${r.ask}`, | |
| 239 | titleAttr: r.ask, | |
outdated
Principle 1 and 8: the decorative |
||
| 240 | meta: html`${r.sender} · ${time(r.createdAt)}`, | |
| 241 | data: { report: r.id }, | |
| 242 | after: html`<div class="outsider-acts">${form(r.id, "adopt", null, html`Adopt`)}${form( | |
| 243 | r.id, | |
| 244 | "decline", | |
| 245 | html`<input class="input" name="reason" type="text" maxlength="${String(REASON_MAX)}" placeholder="${DEFAULT_DECLINE}" aria-label="Why, for the sender" autocomplete="off" />`, | |
Principle 3 (generous rhythm): each row carries a title link, an Adopt form, and a Decline form with a full text input. At 360px that is three controls plus a meta line in one row. Make |
||
| 246 | html`Decline`, | |
| 247 | )}</div>`, | |
| 248 | }), | |
| 249 | ))} | |
| 250 | ${more > 0 ? html`<p class="muted" id="outsiders-more">and ${String(more)} more on <a href="${base}/reports">the reports page</a></p>` : null} | |
| 251 | </section>`; | |
| 252 | } | |
| 253 | ||
| 216 | 254 | export function nextPage(ctx: Ctx): Response { |
| 217 | 255 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 218 | 256 | const repo = loadRepo(ctx); |
| @@ -276,6 +314,7 @@ export function nextPage(ctx: Ctx): Response { | ||
| 276 | 314 | ${chapterLine(ctx, repo, chapters)} |
| 277 | 315 | ${growthLine(week7, pauseAt(week7, new Date()), writer && canAdmin(ctx.app.db, repo, ctx.auth.user!), base, back)} |
| 278 | 316 | <p class="error" id="next-flash" role="alert" hidden></p> |
| 317 | ${outsiderSection(ctx, repo, base, back)} | |
| 279 | 318 | ${rows.length === 0 |
| 280 | 319 | ? html`<p class="muted">Nothing is ready: everything open waits for something. <a href="${base}/map">See the map</a>.</p>` |
| 281 | 320 | : html`${bar}${isFiltered ? html`<p class="muted" id="next-count">${countWords(ats.length, rows.length)} shown${ats.length + parked.length === 0 ? html`. ${nothingWords}` : null}. Numbers and the cut line are the whole list's; the week's capacity bar is left out while filtered.</p>` : null} |
| @@ -318,6 +357,13 @@ export async function nextSubmit(ctx: Ctx): Promise<Response> { | ||
| 318 | 357 | const form = await readForm(ctx, "rw"); |
| 319 | 358 | if (form instanceof Response) return form; |
| 320 | 359 | const dest = backTo(form, `${repoBase(repo)}/next`); |
| 360 | if (form.has("report")) { | |
| 361 | const decision = decisionOf(field(form, "decision")); | |
| 362 | if (decision === undefined) return flashOrJson(ctx, dest, { tone: "danger", message: "Say adopt or decline." }); | |
| 363 | const decided = await decideOutsider(ctx.app, ctx.auth.user, repo, field(form, "report"), decision, field(form, "reason")); | |
| 364 | if (decided.ok) return flashOrJson(ctx, dest, { message: decided.value }); | |
| 365 | return decided.error.kind === "not_found" ? notFoundPage(ctx) : flashOrJson(ctx, dest, { tone: "danger", message: decided.error.message }); | |
| 366 | } | |
| 321 | 367 | const place: Place | undefined = placeOf(field(form, "to")); |
| 322 | 368 | const number = /^[1-9][0-9]{0,8}$/.test(field(form, "number")) ? Number(field(form, "number")) : 0; |
| 323 | 369 | if (place === undefined || number === 0) |
src/web/style/components.ts +7
| @@ -575,6 +575,13 @@ span.ex-pic { display: inline-flex; align-items: center; justify-content: center | ||
| 575 | 575 | /* A control beside a link row, outside the link: the row takes the width, the control keeps its own. */ |
| 576 | 576 | .list > li.has-after { display: flex; align-items: center; flex-wrap: wrap; } |
| 577 | 577 | .list > li.has-after > .row, .list > li.has-after > details { flex: 1 1 0; min-width: 0; } |
| 578 | /* From outside (/next): Adopt and Decline under the ask; the reason takes its own line, 44px taps, at 360px too. */ | |
| 579 | #outsiders .row-after { flex: 1 1 100%; padding: 0 16px 12px; } | |
| 580 | .outsider-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; } | |
| 581 | .outsider-acts form { display: contents; } | |
| 582 | .outsider-acts .form-actions { margin: 0; } | |
| 583 | .outsider-acts input[name="reason"] { order: 3; flex: 1 1 100%; min-width: 0; min-height: 44px; } | |
| 584 | .outsider-acts .btn { min-height: 44px; } | |
| 578 | 585 | .row-after { flex: none; padding: 0 14px 0 0; } |
| 579 | 586 | /* A settings row's acts (Accounts): always visible, wrapping, a full line under 640px. */ |
| 580 | 587 | .setting-list > li.has-after > .row-after { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; } |
test/next-outsider-report.test.ts added +123
| @@ -0,0 +1,123 @@ | ||
| 1 | /** | |
| 2 | * An outsider's report is one row in /next (sender, ask); Adopt opens the issue, Decline closes it | |
| 3 | * with a reason the sender reads (#15840). | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { insertReport } from "../src/core/reports.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { createUser, type User } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | ||
| 16 | let dir: string; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | let cookie: string; | |
| 20 | let alice: User; | |
| 21 | let n = 0; | |
| 22 | ||
| 23 | beforeAll(async () => { | |
| 24 | dir = await mkdtemp(join(tmpdir(), "forge-next-outsider-")); | |
| 25 | app = createApp({ dataDir: dir, port: 0 }); | |
| 26 | servers = await serve(app); | |
| 27 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 28 | if (!made.ok) throw new Error(made.error); | |
| 29 | alice = made.value; | |
| 30 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 31 | const r = await createRepo(app, alice, { name: "game", visibility: "public" }); | |
| 32 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 33 | }); | |
| 34 | afterAll(async () => { | |
| 35 | await servers.stop(); | |
| 36 | app.close(); | |
| 37 | await rm(dir, { recursive: true, force: true }); | |
| 38 | }); | |
| 39 | ||
| 40 | const file = async (title: string, agent = "") => { | |
| 41 | n += 1; | |
| 42 | const res = await fetch(`${servers.url}/api/v1/repos/alice/game/reports`, { | |
| 43 | method: "POST", | |
| 44 | headers: { "content-type": "application/json", "x-forwarded-for": `10.9.0.${n}` }, | |
| 45 | body: JSON.stringify({ title, body: "details", ...(agent === "" ? {} : { agent }) }), | |
| 46 | }); | |
| 47 | expect(res.status).toBe(202); | |
| 48 | return ((await res.json()) as { id: string }).id; | |
| 49 | }; | |
| 50 | const nextPage = async (withCookie = true) => | |
| 51 | (await fetch(`${servers.url}/alice/game/next`, { headers: withCookie ? { cookie } : {} })).text(); | |
| 52 | const decide = (id: string, decision: string, reason = "") => | |
| 53 | fetch(`${servers.url}/alice/game/next`, { | |
| 54 | method: "POST", | |
| 55 | headers: { cookie, origin: servers.url, accept: "application/json" }, | |
| 56 | body: new URLSearchParams({ report: id, decision, reason }), | |
| 57 | }); | |
| 58 | const status = async (id: string) => | |
| 59 | (await (await fetch(`${servers.url}/api/v1/repos/alice/game/reports/${id}/status`)).json()) as { status: string; reason?: string }; | |
| 60 | ||
| 61 | test("an outsider's report is one row with sender and ask, for the owner only", async () => { | |
| 62 | const id = await file("Score resets on <b>reload</b>", "muse"); | |
| 63 | const page = await nextPage(); | |
| 64 | expect(page).toContain(`data-report="${id}"`); | |
| 65 | expect(page).toContain("Score resets on <b>reload</b>"); | |
| 66 | expect(page).not.toContain("<b>reload</b>"); | |
| 67 | expect(page).toContain("claims to be muse, unproven"); | |
| 68 | expect(page).toMatch(/Adopt\s+<\/button>/); | |
| 69 | expect(page).toMatch(/Decline\s+<\/button>/); | |
| 70 | expect(page).toContain('class="outsider-acts"'); | |
| 71 | expect(page).not.toContain("↘"); | |
| 72 | expect(await nextPage(false)).not.toContain(`data-report="${id}"`); | |
| 73 | const gone = await fetch(`${servers.url}/alice/game/next`, { method: "POST", headers: { cookie, origin: servers.url, accept: "application/json" }, body: new URLSearchParams({ report: "nope", decision: "decline" }) }); | |
| 74 | expect(gone.status).toBe(404); | |
| 75 | }); | |
| 76 | ||
| 77 | test("adopt opens the issue, and the row goes", async () => { | |
| 78 | const id = await file("Adopt me"); | |
| 79 | const res = await decide(id, "adopt"); | |
| 80 | expect(res.status).toBe(200); | |
| 81 | const said = (await res.json()) as { ok: boolean; flash: string }; | |
| 82 | expect(said.flash).toMatch(/^Adopted as issue #\d+\.$/); | |
| 83 | const number = Number(/#(\d+)/.exec(said.flash)![1]); | |
| 84 | const issue = app.db.query("SELECT state, title FROM issue WHERE repo_id = (SELECT id FROM repo WHERE name = 'game') AND number = ?1").get(number) as { state: string; title: string }; | |
| 85 | expect(issue.state).toBe("open"); | |
| 86 | expect(issue.title).toContain("Adopt me"); | |
| 87 | expect(await nextPage()).not.toContain(`data-report="${id}"`); | |
| 88 | expect((await status(id)).status).toBe("being worked"); | |
| 89 | expect((await decide(id, "adopt")).status).toBe(422); | |
| 90 | }); | |
| 91 | ||
| 92 | test("decline closes it with a reason the sender reads at their status link", async () => { | |
| 93 | const id = await file("Decline me"); | |
| 94 | const res = await decide(id, "decline", "Out of scope for this game."); | |
| 95 | expect(res.status).toBe(200); | |
| 96 | expect(await nextPage()).not.toContain(`data-report="${id}"`); | |
| 97 | expect(await status(id)).toMatchObject({ status: "declined", reason: "Out of scope for this game." }); | |
| 98 | const other = await file("Decline quietly"); | |
| 99 | await decide(other, "decline"); | |
| 100 | expect((await status(other)).reason).toContain("Not something we will take up"); | |
| 101 | }); | |
| 102 | ||
| 103 | test("a stranger, a bad word or a cross-origin post decides nothing", async () => { | |
| 104 | const id = await file("Leave me"); | |
| 105 | await fetch(`${servers.url}/alice/game/next`, { method: "POST", headers: { origin: servers.url, accept: "application/json" }, body: new URLSearchParams({ report: id, decision: "adopt" }) }); | |
| 106 | expect((await decide(id, "maybe")).status).toBe(422); | |
| 107 | const away = await fetch(`${servers.url}/alice/game/next`, { method: "POST", headers: { cookie, origin: "https://evil.example", accept: "application/json" }, body: new URLSearchParams({ report: id, decision: "adopt" }) }); | |
| 108 | expect(away.status).toBe(403); | |
| 109 | expect((await status(id)).status).toBe("open"); | |
| 110 | }); | |
| 111 | ||
| 112 | test("past twenty waiting, /next shows the oldest twenty and links the rest, the heading counting all", async () => { | |
| 113 | const ids: string[] = []; | |
| 114 | const repoId = (app.db.query("SELECT id FROM repo WHERE name = 'game'").get() as { id: string }).id; | |
| 115 | for (let i = 0; i < 25; i++) ids.push(insertReport(app.db, repoId, { title: `Flood ${i}`, body: "x", page: null }).id); | |
| 116 | const total = (app.db.query("SELECT COUNT(*) AS n FROM report WHERE state = 'pending'").get() as { n: number }).n; | |
| 117 | expect(total).toBeGreaterThan(20); | |
| 118 | const page = await nextPage(); | |
| 119 | expect(page.match(/data-report="/g)?.length).toBe(20); | |
| 120 | expect(page).toContain(`From outside · ${total}`); | |
| 121 | expect(page).toContain(`and ${total - 20} more on <a href="/alice/game/reports">the reports page</a>`); | |
| 122 | expect(page).not.toContain(`data-report="${ids[24]}"`); | |
| 123 | }); |
test/tui-reports.test.ts +10 −6
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Reports from outside in the terminal (#7233): two reports filed through the |
| 3 | 3 | * API wait under "Reports (2)" in the owner's palette; `a` accepts one as an |
| 4 | * issue and says its number, `d` dismisses the other after a confirm, and the | |
| 4 | * issue and says its number, `d` declines the other with a typed reason, and the | |
| 5 | 5 | * row is gone once nothing waits. A reader has no row; a report someone else |
| 6 | 6 | * decided meanwhile is refused in REPORT_ALREADY_DECIDED's words. |
| 7 | 7 | */ |
| @@ -14,7 +14,7 @@ import { dismissReport, waitingReports } from "../src/actions/reports.ts"; | ||
| 14 | 14 | import { createRepo } from "../src/actions/repos.ts"; |
| 15 | 15 | import { createApp, type App } from "../src/app.ts"; |
| 16 | 16 | import { getIssue } from "../src/core/issues.ts"; |
| 17 | import { insertReport } from "../src/core/reports.ts"; | |
| 17 | import { insertReport, reportStatus } from "../src/core/reports.ts"; | |
| 18 | 18 | import type { Repo } from "../src/core/repos.ts"; |
| 19 | 19 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 20 | 20 | import type { Ctx } from "../src/tui/app/app.ts"; |
| @@ -132,12 +132,16 @@ describe("reports from outside, in the terminal", () => { | ||
| 132 | 132 | expect(issue.body).toContain("Clicked save twice, nothing happened."); |
| 133 | 133 | expect(waiting().map((r) => r.title)).toEqual(["Typo on the front page"]); |
| 134 | 134 | |
| 135 | // The confirm's first button keeps it waiting; the second dismisses. | |
| 136 | await h.run("d", "\r"); | |
| 135 | // Escape keeps it waiting; a typed reason declines and reaches the sender's status link. | |
| 136 | const typo = waiting()[0]!; | |
| 137 | await h.run("d", "\x1b"); | |
| 137 | 138 | expect(waiting()).toHaveLength(1); |
| 138 | text = await h.run("d", "\x1b[C", "\r"); | |
| 139 | expect(text).toContain("Dismissed."); | |
| 139 | await h.run("d"); | |
| 140 | for (const ch of "Out of scope") await h.run(ch); | |
| 141 | text = await h.run("\r"); | |
| 142 | expect(text).toContain("Declined."); | |
| 140 | 143 | expect(text).toContain("Nothing waits."); |
| 144 | expect(reportStatus(app.db, repo.id, typo.id)).toMatchObject({ status: "declined", reason: "Out of scope" }); | |
| 141 | 145 | expect(waiting()).toHaveLength(0); |
| 142 | 146 | h.stop(); |
| 143 | 147 |
"not_found" | stringcollapses tostring, so the caller tells a refusal from a sentence by comparing to a magic string. Return a typed result, e.g.{ok:false, error:"not_found"} | {ok:false, error:"refused", message}, so the page does not misrender a sentence that happens to equal "not_found".