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:
parent
0e582c236b
commit
dc53af238f
31 changed files with 1318 additions and 113 deletions
118
docs/google-drive-and-mail.md
Normal file
118
docs/google-drive-and-mail.md
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
# Google Drive and Gmail (the Request form)
|
||||
|
||||
The Request form (`/request`) keeps the files people send in a Google
|
||||
Drive folder, and new requests can be emailed to whoever is listed in
|
||||
Panel → Site settings → Notices. Both go through one Google **service
|
||||
account** (`server/src/googleService.js`). Nothing here is needed for
|
||||
the rest of the site; until it's set up, the form takes no files and no
|
||||
mail goes out.
|
||||
|
||||
| Setting on the `ngu-api` service | What it is |
|
||||
| --- | --- |
|
||||
| `GOOGLE_SERVICE_ACCOUNT` | Path to the service account's key file, eg. `/etc/ngu/google-service-account.json` |
|
||||
| `GOOGLE_DRIVE_FOLDER` | The Drive folder's id (the last part of its URL) |
|
||||
| `GOOGLE_MAIL_FROM` | The Workspace address notices are sent from, eg. `web@nextgenerationofunity.org` |
|
||||
|
||||
Files need the first two; mail needs the first and third.
|
||||
|
||||
## 1. The service account
|
||||
|
||||
1. In Google Cloud Console (the project that holds the Google sign-in
|
||||
client is fine), enable the **Google Drive API** and the **Gmail
|
||||
API**.
|
||||
2. IAM & Admin → Service accounts → Create. Name it eg. `ngu-site`. It
|
||||
needs no roles on the project.
|
||||
3. Open it → Keys → Add key → JSON. Copy the file to the VPS, outside
|
||||
the app and the repo:
|
||||
|
||||
```sh
|
||||
sudo mkdir -p /etc/ngu
|
||||
sudo mv ngu-site-*.json /etc/ngu/google-service-account.json
|
||||
sudo chown <ngu-api user>: /etc/ngu/google-service-account.json
|
||||
sudo chmod 600 /etc/ngu/google-service-account.json
|
||||
```
|
||||
|
||||
Note the account's email (`ngu-site@<project>.iam.gserviceaccount.com`)
|
||||
and, from its Details page, its **Client ID** (a long number).
|
||||
|
||||
## 2. The Drive folder
|
||||
|
||||
A service account has no Drive storage of its own, so the folder must
|
||||
be in a **shared drive**.
|
||||
|
||||
1. In Google Drive, make (or pick) a shared drive, eg. "NGU Website",
|
||||
and a folder in it, eg. "Requests".
|
||||
2. Shared drive → Manage members → add the service account's email as
|
||||
**Content manager**.
|
||||
3. Open the folder; its id is the end of the address:
|
||||
`https://drive.google.com/drive/folders/<this part>`.
|
||||
|
||||
Files are named `Request 12 - original name.docx`, so the number matches
|
||||
the one in Forms → Content requests. Deleting a request in the admin
|
||||
deletes its files from Drive too.
|
||||
|
||||
## 3. Gmail (domain-wide delegation)
|
||||
|
||||
For the service account to send as a Workspace user:
|
||||
|
||||
1. Google Admin console → Security → Access and data control → API
|
||||
controls → **Manage domain wide delegation** → Add new.
|
||||
2. Client ID: the service account's Client ID from step 1.
|
||||
OAuth scopes: `https://www.googleapis.com/auth/gmail.send`
|
||||
3. `GOOGLE_MAIL_FROM` is the address it sends as. It must be a real
|
||||
user or group-owned mailbox in the Workspace (not an alias); a
|
||||
dedicated `web@` account keeps the sent mail out of anyone's inbox.
|
||||
|
||||
Then in the admin, Panel → Site settings → Notices → "Email new
|
||||
requests to": one or more addresses, separated by commas. Each new
|
||||
content request and data request sends one plain-text email with a link
|
||||
to the queue; replying goes to the person who sent the request.
|
||||
|
||||
## 4. The service and nginx
|
||||
|
||||
```sh
|
||||
sudo systemctl edit ngu-api
|
||||
```
|
||||
|
||||
```ini
|
||||
[Service]
|
||||
Environment=GOOGLE_SERVICE_ACCOUNT=/etc/ngu/google-service-account.json
|
||||
Environment=GOOGLE_DRIVE_FOLDER=<folder id>
|
||||
Environment=GOOGLE_MAIL_FROM=web@nextgenerationofunity.org
|
||||
```
|
||||
|
||||
nginx caps `/api/` bodies at 64k, so the form needs its own block in
|
||||
the site's `server` block, beside `/api/admin/import/docx` (`nginx-dev`
|
||||
has it):
|
||||
|
||||
```nginx
|
||||
location = /api/requests {
|
||||
proxy_pass http://127.0.0.1:3001;
|
||||
# the usual proxy_set_header lines
|
||||
proxy_read_timeout 120s;
|
||||
client_max_body_size 31m;
|
||||
}
|
||||
```
|
||||
|
||||
`sudo nginx -t && sudo systemctl reload nginx && sudo systemctl restart ngu-api`.
|
||||
|
||||
## Checking it
|
||||
|
||||
- Send a request with a small file at `/request`. The journal shows
|
||||
`feedback #N (content: new blog, 1 files)`, and with mail on,
|
||||
`feedback #N: notice sent to 1`.
|
||||
- The file is in the Drive folder, and downloads from Forms → Content
|
||||
requests.
|
||||
- `token refused: unauthorized_client` on mail means the delegation
|
||||
(step 3) is missing or has the wrong Client ID or scope. `404 File not
|
||||
found` on upload means the folder id is wrong or the service account
|
||||
isn't a member of the shared drive.
|
||||
|
||||
## What the form takes
|
||||
|
||||
Up to 3 files of 10 MB each: Word documents (.docx), PDFs, JPEG and PNG,
|
||||
checked by their contents rather than their names
|
||||
(`server/src/routes/requests.js`). A Word document on a request can be
|
||||
turned into an unpublished blog post from the queue ("Make a blog post
|
||||
from it"), the same conversion as Blog posts → Import from Word
|
||||
(`docs/importing.md`).
|
||||
|
|
@ -273,6 +273,7 @@ The numbers band's "Number Source" dropdown works the same way:
|
|||
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
|
||||
| Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). |
|
||||
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. |
|
||||
| Request form types (what `/request` can ask for) | `src/data/requestTypes.ts` **and** `CATEGORIES` in `server/src/routes/requests.js` **and** the CHECK on `feedback.category` (`046_content_requests.sql`) | Ids and allowed actions (new, update) identical in all three; a new id needs a migration. Labels, hints and the name field's question are client-only. A button to the form opened on one type: `request: { type, label }` on a section manifest entry, or `<RequestLink>` (`src/components/RequestLink.tsx`). |
|
||||
| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. |
|
||||
| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. |
|
||||
| A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue