Hold /privacy behind a flag until counsel reads it, and fix leftover legal and email copy.

This commit is contained in:
adilallo committed 2026-11-20 15:36:06 -07:00
1 parent ead6c8f716
commit 072e5362f5
43 files changed
+548 -191

No files matched your search

+75 -30
View File
@@ -1,5 +1,6 @@
import { ASSETS, getAssetPath } from "../assetUtils";
import { MAGIC_LINK_TTL_MINUTES } from "../privacyRetention";
import { mailLegalFooterHtml, mailLegalFooterUrls } from "./mailLegalFooter";
export const MAGIC_LINK_LOGO_PATH = getAssetPath(ASSETS.LOGO_MARK);
@@ -31,51 +32,54 @@ function originHost(origin: string): string {
}
}
export function buildMagicLinkMail(
input: MagicLinkMailInput,
type BrandedVerifyMailCopy = {
verifyUrl: string;
origin: string;
subject: string;
previewText: string;
heading: string;
intro: string;
buttonLabel: string;
ignore: string;
why: string;
};
function buildBrandedVerifyMail(
copy: BrandedVerifyMailCopy,
): MagicLinkMailContent {
const origin = input.origin.replace(/\/$/, "");
const minutes = MAGIC_LINK_TTL_MINUTES;
const subject = "Your login link for CommunityRule";
const previewText = `It works once, for ${minutes} minutes.`;
const heading = "Log in to CommunityRule";
const intro = `Use the button to log in. It works once, for ${minutes} minutes.`;
const ignore =
"If you did not ask to log in, ignore this email. Nobody can log in without the link.";
const origin = copy.origin.replace(/\/$/, "");
const { aboutUrl, privacyUrl } = mailLegalFooterUrls(origin);
const madeBy =
"CommunityRule is made by the Media Economies Design Lab at the University of Colorado Boulder.";
const privacyUrl = `${origin}/privacy`;
const aboutUrl = `${origin}/about`;
const logoUrl = `${origin}${MAGIC_LINK_LOGO_PATH}`;
const host = originHost(origin);
const href = escapeHtml(copy.verifyUrl);
const text = [
heading,
copy.heading,
"",
intro,
copy.intro,
"",
`Log in: ${input.verifyUrl}`,
`${copy.buttonLabel}: ${copy.verifyUrl}`,
"",
ignore,
copy.ignore,
"",
madeBy,
`Privacy ${privacyUrl}`,
...(privacyUrl ? [`Privacy ${privacyUrl}`] : []),
`About CommunityRule ${aboutUrl}`,
"",
`Sent because you asked to log in at ${host}.`,
copy.why,
].join("\n");
const href = escapeHtml(input.verifyUrl);
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>${escapeHtml(subject)}</title>
<title>${escapeHtml(copy.subject)}</title>
</head>
<body style="margin:0;padding:0;background:#e4e4e4;">
<div style="display:none;max-height:0;overflow:hidden;mso-hide:all;">${escapeHtml(
previewText,
copy.previewText,
)}</div>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#e4e4e4;">
<tr>
@@ -95,19 +99,17 @@ export function buildMagicLinkMail(
</tr>
<tr>
<td style="padding:40px 32px 56px;">
<h1 style="margin:0 0 16px;font-family:'Bricolage Grotesque',Arial,sans-serif;font-size:36px;line-height:44px;font-weight:700;color:#000000;">${escapeHtml(heading)}</h1>
<p style="margin:0 0 32px;font-family:Inter,Arial,sans-serif;font-size:18px;line-height:24px;color:#303030;">${escapeHtml(intro)}</p>
<h1 style="margin:0 0 16px;font-family:'Bricolage Grotesque',Arial,sans-serif;font-size:36px;line-height:44px;font-weight:700;color:#000000;">${escapeHtml(copy.heading)}</h1>
<p style="margin:0 0 32px;font-family:Inter,Arial,sans-serif;font-size:18px;line-height:24px;color:#303030;">${escapeHtml(copy.intro)}</p>
<p style="margin:0 0 32px;">
<a href="${href}" style="display:inline-block;background:#141414;color:#ffffff;font-family:Inter,Arial,sans-serif;font-size:16px;line-height:20px;font-weight:500;text-decoration:none;border-radius:9999px;padding:12px 16px;">Log in</a>
<a href="${href}" style="display:inline-block;background:#141414;color:#ffffff;font-family:Inter,Arial,sans-serif;font-size:16px;line-height:20px;font-weight:500;text-decoration:none;border-radius:9999px;padding:12px 16px;">${escapeHtml(copy.buttonLabel)}</a>
</p>
<div style="height:1px;background:#e4e4e4;margin:0 0 32px;"></div>
<p style="margin:0 0 32px;font-family:Inter,Arial,sans-serif;font-size:16px;line-height:24px;color:#303030;">${escapeHtml(ignore)}</p>
<p style="margin:0 0 32px;font-family:Inter,Arial,sans-serif;font-size:16px;line-height:24px;color:#303030;">${escapeHtml(copy.ignore)}</p>
<div style="border-top:1px solid #e4e4e4;padding-top:24px;">
<p style="margin:0 0 12px;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">${escapeHtml(madeBy)}</p>
<p style="margin:0;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">
<a href="${escapeHtml(privacyUrl)}" style="color:#464646;text-decoration:underline;">Privacy</a>
&nbsp;&nbsp;
<a href="${escapeHtml(aboutUrl)}" style="color:#464646;text-decoration:underline;">About CommunityRule</a>
${mailLegalFooterHtml(origin)}
</p>
</div>
</td>
@@ -119,5 +121,48 @@ export function buildMagicLinkMail(
</body>
</html>`;
return { subject, previewText, text, html };
return {
subject: copy.subject,
previewText: copy.previewText,
text,
html,
};
}
export function buildMagicLinkMail(
input: MagicLinkMailInput,
): MagicLinkMailContent {
const minutes = MAGIC_LINK_TTL_MINUTES;
const origin = input.origin.replace(/\/$/, "");
return buildBrandedVerifyMail({
verifyUrl: input.verifyUrl,
origin,
subject: "Your login link for CommunityRule",
previewText: `It works once, for ${minutes} minutes.`,
heading: "Log in to CommunityRule",
intro: `Use the button to log in. It works once, for ${minutes} minutes.`,
buttonLabel: "Log in",
ignore:
"If you did not ask to log in, ignore this email. Nobody can log in without the link.",
why: `Sent because you asked to log in at ${originHost(origin)}.`,
});
}
export function buildEmailChangeMail(
input: MagicLinkMailInput,
): MagicLinkMailContent {
const minutes = MAGIC_LINK_TTL_MINUTES;
const origin = input.origin.replace(/\/$/, "");
return buildBrandedVerifyMail({
verifyUrl: input.verifyUrl,
origin,
subject: "Confirm your new CommunityRule email",
previewText: `It works once, for ${minutes} minutes.`,
heading: "Confirm your new email",
intro: `Use the button to confirm the new address on your CommunityRule account. It works once, for ${minutes} minutes.`,
buttonLabel: "Confirm email",
ignore:
"If you did not request this change, ignore this email. Your current login is unchanged until you confirm.",
why: `Sent because you asked to change the email on your CommunityRule account at ${originHost(origin)}.`,
});
}
+17 -12
View File
@@ -5,8 +5,7 @@ import {
buildWorkshopInboxMail,
type WorkshopInquiryMailInput,
} from "../workshopSignupMail";
import { MAGIC_LINK_TTL_MINUTES } from "../privacyRetention";
import { buildMagicLinkMail } from "./magicLinkMail";
import { buildEmailChangeMail, buildMagicLinkMail } from "./magicLinkMail";
import { getSmtpUrl } from "./env";
import {
buildRuleStakeholderInviteMail,
@@ -26,12 +25,22 @@ function escapeHtml(value: string): string {
.replace(/"/g, "&quot;");
}
/** Display name is CommunityRule, one word, even if SMTP_FROM still has a space. */
function formatMailFrom(from: string): string {
const trimmed = from
.trim()
.replace(/^"?Community Rule"?(\s*<)/, "CommunityRule$1");
if (trimmed.includes("<")) return trimmed;
if (trimmed.includes("@")) return `CommunityRule <${trimmed}>`;
return trimmed;
}
export function resolveMailFrom(): string {
return (
const raw =
process.env.SMTP_FROM?.trim() ||
process.env.CLOUDRON_MAIL_FROM?.trim() ||
"noreply@localhost"
);
"noreply@localhost";
return formatMailFrom(raw);
}
/** Avoid quoted-printable `token=3D` wrapping that some webmail clients do not decode. */
@@ -187,16 +196,12 @@ export async function sendWorkshopInquiryConfirmation(input: {
export async function sendEmailChangeEmail(
to: string,
verifyUrl: string,
origin: string,
): Promise<void> {
const { text, html } = buildVerifyLinkParts(
verifyUrl,
`You asked to change the email on your Community Rule account.\n\nOpen this link to confirm the new address (it expires in ${MAGIC_LINK_TTL_MINUTES} minutes):`,
"If you did not request this change, you can ignore this email. Your current login is unchanged until you confirm.",
"Confirm email",
);
const { subject, text, html } = buildEmailChangeMail({ verifyUrl, origin });
await sendHtmlMail({
to,
subject: "Confirm your new Community Rule email",
subject,
text,
html,
devLog: `[dev] Email change verify for ${to}: ${verifyUrl}`,
+30
View File
@@ -0,0 +1,30 @@
import { privacyPolicyUrl } from "../privacyPolicyEnabled";
function escapeHtml(value: string): string {
return value
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
export function mailLegalFooterUrls(origin: string): {
aboutUrl: string;
privacyUrl: string | null;
} {
const base = origin.replace(/\/$/, "");
return {
aboutUrl: `${base}/about`,
privacyUrl: privacyPolicyUrl(base),
};
}
/** HTML Privacy + About links. Omits Privacy while the policy flag is off. */
export function mailLegalFooterHtml(origin: string): string {
const { aboutUrl, privacyUrl } = mailLegalFooterUrls(origin);
const about = `<a href="${escapeHtml(aboutUrl)}" style="color:#464646;text-decoration:underline;">About CommunityRule</a>`;
if (!privacyUrl) return about;
return `<a href="${escapeHtml(privacyUrl)}" style="color:#464646;text-decoration:underline;">Privacy</a>
&nbsp;&nbsp;
${about}`;
}
+6 -10
View File
@@ -1,6 +1,7 @@
import { ASSETS, getAssetPath } from "../assetUtils";
import { communityPossessive } from "../create/ruleInviteCardMeta";
import { RULE_MD_FILENAME } from "../create/ruleExportModel";
import { mailLegalFooterHtml, mailLegalFooterUrls } from "./mailLegalFooter";
export const RULE_FOLLOW_UP_LOGO_PATH = getAssetPath(ASSETS.LOGO_MARK);
@@ -55,8 +56,7 @@ export function buildRuleFollowUpMail(
const why = `Sent because you finished a Rule at ${host}.`;
const madeBy =
"CommunityRule is made by the Media Economies Design Lab at the University of Colorado Boulder.";
const privacyUrl = `${origin}/privacy`;
const aboutUrl = `${origin}/about`;
const { privacyUrl } = mailLegalFooterUrls(origin);
const logoUrl = `${origin}${RULE_FOLLOW_UP_LOGO_PATH}`;
const text = [
@@ -82,7 +82,7 @@ export function buildRuleFollowUpMail(
why,
"",
madeBy,
`Privacy ${privacyUrl}`,
...(privacyUrl ? [`Privacy ${privacyUrl}`] : []),
].join("\n");
const html = followUpHtml({
@@ -98,8 +98,7 @@ export function buildRuleFollowUpMail(
signOff,
why,
madeBy,
privacyUrl,
aboutUrl,
origin,
logoUrl,
kitHostPath: `${host}/kit`,
});
@@ -120,8 +119,7 @@ function followUpHtml(opts: {
signOff: string;
why: string;
madeBy: string;
privacyUrl: string;
aboutUrl: string;
origin: string;
logoUrl: string;
kitHostPath: string;
}): string {
@@ -180,9 +178,7 @@ function followUpHtml(opts: {
<p style="margin:0 0 12px;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">${escapeHtml(opts.why)}</p>
<p style="margin:0 0 12px;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">${escapeHtml(opts.madeBy)}</p>
<p style="margin:0;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">
<a href="${escapeHtml(opts.privacyUrl)}" style="color:#464646;text-decoration:underline;">Privacy</a>
&nbsp;&nbsp;
<a href="${escapeHtml(opts.aboutUrl)}" style="color:#464646;text-decoration:underline;">About CommunityRule</a>
${mailLegalFooterHtml(opts.origin)}
</p>
</div>
</td>
+6 -12
View File
@@ -1,4 +1,5 @@
import { ASSETS, getAssetPath } from "../assetUtils";
import { mailLegalFooterHtml, mailLegalFooterUrls } from "./mailLegalFooter";
import {
clipCommunityInviteDescription,
communityInviteInitials,
@@ -84,8 +85,7 @@ export function buildRuleStakeholderInviteMail(
const why = `You got this email because ${inviterEmail} added your address to ${possessive} Rule on CommunityRule. If you do not know the community, you can ignore this email.`;
const madeBy =
"CommunityRule is made by the Media Economies Design Lab at the University of Colorado Boulder.";
const privacyUrl = `${origin}/privacy`;
const aboutUrl = `${origin}/about`;
const { privacyUrl } = mailLegalFooterUrls(origin);
const logoUrl = `${origin}${RULE_STAKEHOLDER_INVITE_LOGO_PATH}`;
const text = [
@@ -106,7 +106,7 @@ export function buildRuleStakeholderInviteMail(
why,
"",
madeBy,
`Privacy ${privacyUrl}`,
...(privacyUrl ? [`Privacy ${privacyUrl}`] : []),
].join("\n");
const html = inviteHtml({
@@ -123,8 +123,7 @@ export function buildRuleStakeholderInviteMail(
copyLead,
why,
madeBy,
privacyUrl,
aboutUrl,
origin,
logoUrl,
});
@@ -145,8 +144,7 @@ function inviteHtml(opts: {
copyLead: string;
why: string;
madeBy: string;
privacyUrl: string;
aboutUrl: string;
origin: string;
logoUrl: string;
}): string {
const heading = escapeHtml(opts.subject);
@@ -165,8 +163,6 @@ function inviteHtml(opts: {
` of this one and change what does not fit.`;
const why = escapeHtml(opts.why);
const madeBy = escapeHtml(opts.madeBy);
const privacyUrl = escapeHtml(opts.privacyUrl);
const aboutUrl = escapeHtml(opts.aboutUrl);
const logoUrl = escapeHtml(opts.logoUrl);
const cardBody = description
? `<p style="margin:16px 0 0;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:18px;font-weight:500;color:#000000;">${description}</p>`
@@ -236,9 +232,7 @@ function inviteHtml(opts: {
<p style="margin:0 0 12px;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">${why}</p>
<p style="margin:0 0 12px;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">${madeBy}</p>
<p style="margin:0;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:20px;color:#464646;">
<a href="${privacyUrl}" style="color:#464646;text-decoration:underline;">Privacy</a>
&nbsp;&nbsp;
<a href="${aboutUrl}" style="color:#464646;text-decoration:underline;">About CommunityRule</a>
${mailLegalFooterHtml(opts.origin)}
</p>
</div>
</td>