Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions atlas/app/admin/closeout/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CAP = 4;
const LABEL: Record<string, string> = {
blurb: "Description", tech: "Tech stack", topics: "Topics", repoUrl: "Repository", prodUrl: "Live site / demo",
contacts: "Client contacts (admin-only)", clientUrl: "Client website", clientDesc: "About the client (public)",
codePrivate: "Code", presentationUrl: "Final presentation", reportUrl: "Final report",
codePrivate: "Code", presentationUrl: "Final presentation", reportUrl: "Final report", pdUrl: "Project description (PD)",
};
const SEV = { blocker: "var(--danger)", warning: "var(--amber-ink)" } as const;

Expand Down Expand Up @@ -217,7 +217,7 @@ export default function CloseoutReview({ params }: { params: Promise<{ token: st
<div className="lab">
{LABEL[f.field] ?? f.field}
{/* Per-semester deliverables land on this term's run, not the project. */}
{(f.field === "presentationUrl" || f.field === "reportUrl") && ` · ${r.term || "this semester"}`}
{(f.field === "presentationUrl" || f.field === "reportUrl" || f.field === "pdUrl") && ` · ${r.term || "this semester"}`}
</div>
<div style={{ display: "grid", gap: 6, fontSize: 14, lineHeight: 1.5 }}>
<div style={{ color: "var(--sec)", textDecoration: "line-through", whiteSpace: "pre-wrap", overflowWrap: "anywhere" }}>{show(f.before)}</div>
Expand Down
1 change: 1 addition & 0 deletions atlas/app/api/closeout/[token]/approve/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function POST(req: Request, { params }: { params: Promise<{ token:
codePrivate: draft.codePublic ? draft.codePublic === "no" : null,
presentationUrl: draft.presentationUrl,
reportUrl: draft.reportUrl,
pdUrl: draft.pdUrl,
course: draft.course,
}
: undefined,
Expand Down
1 change: 1 addition & 0 deletions atlas/app/api/closeout/[token]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function GET(_req: Request, { params }: { params: Promise<{ token:
codePrivate: project?.codePrivate ?? false,
presentationUrl: termRun?.presentationUrl ?? "",
reportUrl: termRun?.reportUrl ?? "",
pdUrl: termRun?.pdUrl ?? "",
},
before,
draft
Expand Down
29 changes: 26 additions & 3 deletions atlas/app/contribute/[token]/CloseoutClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ export default function CloseoutClient({
["title", "Project name", "e.g. Food Pantry Finder", true, 200],
["partner", "Client or partner", "e.g. City of Boston", true, 200],
["course", "Course", "e.g. DS519", true, 40],
["pdUrl", "Project description link", "https://docs.google.com/…", false, 500],
] as const
).map(([k, lab, ph, req, max]) => (
<div key={k} style={{ minWidth: 0 }}>
Expand All @@ -404,8 +403,7 @@ export default function CloseoutClient({
</label>
<input
id={`co-${k}`}
type={k === "pdUrl" ? "url" : "text"}
inputMode={k === "pdUrl" ? "url" : undefined}
type="text"
maxLength={max}
className={`fld${bad(k) ? " co-bad" : ""}`}
data-bad={bad(k) ? "1" : undefined}
Expand All @@ -420,6 +418,31 @@ export default function CloseoutClient({
</Card>
)}

<Card id="pd" title="Project description (PD)" sub="The Google Doc your team worked from this semester. BU Spark! keeps it on file with the project.">
<label className="lab" htmlFor="co-pdUrl">PD link <span className="req">*</span></label>
<input
id="co-pdUrl"
type="url"
inputMode="url"
maxLength={500}
className={`fld${bad("pdUrl") ? " co-bad" : ""}`}
data-bad={bad("pdUrl") ? "1" : undefined}
value={draft.pdUrl}
onChange={(e) => set("pdUrl", e.target.value)}
placeholder="https://docs.google.com/document/d/…"
/>
<div className="hint">We check the sharing setting when you save.</div>
<Issues list={at("pdUrl")} />
<label data-bad={bad("pdPublic") ? "1" : undefined} style={{ color: bad("pdPublic") ? "var(--danger)" : undefined, display: "flex", gap: 10, alignItems: "flex-start", marginTop: 14, fontSize: 14, lineHeight: 1.45, cursor: "pointer" }}>
<input type="checkbox" checked={draft.pdPublic} onChange={(e) => set("pdPublic", e.target.checked)} style={{ marginTop: 3 }} />
<span>
I confirm the PD&rsquo;s General access is set to <strong>Anyone with the link</strong> &middot; <em>Anyone on the internet with the link can view</em>.
<span className="hint" style={{ display: "block", marginTop: 2 }}>In the doc: Share &rarr; General access &rarr; Anyone with the link &rarr; Viewer.</span>
</span>
</label>
<Issues list={at("pdPublic")} />
</Card>

<Card id="about" title="About the project" sub="Shown on the public project page once published.">
<label className="lab" htmlFor="co-blurb">Description <span className="req">*</span></label>
<textarea
Expand Down
3 changes: 3 additions & 0 deletions atlas/app/contribute/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default async function ContributePage({
programLeads: leads,
runs: [],
newProject: { term },
requirePd: true,
});
return (
<Shell label="semester close-out">
Expand Down Expand Up @@ -214,6 +215,7 @@ export default async function ContributePage({
// Per semester: this term's run, not another semester's deliverables.
presentationUrl: project.runs.find((r) => termsEqual(r.term, term))?.presentationUrl ?? "",
reportUrl: project.runs.find((r) => termsEqual(r.term, term))?.reportUrl ?? "",
pdUrl: project.runs.find((r) => termsEqual(r.term, term))?.pdUrl ?? project.pdUrl ?? "",
};
const saved = reqRow.draft && typeof reqRow.draft === "object" && Object.keys(reqRow.draft).length > 0;
let draft: CloseoutDraft = coerceDraft({ ...clientPrefill, ...(saved ? (reqRow.draft as object) : {}) });
Expand Down Expand Up @@ -242,6 +244,7 @@ export default async function ContributePage({
topicVocabulary: settings.topics ?? [],
programLeads: leads,
runs: project.runs,
requirePd: true,
});
return (
<Shell label="semester close-out">
Expand Down
2 changes: 1 addition & 1 deletion atlas/app/wrap-up/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default async function CloseoutStart({
<input type="hidden" name="term" value={term} />
<label className="lab" htmlFor="cs-name">Project name <span className="req">*</span></label>
<input id="cs-name" name="name" className="fld" required maxLength={START_LIMITS.name} placeholder="e.g. Food Pantry Finder" />
<label className="lab" htmlFor="cs-pd" style={{ marginTop: 14 }}>Project description link (optional)</label>
<label className="lab" htmlFor="cs-pd" style={{ marginTop: 14 }}>Project description (PD) link <span style={{ fontWeight: 400, color: "var(--muted)" }}>· optional here, required before you submit</span></label>
<input id="cs-pd" name="pdUrl" type="url" inputMode="url" className="fld" maxLength={START_LIMITS.url} placeholder="https://docs.google.com/…" />
{error && <div role="alert" style={{ color: "var(--danger)", fontSize: 13.5, marginTop: 10 }}>{error}</div>}
<button type="submit" className="btn btn-dark" style={{ padding: "11px 18px", fontSize: 14, marginTop: 16 }}>
Expand Down
24 changes: 23 additions & 1 deletion atlas/lib/closeout-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import "server-only";
import { getOpenUploadRequest, getProjectAdmin, getGallerySettings, getProgramLeads } from "@/lib/db";
import { checkRateLimit, clientIp } from "@/lib/ratelimit";
import { coerceDraft, validateCloseout, type CloseoutDraft, type Problem } from "@/lib/closeout";
import { coerceDraft, googleDocId, pdSharingFromResponse, pdSharingProblem, validateCloseout, type CloseoutDraft, type PdSharing, type Problem } from "@/lib/closeout";
import { buEmail } from "@/lib/closeout-start";
import { auth } from "@/auth";
import { ORGS } from "@/lib/authz";
Expand Down Expand Up @@ -69,6 +69,28 @@ export async function readCloseoutBody(
programLeads,
runs: project?.runs ?? [],
newProject: project ? undefined : { term: open.term ?? "" },
requirePd: true,
});
// Only a link that passed the format checks is fetched.
if (draft.pdUrl && !problems.some((p) => p.field === "pdUrl")) {
const s = await checkPdSharing(draft.pdUrl);
const p = pdSharingProblem(s);
if (p) problems.push(p);
}
return { draft, problems };
}

/** Ask Google, anonymously, whether the PD opens for anyone with the link. */
async function checkPdSharing(url: string): Promise<PdSharing | "not-doc"> {
const id = googleDocId(url);
if (!id) return "not-doc";
try {
const res = await fetch(`https://docs.google.com/document/d/${id}/export?format=txt`, {
redirect: "manual",
signal: AbortSignal.timeout(5000),
});
return pdSharingFromResponse(res.status, res.headers.get("location"));
} catch {
return "unknown";
}
}
35 changes: 35 additions & 0 deletions atlas/lib/closeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
mergeClientContacts,
answeredClientQuestions,
emptyDraft,
googleDocId,
pdSharingFromResponse,
pdSharingProblem,
type CloseoutDraft,
} from "./closeout";
import type { Run } from "./types";
Expand Down Expand Up @@ -36,6 +39,7 @@ function draft(over: Partial<CloseoutDraft> = {}): CloseoutDraft {
codePublic: "yes",
presentationUrl: "",
reportUrl: "",
pdPublic: false,
clientFieldsV: 1,
...over,
};
Expand Down Expand Up @@ -243,3 +247,34 @@ describe("mergeClientContacts", () => {
expect(out.map((c) => c.name)).toEqual(["Pat New", "Sam", "No Email"]);
});
});

describe("PD sharing", () => {
const ctx = { topicVocabulary: [], runs: [] };
const fields = (d: Partial<CloseoutDraft>, requirePd: boolean) =>
validateCloseout({ ...emptyDraft(), ...d }, { ...ctx, requirePd })
.filter((p) => p.field === "pdUrl" || p.field === "pdPublic")
.map((p) => p.field);

it("requires the link and the tick on the PM's save, not at approve", () => {
expect(fields({}, true)).toEqual(["pdUrl", "pdPublic"]);
expect(fields({ pdUrl: "https://docs.google.com/document/d/abc", pdPublic: true }, true)).toEqual([]);
expect(fields({}, false)).toEqual([]);
});

it("reads Google's anonymous export response", () => {
expect(pdSharingFromResponse(307, "https://doc-0g-4o-docstext.googleusercontent.com/export/x")).toBe("public");
expect(pdSharingFromResponse(401, null)).toBe("restricted");
expect(pdSharingFromResponse(302, "https://accounts.google.com/ServiceLogin?x")).toBe("restricted");
expect(pdSharingFromResponse(404, null)).toBe("missing");
expect(pdSharingFromResponse(500, null)).toBe("unknown");
expect(pdSharingProblem("unknown")?.severity).toBe("warning");
expect(pdSharingProblem("restricted")?.severity).toBe("blocker");
});

it("only checks docs.google.com documents", () => {
expect(googleDocId("https://docs.google.com/document/d/1AbCdEfGhIjKlMnOpQrStUvWxYz/edit?usp=sharing")).toBe("1AbCdEfGhIjKlMnOpQrStUvWxYz");
expect(googleDocId("https://docs.google.com/document/u/0/d/1AbCdEfGhIjKlMnOpQrStUvWxYz/edit")).toBe("1AbCdEfGhIjKlMnOpQrStUvWxYz");
expect(googleDocId("https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz/view")).toBeNull();
expect(googleDocId("https://evil.example/document/d/1AbCdEfGhIjKlMnOpQrStUvWxYz")).toBeNull();
});
});
60 changes: 59 additions & 1 deletion atlas/lib/closeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface CloseoutDraft {
codePublic: CodePublic;
presentationUrl: string;
reportUrl: string;
/** The PM ticked "the PD is shared as Anyone with the link can view". */
pdPublic: boolean;
/** 1 = saved by a form that showed the client cards (see answeredClientQuestions). */
clientFieldsV: 0 | 1;
}
Expand Down Expand Up @@ -110,7 +112,7 @@ export function emptyDraft(): CloseoutDraft {
return {
blurb: "", tech: [], topics: [], repoUrl: "", prodUrl: "", contributors: [], programLead: "",
title: "", partner: "", course: "", pdUrl: "",
clientContacts: [], clientUrl: "", clientDesc: "", codePublic: "", presentationUrl: "", reportUrl: "", clientFieldsV: 0,
clientContacts: [], clientUrl: "", clientDesc: "", codePublic: "", presentationUrl: "", reportUrl: "", pdPublic: false, clientFieldsV: 0,
};
}

Expand Down Expand Up @@ -160,6 +162,7 @@ export function coerceDraft(raw: unknown): CloseoutDraft {
codePublic: oneOf(o.codePublic, ["yes", "no"] as const),
presentationUrl: str(o.presentationUrl),
reportUrl: str(o.reportUrl),
pdPublic: o.pdPublic === true,
// An old stored draft may still carry galleryOk (the dropped gallery question):
// it is read only as proof the client cards were shown, then discarded.
clientFieldsV: o.clientFieldsV === 1 || oneOf(o.galleryOk, ["yes", "no", "unsure"] as const) ? 1 : 0,
Expand Down Expand Up @@ -193,6 +196,9 @@ export interface ValidateContext {
/** A project-less request: title/partner/course come from the draft and are
* required, and the term's run is the one approval will create. */
newProject?: { term: string };
/** The PM's own save/submit: the PD link and the sharing tick are required. Off at
* approve time, so a draft submitted before this rule can still be signed off. */
requirePd?: boolean;
}

export function validateCloseout(d: CloseoutDraft, ctx: ValidateContext): Problem[] {
Expand All @@ -216,6 +222,9 @@ export function validateCloseout(d: CloseoutDraft, ctx: ValidateContext): Proble
if (d.pdUrl) {
if (d.pdUrl.length > LIMITS.url) block("pdUrl", `Keep the link under ${LIMITS.url} characters.`);
else if (!isHttpUrl(d.pdUrl)) block("pdUrl", "Must be a full http(s):// link.");
} else if (ctx.requirePd) block("pdUrl", "Add the link to your project description (PD).");
if (ctx.requirePd && !d.pdPublic) {
block("pdPublic", "Confirm the PD is shared as \"Anyone with the link\" can view.");
}
const runs = ctx.newProject ? [{ term: ctx.newProject.term, course: d.course, discipline: "", students: [] }] : ctx.runs;
for (const b of publishBlockers({ blurb: d.blurb, runs })) {
Expand Down Expand Up @@ -314,6 +323,7 @@ export interface ProjectFields {
codePrivate?: boolean;
presentationUrl?: string;
reportUrl?: string;
pdUrl?: string;
}

export interface FieldChange {
Expand Down Expand Up @@ -370,6 +380,10 @@ export function diffCloseout(
for (const f of ["clientUrl", "clientDesc", "presentationUrl", "reportUrl"] as const) {
if ((before[f] ?? "").trim() !== after[f]) fields.push({ field: f, before: before[f] ?? "", after: after[f] });
}
// Fill/replace only: an empty PD link (a draft from before it was asked) clears nothing.
if (after.pdUrl && (before.pdUrl ?? "").trim() !== after.pdUrl) {
fields.push({ field: "pdUrl", before: before.pdUrl ?? "", after: after.pdUrl });
}
if (after.codePublic) {
const code = (priv: boolean) => (priv ? "Private (available on request)" : "Public");
const priv = after.codePublic === "no";
Expand Down Expand Up @@ -441,3 +455,47 @@ export function cleanProgramLeads(raw: unknown): { leads: ProgramLead[] } | { er
if (leads.length > LIMITS.programLeads) return { error: `At most ${LIMITS.programLeads} program leads.` };
return { leads };
}

// ── PD sharing ──────────────────────────────────────────────────────────────

export type PdSharing = "public" | "restricted" | "missing" | "unknown";

/** The Google Doc id when the link is a docs.google.com document, else null. */
export function googleDocId(url: string): string | null {
try {
const u = new URL(url);
if (u.hostname !== "docs.google.com") return null;
return u.pathname.match(/^\/document\/(?:u\/\d+\/)?d\/([a-zA-Z0-9_-]{20,})/)?.[1] ?? null;
} catch {
return null;
}
}

/**
* What an anonymous GET of /document/d/<id>/export?format=txt says about sharing
* (verified 2026-12-04): a public doc 307s to docstext.googleusercontent.com, a
* restricted one is 401 (or a redirect to the sign-in page), a bad id is 404.
*/
export function pdSharingFromResponse(status: number, location: string | null): PdSharing {
if (status === 200) return "public";
if (status >= 300 && status < 400) {
if (/googleusercontent\.com/.test(location ?? "")) return "public";
if (/accounts\.google\.com/.test(location ?? "")) return "restricted";
return "unknown";
}
if (status === 401 || status === 403) return "restricted";
if (status === 404) return "missing";
return "unknown";
}

/** The problem (if any) to show for a checked PD. "unknown" never blocks. */
export function pdSharingProblem(s: PdSharing | "not-doc"): Problem | null {
const field = "pdUrl";
if (s === "restricted") {
return { field, severity: "blocker", message: "This PD isn't public yet. In the doc: Share → General access → \"Anyone with the link\" → Viewer." };
}
if (s === "missing") return { field, severity: "blocker", message: "No Google Doc at this link — check you copied the whole link." };
if (s === "not-doc") return { field, severity: "warning", message: "Not a Google Docs link, so its sharing can't be checked. Make sure anyone with the link can view it." };
if (s === "unknown") return { field, severity: "warning", message: "Couldn't check this PD's sharing right now. Make sure anyone with the link can view it." };
return null;
}
2 changes: 2 additions & 0 deletions atlas/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,8 @@ export interface CloseoutApply {
/** Stored on the run for the close-out's term, not on the project. */
presentationUrl: string;
reportUrl: string;
/** The PD link for that run. Empty leaves the stored one alone. */
pdUrl?: string;
/** Course for that run if the project has none for the term yet. */
course: string;
};
Expand Down
15 changes: 11 additions & 4 deletions atlas/lib/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,26 @@ export function deliverableRuns(runs: Run[]): Run[] {
export function applyRunDeliverables(
runs: Run[],
term: string,
links: { presentationUrl: string; reportUrl: string },
links: { presentationUrl: string; reportUrl: string; pdUrl?: string },
opts: { fillOnly: boolean; course: string }
): Run[] | null {
if (!term.trim()) return null;
const p = links.presentationUrl.trim();
const r = links.reportUrl.trim();
const pd = (links.pdUrl ?? "").trim();
const has = runs.some((rn) => termsEqual(rn.term, term));
if (!has && !p && !r) return null;
if (!has && !p && !r && !pd) return null;
const { runs: next, idx } = ensureRunForTerm(runs, term, opts.course);
const cur = next[idx];
const pick = (v: string, prev?: string | null) => (opts.fillOnly ? v || prev : v) || null;
const updated = { ...cur, presentationUrl: pick(p, cur.presentationUrl), reportUrl: pick(r, cur.reportUrl) };
if (has && (cur.presentationUrl ?? null) === updated.presentationUrl && (cur.reportUrl ?? null) === updated.reportUrl) {
// The PD link never clears: an empty one is a draft from before it was asked.
const updated = { ...cur, presentationUrl: pick(p, cur.presentationUrl), reportUrl: pick(r, cur.reportUrl), pdUrl: (opts.fillOnly ? cur.pdUrl || pd : pd || cur.pdUrl) || null };
if (
has &&
(cur.presentationUrl ?? null) === updated.presentationUrl &&
(cur.reportUrl ?? null) === updated.reportUrl &&
(cur.pdUrl ?? null) === updated.pdUrl
) {
return null;
}
return next.map((rn, i) => (i === idx ? updated : rn));
Expand Down
Loading