People directories, ministries, organization contacts (migrations 062 to 064)

- People tags (062): Data → People tags (Musicians seeded); a person's
  Directories repeater tags them and their Specialty line shows on
  their tile. A People directory section preset shows a tag's first
  12 and links to its full page, /directory/<tag>, with page meta and
  a sitemap entry. Tiles' details panels show a person's links.
- Ministries (063): a new organization kind. A group picks its
  ministry and its page says "Ministry: <name>", linked to the
  ministry's website. Ministries have no public page, list, sitemap
  or timeline entry, and aren't offered where a record links to its
  organization. organizations is rebuilt for the kind CHECK.
- Organization contacts (064): Data → Contact types; a private
  Contacts repeater on each organization (editors and up, readRole on
  a child collection). Tools → Newsletter → Recipients filters them
  by type, kind, region and published and downloads a Mailchimp CSV.
- A trigger refusing a save with a sentence is shown as that message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-03 22:57:34 -05:00
parent 07e56bfd20
commit 0ed7315156
38 changed files with 1108 additions and 29 deletions

View file

@ -53,13 +53,17 @@ function entityForWrite(c) {
return entity;
}
/* An extension can ask for more than a sign-in to be read
(readRole): a person's private details need editor. Blanked on
every row sent back, so a write's reply can't leak it either. */
/* An extension or a child collection can ask for more than a
sign-in to be read (readRole): a person's private details and an
organization's contacts need editor. Blanked on every row sent
back, so a write's reply can't leak it either. */
function visible(c, entity, row) {
for (const ext of entity.extensions ?? []) {
if (ext.readRole && !hasRole(c.get("user"), ext.readRole)) row[ext.key] = null;
}
for (const child of entity.children ?? []) {
if (child.readRole && !hasRole(c.get("user"), child.readRole)) row[child.key] = [];
}
return row;
}

View file

@ -364,4 +364,55 @@ admin.get("/request-files", async (c) => {
);
});
/* ── Contacts for a mailing list (064_org_contacts.sql) ──────────
GET /contacts?types=minister,info&kinds=group&region=northwest
Every organization contact matching the filters, for the
Newsletter's recipient export (a CSV made in the browser). Each
filter is optional; a region keeps the region itself and the
groups in it. Private, so editors and up only. Unpublished
organizations are left out unless ?unpublished=1. */
const CONTACT_KINDS = ["national", "region", "group", "partner", "ministry"];
const listParam = (value) => (value ?? "").split(",").map((v) => v.trim()).filter(Boolean);
admin.get("/contacts", requireRole("editor"), (c) => {
const db = c.get("db");
const types = listParam(c.req.query("types"));
const kinds = listParam(c.req.query("kinds")).filter((k) => CONTACT_KINDS.includes(k));
const region = c.req.query("region") || null;
const where = [];
const params = [];
if (types.length) {
where.push(`oc.type_id IN (${types.map(() => "?").join(",")})`);
params.push(...types);
}
if (kinds.length) {
where.push(`o.kind IN (${kinds.map(() => "?").join(",")})`);
params.push(...kinds);
}
if (region) {
where.push(`(o.id = ? OR g.region_id = ?)`);
params.push(region, region);
}
if (c.req.query("unpublished") !== "1") where.push(`o.is_published = 1`);
const rows = db
.prepare(
`SELECT oc.name, oc.email, oc.phone,
ct.id AS type_id, ct.name AS type_name,
o.id AS org_id, o.name AS org_name, o.kind AS org_kind,
r.name AS region_name
FROM organization_contacts oc
JOIN contact_types ct ON ct.id = oc.type_id
JOIN organizations o ON o.id = oc.org_id
LEFT JOIN groups g ON g.id = o.id
LEFT JOIN organizations r ON r.id = COALESCE(g.region_id, CASE o.kind WHEN 'region' THEN o.id END)
${where.length ? `WHERE ${where.join(" AND ")}` : ""}
ORDER BY o.kind, o.name, ct.sort_order, ct.name, oc.sort_order`,
)
.all(...params);
return c.json({ contacts: rows }, 200, NO_STORE);
});
export default admin;

View file

@ -70,6 +70,8 @@ const content = new Hono();
// anything. stale-while-revalidate keeps the page instant while the
// refresh happens behind it.
// Kinds with a public page. A ministry (063_ministries.sql) has none:
// it's only named on its groups' pages, so no route here serves one.
const ORG_KINDS = ["national", "region", "group", "partner"];
/* ── Loaders ───────────────────────────────────────────────── */
@ -327,9 +329,14 @@ function attachGroupDetails(db, orgs) {
const rows = db
.prepare(
`SELECT c.id, c.region_id, c.meets, c.started,
r.name AS region_name, r.color AS region_color
r.name AS region_name, r.color AS region_color,
m.name AS ministry_name,
(SELECT url FROM links
WHERE owner_kind = 'organization' AND owner_id = m.id AND kind = 'website'
ORDER BY sort_order LIMIT 1) AS ministry_url
FROM groups c
LEFT JOIN organizations r ON r.id = c.region_id
LEFT JOIN organizations m ON m.id = c.ministry_id AND m.is_published = 1
WHERE c.id IN (${marks(ids.length)})`,
)
.all(...ids);
@ -343,6 +350,10 @@ function attachGroupDetails(db, orgs) {
region_id: row.region_id ?? null,
region_name: row.region_name ?? null,
region_color: row.region_color ?? null,
// The Unity ministry it belongs to: a name, and its website
// when it has one (ministries have no page here).
ministry_name: row.ministry_name ?? null,
ministry_url: row.ministry_url ?? null,
meets: row.meets ?? null,
started: row.started ?? null,
};
@ -610,7 +621,7 @@ content.get("/organizations", (c) => {
const rows = db
.prepare(
`SELECT * FROM organizations
WHERE is_published = 1 AND is_listed = 1 ${filter}
WHERE is_published = 1 AND is_listed = 1 AND kind <> 'ministry' ${filter}
ORDER BY kind, sort_order, name`,
)
.all(...kinds);
@ -639,7 +650,7 @@ content.get("/organizations/:id", (c) => {
const id = c.req.param("id");
const row = db
.prepare(`SELECT * FROM organizations WHERE id = ? AND is_published = 1`)
.prepare(`SELECT * FROM organizations WHERE id = ? AND is_published = 1 AND kind <> 'ministry'`)
.get(id);
if (!row) return c.json({ error: "No such organization" }, 404);

View file

@ -48,7 +48,7 @@ directory.get("/directory", (c) => {
organizations: all(
`SELECT id, name, kind
FROM organizations
WHERE is_published = 1 AND is_listed = 1
WHERE is_published = 1 AND is_listed = 1 AND kind <> 'ministry'
ORDER BY kind, name`,
),
teams: all(

View file

@ -105,6 +105,8 @@ history.get("/history", (c) => {
WHERE is_published = 1
-- A standalone milestone reports null here and is unaffected.
AND (ref_is_published IS NULL OR ref_is_published = 1)
-- A ministry has no public page (063_ministries.sql).
AND (org_kind IS NULL OR org_kind <> 'ministry')
AND effective_date IS NOT NULL
ORDER BY effective_date DESC, sort_order, id`,
)

View file

@ -4,6 +4,9 @@
GET /teams/:id/people current public members of a team
GET /people?ids=a,b,c named people, any order
GET /people/:id one person's page
GET /directories/:tag a tag's directory: its name and
intro, and its published, listed
people with their specialty and links
The team route reads v_org_leadership, which already decides who
counts as current and public, affiliation still open, marked
@ -21,7 +24,7 @@
import { Hono } from "hono";
import { asBool, json, loadOwned, marks, paragraphs, splitLinks } from "../shape.js";
import { asBool, json, loadLinks, loadOwned, marks, paragraphs, splitLinks } from "../shape.js";
import { postsBy } from "./blog.js";
const people = new Hono();
@ -136,6 +139,54 @@ people.get("/people", (c) => {
return json(c, { people: rows.map(shapePerson) });
});
/* ── A tag's directory ─────────────────────────────────────────
Everyone carrying the tag (062_people_tags.sql), in name order,
each as a tile wants them plus their specialty line and links
(website, music, booking email). Unlisted people stay off it, as
they stay off every list.
───────────────────────────────────────────────────────────── */
people.get("/directories/:tag", (c) => {
const db = c.get("db");
const tag = db
.prepare(`SELECT id, name, blurb FROM person_tag_types WHERE id = ?`)
.get(c.req.param("tag"));
if (!tag) return c.json({ error: "No such directory." }, 404);
const rows = db
.prepare(
`SELECT p.id,
p.display_name,
p.pronouns,
p.photo,
p.tagline,
p.specialty,
p.location_label,
p.public_email,
p.bio,
o.id AS primary_org_id,
o.name AS primary_org_name
FROM person_tags t
JOIN people p ON p.id = t.person_id AND p.is_published = 1 AND p.is_listed = 1
LEFT JOIN organizations o ON o.id = p.primary_org_id AND o.is_published = 1
WHERE t.tag_id = ?
ORDER BY COALESCE(p.sort_name, p.display_name)`,
)
.all(tag.id);
const links = loadLinks(db, "person", rows.map((row) => row.id));
return json(c, {
directory: {
...tag,
people: rows.map((row) => ({
...shapePerson(row),
specialty: row.specialty,
links: links.get(row.id) ?? [],
})),
},
});
});
/* ── One person's page ─────────────────────────────────────────
Everything public that points at this person, each list with
the same visibility rules its own page applies: a role needs a

View file

@ -37,7 +37,7 @@ sitePages.get("/site-pages/:id", (c) => {
const rows = db
.prepare(
`SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view
`SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, tag_id
FROM page_sections WHERE page_id = ? ORDER BY sort_order, id`,
)
.all(id);