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
6 changes: 4 additions & 2 deletions backend/src/db/sponsorDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ export async function updateSponsorDoc(
}

if (nextStatus === 'submitted') validateSubmittedContent(nextTemplate, nextContent);
const linkType = nextTemplate !== doc.template && doc.linkType === getSponsorDocTemplate(doc.template).defaultLinkType
? getSponsorDocTemplate(nextTemplate).defaultLinkType
const defaultLinkType = getSponsorDocTemplate(nextTemplate).defaultLinkType;
const linkType = (nextTemplate !== doc.template && doc.linkType === getSponsorDocTemplate(doc.template).defaultLinkType)
|| ((nextTemplate === 'podcast' || nextTemplate === 'webinar' || nextTemplate === 'workshop') && doc.linkType === 'Sponsorship document')
? defaultLinkType
: doc.linkType;

const updated: SponsorDoc = await projectDocumentEvent(client, {
Expand Down
71 changes: 61 additions & 10 deletions backend/src/routes/sponsorDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,78 @@ export function sponsorDocPathForTemplate(template: string | null | undefined):
return '/sponsor-docs';
}

/**
* Retired legacy podcast prep doc IDs (episode-brief, run-sheet, guest-research)
* whose content was folded into their card's single canonical `podcast` doc.
*/
const LEGACY_PODCAST_DOC_REDIRECTS: Record<string, string> = {
'sdoc-f32e2d0cf444d425': 'sdoc-bd8460a27de69e0f',
'sdoc-d3d717c93b05a84a': 'sdoc-bd8460a27de69e0f',
'sdoc-f9eb105e3012e950': 'sdoc-bd8460a27de69e0f',
'sdoc-fae3a5e82bd086bd': 'sdoc-c894d8bdd8ce41e0',
'sdoc-8f7ca07b1e5952b2': 'sdoc-c894d8bdd8ce41e0',
'sdoc-733deeacbf0c82d8': 'sdoc-c894d8bdd8ce41e0',
'sdoc-200f61d017046c1e': 'sdoc-3c7c75fa8d78f881',
'sdoc-02d072778a589afe': 'sdoc-3c7c75fa8d78f881',
'sdoc-2eb9c9ab245386f4': 'sdoc-3c7c75fa8d78f881',
'sdoc-e75c1e639da13f62': 'sdoc-01bb8ebd2e1a34f3f0b705c5',
'sdoc-5e1d0241335b4681': 'sdoc-dd879cbb9b1917f0',
'sdoc-77041907581c35c4': 'sdoc-dd879cbb9b1917f0',
'sdoc-a58585451c05d994': 'sdoc-dd879cbb9b1917f0',
'sdoc-5c4365c902518892': 'sdoc-88fcb2ee31012cd1',
'sdoc-8242c4772ed42031': 'sdoc-88fcb2ee31012cd1',
'sdoc-ab6c1449b9e97ce7': 'sdoc-88fcb2ee31012cd1',
'sdoc-0c3846ea08efb724': 'sdoc-c8b13d5253fad7e1f628b225',
'sdoc-961abc2f0100fa43': 'sdoc-c8b13d5253fad7e1f628b225',
'sdoc-feeaf44bb31cf54b': 'sdoc-c8b13d5253fad7e1f628b225',
'sdoc-7b8854fadfdc25ff': 'sdoc-40fa43800c86d13b',
'sdoc-1ce72f3b936c143b': 'sdoc-40fa43800c86d13b',
'sdoc-03a28cc607f84e38': 'sdoc-40fa43800c86d13b',
'sdoc-83b036321c1e76af': 'sdoc-e7a941b39daa3804',
'sdoc-2005735767baa70c': 'sdoc-e7a941b39daa3804',
'sdoc-aaf40109b792a683': 'sdoc-e7a941b39daa3804',
'sdoc-5a2eb0a393452ef9': 'sdoc-60478c50f377c561',
'sdoc-96522ddf73f5db3b': 'sdoc-60478c50f377c561',
'sdoc-4e725d97980b9ac2': 'sdoc-60478c50f377c561',
};

/**
* Redirect legacy `/sponsor-docs/:id` requests for podcast/webinar/workshop
* documents to their canonical `/podcast-docs/:id` (or webinar/workshop) URL,
* preserving query parameters (e.g. `?code=...`).
* and redirect retired legacy podcast prep doc IDs to their card's canonical
* `/podcast-docs/:id`, preserving query parameters (e.g. `?code=...`).
*/
export async function redirectLegacySponsorDocPath(
event: LambdaEvent,
client: DynamoDBDocumentClient,
): Promise<LambdaResponse | null> {
if ((event.httpMethod || 'GET').toUpperCase() !== 'GET') return null;
const match = /^\/sponsor-docs\/([^/?#]+)\/?$/.exec(event.path || '');
const match = /^\/(sponsor-docs|podcast-docs)\/([^/?#]+)\/?$/.exec(event.path || '');
if (!match) return null;
const docId = decodeURIComponent(match[1]);
const loaded = await getSponsorDocWithAuthMaterial(client, docId);
if (!loaded) return null;
const canonicalPrefix = sponsorDocPathForTemplate(loaded.doc.template);
if (canonicalPrefix === '/sponsor-docs') return null;
const prefix = match[1];
const docId = decodeURIComponent(match[2]);
const rawQuery = event.queryStringParameters && Object.keys(event.queryStringParameters).length > 0
? `?${new URLSearchParams(
Object.entries(event.queryStringParameters).filter((e): e is [string, string] => typeof e[1] === 'string'),
).toString()}`
: '';
const retiredTarget = LEGACY_PODCAST_DOC_REDIRECTS[docId];
if (retiredTarget) {
return {
statusCode: 302,
headers: {
Location: `/podcast-docs/${encodeURIComponent(retiredTarget)}${rawQuery}`,
'Cache-Control': 'no-store',
'Referrer-Policy': 'no-referrer',
},
body: '',
};
}
if (prefix !== 'sponsor-docs') return null;
const loaded = await getSponsorDocWithAuthMaterial(client, docId);
if (!loaded) return null;
const canonicalPrefix = sponsorDocPathForTemplate(loaded.doc.template);
if (canonicalPrefix === '/sponsor-docs') return null;
return {
statusCode: 302,
headers: {
Expand Down Expand Up @@ -1194,8 +1244,9 @@ export async function handleSponsorDocRoutes(
const card = await getCardConsistent(client, deleted.cardId);
if (card && Array.isArray(card.cardLinks)) {
const encodedId = encodeURIComponent(deleted.id);
const isEventCard = (card.tags || []).some((t) => /^(podcast|webinar|workshop)$/i.test(String(t || '').trim()));
let changed = false;
const nextLinks = card.cardLinks.map((item) => {
const nextLinks = card.cardLinks.flatMap((item) => {
const url = String(item.url || '');
if (
url.endsWith(`/sponsor-docs/${encodedId}`)
Expand All @@ -1205,9 +1256,9 @@ export async function handleSponsorDocRoutes(
|| url.endsWith(`/guest-docs/${encodedId}`)
) {
changed = true;
return { ...item, url: '' };
return isEventCard ? [] : [{ ...item, url: '' }];
}
return item;
return [item];
});
if (changed) {
await updateCard(client, card.id, {
Expand Down
11 changes: 11 additions & 0 deletions backend/tests/sponsor-docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ describe('Sponsor Content Docs API (/api/sponsor-docs)', () => {
assert.ok(redir);
assert.strictEqual(redir.statusCode, 302);
assert.strictEqual(redir.headers?.Location, `/podcast-docs/${guestCreated.doc.id}?code=${encodeURIComponent(guestCreated.doc.accessCode)}`);

// Retired legacy podcast prep doc IDs redirect to the card's canonical /podcast-docs/:id.
for (const legacyPath of ['/sponsor-docs/sdoc-fae3a5e82bd086bd', '/podcast-docs/sdoc-fae3a5e82bd086bd']) {
const retiredRedir = await redirectLegacySponsorDocPath({
httpMethod: 'GET',
path: legacyPath,
} as any, client);
assert.ok(retiredRedir, `expected redirect for ${legacyPath}`);
assert.strictEqual(retiredRedir.statusCode, 302);
assert.strictEqual(retiredRedir.headers?.Location, '/podcast-docs/sdoc-c894d8bdd8ce41e0');
}
});

it('gates anonymous sponsor access by access code (query or header), allows sponsor edits & submission, and lets staff edit without a code', async () => {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/surfaces/work-detail/link-rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,19 @@ export function renderCardLinksSection(options) {
const missing = [];
let missingEditorOpen = false;
const seenUrls = new Set();
const isEventCard =
/^(podcast|webinar|workshop)$/i.test(String(card.templateDefinitionSnapshot?.type || "").trim())
|| (card.tags || []).some((tag) => /^(podcast|webinar|workshop)$/i.test(String(tag || "").trim()));
for (const link of card.cardLinks) {
const linkName = link.name || link.label || "Link";
const rawUrl = link.url || "";
const linkUrl = String(rawUrl)
.replace(/[\s"'\u200c\u200b]+$/, "")
.replace(/^["']/, "")
.trim();
if (isEventCard && /\/sponsor-docs\//i.test(linkUrl)) {
continue;
}
// If a named link already displayed this exact URL, skip the duplicate raw-url item
if (
linkUrl &&
Expand Down
25 changes: 25 additions & 0 deletions frontend/test/sponsor-docs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -911,3 +911,28 @@ test("podcast doc supports read-only view-questions mode and photo preview place
assert.equal(h.root.querySelector('[data-sponsor-action="submit-ready"]'), null);
h.controller.destroy();
});

test("event cards filter out legacy /sponsor-docs/ cardLinks in renderCardLinksSection", async () => {
const prevDoc = globalThis.document;
globalThis.document = new FakeDocument();
try {
const { renderCardLinksSection } = await import("../src/surfaces/work-detail/link-rows.js");
const section = renderCardLinksSection({
card: {
id: "card-pod-2",
tags: ["Podcast"],
cardLinks: [
{ name: "Podcast document", url: "https://ops.dtcdev.click/podcast-docs/sdoc-canon" },
{ name: "Guest research", url: "https://ops.dtcdev.click/sponsor-docs/sdoc-legacy-res" },
{ name: "Host run sheet", url: "https://ops.dtcdev.click/sponsor-docs/sdoc-legacy-run" },
],
},
onSaveLink: () => {},
});
assert.match(section.textContent, /Podcast document/);
assert.doesNotMatch(section.textContent, /Guest research/);
assert.doesNotMatch(section.textContent, /Host run sheet/);
} finally {
globalThis.document = prevDoc;
}
});