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

A signed-out visitor who taps Make it yours signs up and lands on their own fork, not on the home page #16616

opened this

Check · Review · Land · Live — Its check is red. Next: builder, its check is red.

Ready to land

scout/forge:scout/16304-a-signed-out-visitor-who-taps-make-it-yo → main 4 commits fork 2 threads · 2 unresolved

Review

Sign in to review this change.
11 files changed +135 −21
src/web/chrome.ts +12 −1
@@ -10,7 +10,7 @@
1010
1111 import { togetherHtml } from "./together.ts";
1212 import { repoOnRequest } from "../http/request_repo.ts";
13 import { hereAddress, returnTo, withReturn } from "./return_to.ts";
13 import { hereAddress, returnTo, safeNext, withReturn } from "./return_to.ts";
1414 import { MACHINE_PREFIX, typedMiss } from "../http/asset_miss.ts";
1515 import { audienceFacts, audienceOf } from "../core/audience.ts";
1616 import { activeEdgeToken, edgeLoginUrl, edgeStrangerLogin } from "../http/edge.ts";
@@ -205,6 +205,17 @@ export function signInHref(ctx: Ctx, next: string = hereAddress(ctx)): string {
205205 return `/signin?next=${encodeURIComponent(next)}`;
206206 }
207207
208 /**
209 * Where a signed-out visitor who tapped "Make it yours" starts: sign-up carrying the app's page
210 * (`next`, a path on this forge, checked again by the door), or the usual sign-in where the
211 * forge offers no sign-up. Coming back, the page makes the copy once; a copy that exists is opened.
212 */
213 export function signUpHref(ctx: Ctx, next: string): string {
214 const safe = safeNext(next);
215 if (safe === undefined || !offersSignup(ctx) || activeEdgeToken(ctx.app) !== undefined) return signInHref(ctx, safe ?? "/");
216 return withReturn("/signup", safe);
217 }
218
208219 /**
209220 * Whether a signed-out visitor is offered Create an account beside Sign in.
210221 * Behind a platform edge the edge is the one way in, unless it has vouched
src/web/pages/first_steps.ts +2 −2
@@ -29,9 +29,9 @@ export function firstRunHtml(run: FirstRun): Html {
2929 /**
3030 * The crew now, then the undone steps under one fixed heading; the crew block appears here only.
3131 */
32 export function firstSteps(ctx: Ctx, steps: readonly NextStep[]): Html {
32 export function firstSteps(ctx: Ctx, steps: readonly NextStep[], hrefs: Partial<Record<StepKey, string>> = {}): Html {
3333 const todo = steps.filter((s) => !s.done);
3434 return html`${crewNowHtml(crewNow(ctx.app.db))}
3535 <section id="first-steps" class="mt" aria-label="${FIRST_STEPS_HEADING}"><h2 class="small">${FIRST_STEPS_HEADING}</h2>
36 ${listCard(todo.map((s) => row({ href: STEP_HREF[s.key], title: html`${STEP_TITLES[s.key]}`, data: { "first-step": s.key } })))}</section>`;
36 ${listCard(todo.map((s) => row({ href: hrefs[s.key] ?? STEP_HREF[s.key], title: html`${STEP_TITLES[s.key]}`, data: { "first-step": s.key } })))}</section>`;
3737 }
src/web/studio/app.ts +9 −1
@@ -79,7 +79,8 @@ import {
7979 timePhase,
8080 timePhaseAsync,
8181 } from "../../core/route_timing.ts";
82 import { noteAppOpened } from "../../core/next-steps.ts";
82 import { firstSteps } from "../pages/first_steps.ts";
83 import { STEP_TITLES, noteAppOpened } from "../../core/next-steps.ts";
8384 import { mayReadStatement } from "../../actions/statement.ts";
8485 import { appPicture } from "../../flow/pages.ts";
8586 import { moneyRows } from "./money_line.ts";
@@ -506,6 +507,11 @@ export async function studioApp(
506507 const migration = await timePhaseAsync(req, "migration", () => migrationRegion(ctx, repo, ownerFacts));
507508 const schedules = ownerFacts ? html`${schedulesCard(ctx, repo)}${jobsLink(ctx, repo)}` : null;
508509 const rendering = performance.now();
510 // A copy just made from sign-up (`?welcome=1`) shows its owner what to do first: tell the crew.
511 const welcome =
512 ctx.url.searchParams.get("welcome") === "1" && ctx.auth.user?.id === repo.ownerId
513 ? firstSteps(ctx, [{ key: "tell", title: STEP_TITLES.tell, done: false }], { tell: "#tell" })
514 : null;
509515 const tellRegion = html`${tell}
510516 ${ownerFacts && ctx.auth.user ? answersRegion(ctx, repo, ctx.auth.user) : null}`;
511517 // A new app that has not run yet shows only its progress: the head's
@@ -518,6 +524,7 @@ export async function studioApp(
518524 : followingCard(ctx, repo, following)}
519525 ${archivedLine(ctx, repo)}
520526 <div id="app-head">${head}</div>
527 ${welcome}
521528 ${ownerFacts ? crewKeyCard(ctx, true) : null}
522529 ${ownerFacts ? landOnApp(ctx, repo) : null}
523530 ${pausedLine(ctx, repo)}
@@ -545,6 +552,7 @@ export async function studioApp(
545552 : followingCard(ctx, repo, following)}
546553 ${archivedLine(ctx, repo)}
547554 <div id="app-head">${head}</div>
555 ${welcome}
548556 ${askingLine(ctx, repo)}
549557 ${policy}
550558 ${ownerFacts ? crewKeyCard(ctx, true) : null}
src/web/studio/make_it_yours.ts +30 −3
@@ -16,6 +16,7 @@ import {
1616 pageHead,
1717 repoBase,
1818 signInFirst,
19 signUpHref,
1920 } from "../chrome.ts";
2021 import { field, readForm } from "../form.ts";
2122 import { html, when } from "../html.ts";
@@ -71,12 +72,33 @@ function helpBuildPage(ctx: Ctx, repo: Repo): Response {
7172 });
7273 }
7374
75 /**
76 * A signed-out visitor goes to sign-up carrying this app's make-it-yours page, and returns to it.
77 */
78 const signUpFirst = (ctx: Ctx, repo: Repo): Response => {
79 const q = ctx.url.searchParams.get("receipt") === "1" ? "?receipt=1" : ctx.url.searchParams.get("welcome") === "1" ? "?welcome=1" : "";
outdated

This only moves the visitor to a page that still needs a second tap and never reaches the fork or first-steps; the issue asks for landing on their own fork. Make the return create the copy once and land on it.

80 return redirect(signUpHref(ctx, `${repoBase(repo)}/make-it-yours${q}`));
81 };
82
83 /** How long after joining the sign-up return may make the copy on its own. */
84 const JUST_JOINED_MS = 30 * 60_000;
85
86 /**
87 * Whether this account was made in the last half hour: only then does a link's say-so stand for a
88 * tap.
89 */
90 function justJoined(createdAt: string): boolean {
91 const iso = createdAt.includes("T") ? createdAt : createdAt.replace(" ", "T");
92 const at = Date.parse(/(?:Z|[+-]\d\d:?\d\d)$/.test(iso) ? iso : `${iso}Z`);
93 return Number.isFinite(at) && Date.now() - at < JUST_JOINED_MS;
94 }
95
7496 // GET /:owner/:name/make-it-yours
7597 export async function makeItYoursPage(ctx: Ctx): Promise<Response> {
7698 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
7799 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
78100 if (!repo) return timePhase(ctx.request, "render", () => notFoundPage(ctx));
79 if (!ctx.auth.user) return timePhase(ctx.request, "render", () => signInFirst(ctx));
101 if (!ctx.auth.user) return timePhase(ctx.request, "render", () => signUpFirst(ctx, repo));
80102 const user = ctx.auth.user;
81103 const plan = await timePhaseAsync(ctx.request, "plan", () =>
82104 makeItYours(ctx.app, user, repo, { dryRun: true }),
@@ -86,6 +108,10 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> {
86108 if (!plan.ok)
87109 return timePhase(ctx.request, "render", () => planRefused(ctx, repo, plan.error));
88110 const p = plan.value;
111 // Back from sign-up with the intent kept (`welcome=1`): a new account's return is the tap, so the
112 // page confirms itself, once, from its own origin. For anyone else the link waits for the button.
113 const welcome = ctx.url.searchParams.get("welcome") === "1";
114 const selfTap = welcome && justJoined(user.createdAt);
89115 const rendering = performance.now();
90116 const body = html`<div class="narrow-wide">
91117 ${pageHead("Make it yours", {
@@ -106,6 +132,7 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> {
106132 ctx.url.searchParams.get("receipt") === "1",
107133 () => html`<input type="hidden" name="receipt" value="1" />`,
108134 )}
135 ${when(welcome, () => html`<input type="hidden" name="welcome" value="1" />`)}
109136 <ul class="list setting-list">
110137 ${row({ title: "Yours as", trail: html`<span class="mono">${p.repo}</span>` })}
111138 ${row({ title: "Its address", trail: html`<span class="mono">${p.slug}</span>` })}
@@ -165,7 +192,7 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> {
165192 // The toolbar's tap is the whole ask only when its `go` token verifies for this viewer and
166193 // repository (minted by the crew door, `apps/yours_go.ts`): then the page confirms itself,
167194 // from its own origin. Any other link waits for the button below, which is the same ask.
168 ...(verifyYoursGo(ctx.app.config.dataDir, ctx.url.searchParams.get("go"), user.id, repo.id)
195 ...(selfTap || verifyYoursGo(ctx.app.config.dataDir, ctx.url.searchParams.get("go"), user.id, repo.id)
169196 ? { scriptJs: AUTO_SUBMIT_JS }
170197 : {}),
171198 });
@@ -197,7 +224,7 @@ export async function makeItYoursSubmit(ctx: Ctx): Promise<Response> {
197224 url: ctx.url,
198225 forgeUrl: ctx.app.config.url,
199226 });
200 return redirect(repoBase(made.value.made.repo), {
227 return redirect(`${repoBase(made.value.made.repo)}${field(form, "welcome") === "1" ? "?welcome=1" : ""}`, {
201228 url: ctx.url,
202229 forgeUrl: ctx.app.config.url,
203230 flash: {
src/web/studio/yours_button.ts +2 −2
@@ -11,7 +11,7 @@ import type { AppRecord } from "../../core/apps.ts";
1111 import { getForkOf, type Repo } from "../../core/repos.ts";
1212 import { lacks } from "../../core/roles.ts";
1313 import type { Ctx } from "../../http/context.ts";
14 import { repoBase, signInHref } from "../chrome.ts";
14 import { repoBase, signUpHref } from "../chrome.ts";
1515 import { html, type Html } from "../html.ts";
1616 import { btn } from "../ui.ts";
1717
@@ -19,7 +19,7 @@ export function yoursButton(ctx: Ctx, repo: Repo, record: AppRecord): Html | und
1919 if (repo.visibility !== "public" || record.access !== "public") return undefined;
2020 const base = repoBase(repo);
2121 const user = ctx.auth.user;
22 if (user === undefined) return btn("Make it yours", { icon: "fork", href: signInHref(ctx) });
22 if (user === undefined) return btn("Make it yours", { icon: "fork", href: signUpHref(ctx, `${base}/make-it-yours?welcome=1`) });
2323 if (user.kind !== "user") return undefined;
2424 const db = ctx.app.db;
2525 if (lacks(db, user, "make_it_yours")) return btn(HELP_BUILD, { icon: "fork", href: `${base}/make-it-yours` });
test/explore-fork.test.ts +2 −2
@@ -68,8 +68,8 @@ describe("explore: make it yours", () => {
6868 const res = await fetch(`${servers.url}${href!.replaceAll("&amp;", "&")}`, { redirect: "manual" });
6969 expect(res.status).toBe(303);
7070 const to = res.headers.get("location")!;
71 expect(to).toStartWith("/signin?next=");
72 expect(decodeURIComponent(to.slice("/signin?next=".length))).toBe("/alice/open/make-it-yours?receipt=1");
71 expect(to).toStartWith("/signup?next=");
72 expect(decodeURIComponent(to.slice("/signup?next=".length))).toBe("/alice/open/make-it-yours?receipt=1");
outdated

Stale '/signin?next=' in the slice below; use '/signup?next=' so the assertion reads what it checks.

7373 // A signed-out POST is sent the same way and makes nothing.
7474 const post = await fetch(`${servers.url}/alice/open/make-it-yours`, {
7575 method: "POST",
test/explore.test.ts +1 −1
@@ -334,7 +334,7 @@ describe("explore", () => {
334334 const next = encodeURIComponent(path);
335335 const res = await fetch(`${base}${path}`, { redirect: "manual" });
336336 expect(res.status).toBe(303);
337 expect(res.headers.get("location")).toBe(`/signin?next=${next}`);
337 expect(res.headers.get("location")).toBe(`/signup?next=${next}`);
338338 const copies = () => (app.db.query(`SELECT COUNT(*) AS n FROM repo WHERE owner_id = ?1`).get(bob.id) as { n: number }).n;
339339 const before = copies();
340340 const signedIn = await fetch(`${base}/signin?next=${next}`, {
test/explorer-make-it-yours.test.ts +2 −2
@@ -112,11 +112,11 @@ describe("explorer: make it yours", () => {
112112 expect(getRepo(app.db, "bob", "garden")).toBeUndefined();
113113 });
114114
115 test("signed out, the preview asks to sign in and offers no confirm", async () => {
115 test("signed out, the preview asks to sign up and offers no confirm", async () => {
116116 const res = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { redirect: "manual" });
117117 const body = await res.text();
118118 expect(res.status).toBe(303);
119 expect(res.headers.get("location")).toBe("/signin?next=%2Falice%2Fgarden%2Fmake-it-yours%3Freceipt%3D1");
119 expect(res.headers.get("location")).toBe("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Freceipt%3D1");
120120 expect(body).not.toContain('action="/alice/garden/make-it-yours"');
121121 expect(getRepo(app.db, "bob", "garden")).toBeUndefined();
122122 });
test/friend-journey.test.ts +1 −1
@@ -92,7 +92,7 @@ describe("the Friend test", () => {
9292 const lead = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { redirect: "manual" });
9393 expect(lead.status).toBe(303);
9494 expect(lead.headers.get("location")).toBe(
95 `/signin?next=${encodeURIComponent("/alice/garden/make-it-yours?receipt=1")}`,
95 `/signup?next=${encodeURIComponent("/alice/garden/make-it-yours?receipt=1")}`,
9696 );
9797
9898 // A stranger who only signed up is a guest: the page offers them help
test/guest-contribute.test.ts +1 −1
@@ -650,7 +650,7 @@ describe("a stranger's first pull starts from the app's page", () => {
650650 expect(opts.status).toBe(200);
651651 expect(((await opts.json()) as { challenge?: string }).challenge).toBeTruthy();
652652 const toSignIn = await fetch(`${servers.url}/olive/game/make-it-yours`, { redirect: "manual" });
653 expect(toSignIn.headers.get("location")).toContain("/signin?next=");
653 expect(toSignIn.headers.get("location")).toContain("/signup?next=");
654654
655655 // A private app offers nothing.
656656 expect(await (await fetch(`${servers.url}/olive/secret`)).text()).not.toContain('id="contribute"');
test/make-it-yours-button.test.ts +73 −5
@@ -10,8 +10,11 @@ import { createApp, type App } from "../src/app.ts";
1010 import { updateApp, getAppByRepo } from "../src/core/apps.ts";
1111 import { newApp } from "../src/actions/apps.ts";
1212 import { createSession } from "../src/core/sessions.ts";
13 import { createUser, getUserById } from "../src/core/users.ts";
13 import { createUser, getUserById, getUserByName } from "../src/core/users.ts";
1414 import { getRepo } from "../src/core/repos.ts";
15 import { setLimit } from "../src/settings/limits.ts";
16 import { markVerified } from "../src/core/verify.ts";
17 import { safeNext } from "../src/web/return_to.ts";
1518 import { serve, type Servers } from "../src/http/server.ts";
1619 import { quietLogs } from "./helpers/globals.ts";
1720 import { promote } from "./helpers/members.ts";
@@ -27,11 +30,11 @@ describe("make it yours on the repository page", () => {
2730
2831 const get = async (path: string, cookie?: string) =>
2932 (await fetch(`${servers.url}${path}`, { headers: cookie ? { cookie } : {} })).text();
30 const post = (path: string, headers: Record<string, string>) =>
33 const post = (path: string, headers: Record<string, string>, body = "") =>
3134 fetch(`${servers.url}${path}`, {
3235 method: "POST",
3336 headers: { cookie: bobCookie, "content-type": "application/x-www-form-urlencoded", ...headers },
34 body: "",
37 body,
3538 redirect: "manual",
3639 });
3740
@@ -80,10 +83,10 @@ describe("make it yours on the repository page", () => {
8083 await rm(dataDir, { recursive: true, force: true });
8184 });
8285
83 test("signed out: the button leads to sign-in and back", async () => {
86 test("signed out: the button leads to sign-up carrying the app", async () => {
8487 const page = await get("/alice/garden");
8588 expect(page).toContain("Make it yours");
86 expect(page).toContain("/signin?next=%2Falice%2Fgarden");
89 expect(page).toContain("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Fwelcome%3D1");
8790 });
8891
8992 test("signed out: the sign-in it leads to carries the visitor back to the app page", async () => {
@@ -140,4 +143,69 @@ describe("make it yours on the repository page", () => {
140143 expect(after).toContain("Open your copy");
141144 expect(after).not.toContain('action="/alice/garden/make-it-yours"');
142145 });
146
147 test("the whole path: signed out, through the real sign-up form, the return makes one copy and lands on it with first steps", async () => {
148 setLimit(app.db, "signup.per_source", 100, "system");
149 const out = await fetch(`${servers.url}/alice/garden/make-it-yours?welcome=1`, { redirect: "manual" });
150 const to = out.headers.get("location")!;
151 expect(to).toBe("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Fwelcome%3D1");
152 expect(await (await fetch(`${servers.url}${to}`)).text()).toContain("%2Falice%2Fgarden%2Fmake-it-yours");
153 const signed = await fetch(`${servers.url}${to}`, {
154 method: "POST",
155 headers: { origin: servers.url },
156 body: new URLSearchParams({ username: "erin", email: "[email protected]", password: "correct horse battery" }),
157 redirect: "manual",
158 });
159 expect(signed.status).toBe(303);
160 const back = signed.headers.get("location")!;
161 expect(back).toBe("/alice/garden/make-it-yours?welcome=1");
162 const cookie = signed.headers.get("set-cookie")!.split(";")[0]!;
163 expect(getRepo(app.db, "erin", "garden")).toBeUndefined();
164 // A newcomer is a guest until a member admits them (a guest gets the help-build page instead);
165 // this forge admits erin, as its owner would.
166 promote(app.db);
167 markVerified(app.db, getUserByName(app.db, "erin")!.id, new Date().toISOString());
168 // The return confirms itself from its own origin, and carries the intent to the post.
169 const confirm = await get(back, cookie);
170 expect(confirm).toContain('name="welcome" value="1"');
171 const script = confirm.match(/src="(\/assets\/page-[^"]+\.js)"/)?.[1];
172 expect(script).toBeDefined();
173 expect(await (await fetch(`${servers.url}${script}`)).text()).toContain("requestSubmit");
174 // That submit makes the copy once; a repeat opens it, never a second.
175 for (let i = 0; i < 3; i++) {
176 const res = await post("/alice/garden/make-it-yours", {
177 origin: servers.url,
178 cookie,
179 "content-type": "application/x-www-form-urlencoded",
180 }, "welcome=1");
181 expect(res.status).toBe(303);
182 expect(res.headers.get("location")).toBe("/erin/garden?welcome=1");
183 }
184 const erin = getUserByName(app.db, "erin")!;
185 const copies = app.db.query<{ n: number }, [string]>("SELECT count(*) AS n FROM repo WHERE owner_id = ?1 AND name = 'garden'").get(erin.id)!;
186 expect(copies.n).toBe(1);
187 const landed = await get("/erin/garden?welcome=1", cookie);
188 expect(landed).toContain('id="first-steps"');
189 expect(await get("/erin/garden", cookie)).not.toContain('id="first-steps"');
190 });
191
192 test("a link saying welcome does not make a copy for an account that is not new", async () => {
193 const gina = await createUser(app.db, {
194 origin: "seed", trusted: true, username: "gina", email: "[email protected]", password: "correct horse battery",
195 });
196 if (!gina.ok) throw new Error(String(gina.error));
197 promote(app.db, gina.value);
198 const cookie = `forge_session=${createSession(app.db, gina.value.id).token}`;
199 const scripted = /src="\/assets\/page-[^"]+\.js"/;
200 expect(await get("/alice/garden/make-it-yours?welcome=1", cookie)).toMatch(scripted);
201 app.db.query("UPDATE user SET created_at = '2026-01-01T00:00:00.000Z' WHERE id = ?1").run(gina.value.id);
202 expect(await get("/alice/garden/make-it-yours?welcome=1", cookie)).not.toMatch(scripted);
203 expect(getRepo(app.db, "gina", "garden")).toBeUndefined();
204 });
205
206 test("a return target off the forge is refused", () => {
207 for (const bad of ["https://evil.example/", "//evil.example", "/\\evil.example", "/\t/evil.example", "javascript:alert(1)"])
208 expect(safeNext(bad)).toBeUndefined();
209 expect(safeNext("/alice/garden/make-it-yours")).toBe("/alice/garden/make-it-yours");
210 });
143211 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs