NGU-Web/src/lib/adminSchema/siteSettings.ts
Zaldimmar 80877a4659 Let Google Workspace groups grant admin access
Site settings → Access names a group for each of admin, editor and
viewer (migration 047). Someone in one who signs in with Google gets a
Google-only account with their highest group's role, and the role
follows the groups: at every sign-in, hourly while signed in, and on
Panel → Google groups → Re-sync now. Out of every group, the account
is disabled and signed out until they're back in one.

Group accounts' roles are locked in the Panel; a superadmin's Disable
sticks. Superadmins and admin-cli accounts are never changed. If
Google can't be asked, sign-ins are refused but the hourly check
leaves accounts alone. Panel → Check their groups tests an email.

Lookups use the service account through the Directory API as
GOOGLE_DIRECTORY_AS. Setup: docs/google-sign-in.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 17:44:04 -05:00

216 lines
8.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import siteConfiguration from "../../../site.json";
import { mediaUrl } from "../media.ts";
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
/* ── Site settings (035_site_settings.sql) ───────────────────────
Overrides for site.json, superadmins only: every blank falls back
to what site.json says, which is shown as the default. */
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
([path, page]) => [path, `${page.title} (${path})`],
);
/* The palette an admin can change, in the order the dropdown lists
it: token and label. The defaults come from the server's list
(server/src/themeDefaults.js), which the build checks against
src/index.css, so there's one copy of each colour to change. */
const THEME_LABELS: [string, string][] = [
["ink", "Headings"],
["body", "Body text"],
["muted", "Secondary text and quiet borders"],
["link", "Links and teal text"],
["brand", "Brand teal (borders, rules, rings)"],
["action", "Buttons (under white text)"],
["action-hover", "Buttons, hovered"],
["surface", "Page and card background"],
["tint", "Tinted sections and panels"],
["tint-soft", "Faint panels and hovered rows"],
["danger", "Errors and warnings"],
["danger-tint", "Error panel background"],
];
const THEME_COLORS: [string, string, string, string][] = THEME_LABELS.map(([token, label]) => [
token,
label,
THEME_DEFAULTS[token][0],
THEME_DEFAULTS[token][1],
]);
const defaultHelp = (row, column: 2 | 3) => {
const entry = THEME_COLORS.find(([token]) => token === row?.token);
return entry ? `Default: ${entry[column]}` : undefined;
};
export const siteSettings = {
key: "site_settings",
label: "Site settings",
singular: "site settings",
idLabel: "Settings",
singleton: "site",
writeRole: "superadmin",
list: { columns: [], filters: [] },
groups: [
{
legend: "The site",
note: "Anything left blank uses site.json, so the build and these settings agree until you change one.",
fields: [
{ path: "site_name", label: "Site name", help: `Default: ${siteConfiguration.title}` },
{
path: "description",
label: "Description",
widget: "textarea",
full: true,
help: "Search engines and link previews show this for pages without their own. Default: site.json's, or the front page's subhead.",
},
{
path: "preview_image",
label: "Preview image",
widget: "image",
resolve: mediaUrl,
full: true,
help: "Shown when a page without its own image is shared. 1200 × 630 works everywhere.",
},
],
},
{
legend: "Icons",
fields: [
{
path: "favicon",
label: "Favicon",
widget: "image",
resolve: mediaUrl,
full: true,
help: "The browser-tab icon: a square PNG (512px) or an SVG. Keep original when uploading an SVG.",
},
{
path: "apple_touch_icon",
label: "Home-screen icon",
widget: "image",
resolve: mediaUrl,
full: true,
help: "For iPhones saving the site to their home screen: a square PNG, 180px, no transparency.",
},
],
},
{
legend: "Search engines",
fields: [
{
path: "indexing",
label: "Let search engines list this site",
widget: "select",
options: [
["on", "On: pages can appear in Google"],
["off", "Off: hidden from search (use on the dev server)"],
],
blankLabel: `Default: site.json (${siteConfiguration.robots?.index === false ? "off" : "on"})`,
help: "Applies to this server's database only, so dev can be off while production is on.",
},
],
},
{
legend: "Privacy",
fields: [
{
path: "privacy_email",
label: "Privacy contact email",
help: `The Privacy page gives this for privacy questions and data requests, eg. privacy@nextgenerationofunity.org. ${
siteConfiguration.privacyEmail ? `Default: ${siteConfiguration.privacyEmail}` : "Default: none, the page offers its request form only"
}.`,
},
],
},
{
legend: "Access (Google groups)",
note: "Anyone in one of these Workspace groups can sign in to the admin with Google; their account is made at first sign-in, with the highest role their groups give. Their role follows the groups (checked at sign-in, hourly, and by Panel → Re-sync now); out of every group, the account is disabled. Superadmins and accounts made with admin-cli aren't affected. Needs GOOGLE_DIRECTORY_AS on the server (docs/google-sign-in.md).",
fields: [
{
path: "access_group_admin",
label: "Admins group",
help: "Its members sign in as admins: edit and delete anything. eg. web-admins@nextgenerationofunity.org. Default: none.",
},
{
path: "access_group_editor",
label: "Editors group",
help: "Its members sign in as editors: create and edit, not delete. eg. web-editors@nextgenerationofunity.org. Default: none.",
},
{
path: "access_group_viewer",
label: "Viewers group",
help: "Its members sign in as viewers: read only. eg. web-viewers@nextgenerationofunity.org. Default: none.",
},
],
},
{
legend: "Notices",
fields: [
{
path: "notify_emails",
label: "Email new requests to",
widget: "testNotice",
full: true,
help: "Who gets an email for each new content request (the Request form) and data request (the Privacy page), separated by commas, eg. web@nextgenerationofunity.org, board@nextgenerationofunity.org. Needs Gmail set up on the server (docs/google-drive-and-mail.md). Send a test notice emails whatever is in the box now, saved or not, and shows Google's answer. Default: none, check Forms instead.",
},
],
},
],
children: [
{
key: "colors",
label: "Colours",
note: "Change any of the site's colours, for light mode, dark mode or both; a blank keeps the default. Saving refuses a palette that would make text hard to read (under 4.5:1). Changes show on the next page load.",
addLabel: "Change a colour",
title: (row) => THEME_COLORS.find(([token]) => token === row.token)?.[1] ?? "New colour",
blank: { token: "", light: "", dark: "" },
fields: [
{
path: "token",
label: "Colour",
widget: "select",
options: THEME_COLORS.map(([token, label]) => [token, label]),
required: true,
},
{
path: "light",
label: "Light mode",
widget: "color",
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[2],
help: (row) => defaultHelp(row, 2),
},
{
path: "dark",
label: "Dark mode",
widget: "color",
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[3],
help: (row) => defaultHelp(row, 3),
},
],
},
{
key: "pages",
label: "Page titles and intros",
note: "Change a static page's heading and intro, which are also its search title and description. Blank fields keep site.json's.",
addLabel: "Change a page",
title: (row) => SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page",
blank: { path: "", title: "", description: "" },
fields: [
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
{
path: "title",
label: "Title",
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.title ?? ""}` : undefined),
},
{
path: "description",
label: "Intro",
widget: "textarea",
full: true,
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.description ?? ""}` : undefined),
},
],
},
],
};