Add a Request form, with files in Google Drive and email notices

One form at /request for blog posts, events, and new or updated
chapters, regions (updates only), partners, teams, awards and people.
?type= opens it on one; buttons on the Community sections, blog posts,
Retreats and the front page calendar do. Files (.docx, PDF, JPEG, PNG)
go to a Google Drive folder through a service account.

Requests are feedback rows of type 'content' (migration 046), in a
third Forms queue: files download from Drive, a .docx can become a
draft blog post, and deleting a request deletes its files. New content
and data requests email the addresses in Site settings through Gmail.

Setup: docs/google-drive-and-mail.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 15:54:00 -05:00
parent 0e582c236b
commit dc53af238f
31 changed files with 1318 additions and 113 deletions

40
server/src/notify.js Normal file
View file

@ -0,0 +1,40 @@
/* ═══════════════════════════════════════════════════════════════
NEW-REQUEST NOTICES
An email to the people in Panel → Site settings → "Email new
requests to" when a content request (/request) or a data request
(the Privacy page) comes in. Sent after the row is saved and never
waited on: a mail problem is logged, the submission stands.
Off until Gmail is set up (googleService.js) and someone is listed.
═══════════════════════════════════════════════════════════════ */
import { mailReady, sendMail } from "./googleService.js";
import { siteFor } from "./pageMeta.js";
const EMAIL = /^[^\s@,;<>]+@[^\s@,;<>]+\.[^\s@,;<>]+$/;
export function recipients(db) {
const row = db.prepare(`SELECT notify_emails FROM site_settings WHERE id = 'site'`).get();
return String(row?.notify_emails ?? "")
.split(/[\s,;]+/)
.filter((address) => EMAIL.test(address));
}
/* queue: the admin path of the queue it landed in, eg. /admin/requests */
export function notifyNew(db, { id, subject, lines, replyTo, queue }) {
if (!mailReady()) return;
const to = recipients(db);
if (to.length === 0) return;
let origin = "";
try {
origin = (siteFor(db).url ?? "").replace(/\/$/, "");
} catch {
// No site.json: the notice goes without a link.
}
const text = [...lines, "", origin ? `Open it: ${origin}${queue}` : `In the admin: Forms, ${queue}`, ""].join("\n");
sendMail({ to, subject, text, replyTo: EMAIL.test(replyTo ?? "") ? replyTo : undefined })
.then(() => console.log(`feedback #${id}: notice sent to ${to.length}`))
.catch((err) => console.warn(`feedback #${id}: notice failed: ${err.message}`));
}