Core's half of ENGAGEMENT.md Phase 11a: the two decisions the org lead settled before any code that land in core rather than in module-uo. Pairs with Module-uo#22 and docs#194. ## Decision 1 -- a seventh ceiling, `admin`, as a child of `staff` Phase 11's operator-facing triggers (uo.audit.staff_action, uo.economy.milestone, uo.world.saved) are described as admin-audience everywhere, and the narrowest value the lattice had was `staff` -- which ceilings.js defines as admin, editor AND moderator. Ceilinging them there would have let an operator save a rule that mails the staff audit digest to every moderator in it. `admin` is the ONLY genuine refinement in the tree -- every admin is staff, which is exactly the containment every other pair of branches lacks -- so it is a child rather than a seventh leaf, and permits/meet/meetAll needed no change beyond the new PARENT entry. **The one non-obvious consequence, and the reason for ROLE_CEILINGS.** notificationChannelPrefs' `visibleTo` asked `item.ceiling !== 'staff'`. That was correct while `staff` was the only role-gated value, and the day `admin` arrived it would have silently published every admin-ceilinged id -- the staff audit digest, the economy thresholds -- to every player's preferences screen by name. It now reads a TABLE (`ceilings.reachableBy`), so a ceiling added without an entry fails closed instead. An EDITOR is the viewer that tells the two rules apart, and the new tests use one. MODULE_API_VERSION -> 1.8.0 on both halves. Additive: every declaration valid under 1.7.0 is valid now and no stored value changes. ## Decision 5 -- 7.1 Q9: news.post gets an emitter, and it REPLACES the tickle `news.post` has been a declared payload contract with no caller since Phase 2, so a rule naming it could never fire. utils/newsNotify.js is the caller; announceIfNewlyPublished now calls it instead of pushDispatch.publish, gated on the same enqueueIfNeeded job id -- the single "newly published news" transition signal, not re-derived. **News push therefore stops on upgrade** until an operator enables the seeded rule. That is the org lead's decision, taken over keeping the raw call beside the emit "for one release": an exception with a deadline nobody owns, which Phase 6 already refused for Teams. The Rules screen gains a second migration notice naming news, and Phase 13's release note carries it as an upgrade step. **The seed needed its own one-shot key, and this is the trap worth recording.** `engagement_team_rules_seeded` is already stamped on every deployment that has booted since Phase 6, and the guard reads its presence -- so appending news to RULES would have seeded it on fresh installs only, and on exactly the upgrades that lose their raw push, never. One key per seed GROUP is now the rule; seedGroup() is the shared implementation and seedCoreRules() is what boot calls. Also fixes news.post's `postUrl` example, which named `/news/<slug>` -- a path App.jsx does not mount. An example is what the template editor previews and test-sends with, so a wrong one is a preview that looks right and a mail that is not. It is `/site/news`, the list, which is what the Discord and town-crier announcements have always linked. 1550 tests pass (16 new), 327 client tests pass, client builds, check:modules clean -- core still names no module identifier with module-uo now registering 24 UO-named triggers. Co-Authored-By: Claude <noreply@anthropic.com>
131 lines
5.5 KiB
JavaScript
131 lines
5.5 KiB
JavaScript
import { useEffect, useState } from 'react'
|
|
import { Loading, ErrorState } from '../../../components/PageState.jsx'
|
|
import { api } from '../../../api/client.js'
|
|
|
|
// Admin → Engagement → Triggers (ENGAGEMENT.md §4.3, Phase 5b).
|
|
//
|
|
// Read-only, and structurally so: **there is no table behind this screen.** A
|
|
// trigger is DECLARED in code by core or by an installed module, so this is
|
|
// whatever registered on the current boot. Uninstall a module and its triggers
|
|
// stop appearing here; nothing was deleted and nothing needs to be.
|
|
//
|
|
// It exists because the two things it shows are otherwise invisible and both are
|
|
// load-bearing elsewhere:
|
|
//
|
|
// • **The variables** are the contract a template may reference. When a rule
|
|
// mails nothing sensible, "which variables does this event actually carry"
|
|
// is the first question, and the answer used to live only in a module's source.
|
|
// • **The ceiling** is the security boundary from G24 — the widest audience a
|
|
// rule may ever give this trigger. A rule editor that offers a narrower set
|
|
// than an operator expects is obeying a number declared here.
|
|
|
|
const CEILING_NOTE = {
|
|
owner: 'only the person the event is about',
|
|
members: 'only members of the thing it is about',
|
|
subscribers: 'only people who opted in',
|
|
staff: 'only staff',
|
|
admin: 'only administrators',
|
|
authenticated: 'any signed-in account',
|
|
everyone: 'anyone',
|
|
}
|
|
|
|
export default function EngagementTriggers() {
|
|
const [triggers, setTriggers] = useState([])
|
|
const [loading, setLoading] = useState(true)
|
|
const [error, setError] = useState(null)
|
|
|
|
useEffect(() => {
|
|
let alive = true
|
|
;(async () => {
|
|
try {
|
|
const { triggers: list } = await api.admin.engagementTriggers()
|
|
if (alive) setTriggers(list || [])
|
|
} catch (err) {
|
|
if (alive) setError(err.message)
|
|
} finally {
|
|
if (alive) setLoading(false)
|
|
}
|
|
})()
|
|
return () => { alive = false }
|
|
}, [])
|
|
|
|
if (loading) return <Loading />
|
|
if (error) return <ErrorState message={error} />
|
|
|
|
return (
|
|
<section>
|
|
<p className="sans" style={{ margin: '0 0 16px', fontSize: '0.86rem', color: 'var(--muted)', maxWidth: 680 }}>
|
|
The events a rule can be built on, declared in code by core and by installed modules. This
|
|
list is whatever is registered right now — it is not stored anywhere, so a module that is
|
|
uninstalled simply stops appearing.
|
|
</p>
|
|
|
|
{triggers.length === 0 && (
|
|
<p className="sans dim" style={{ fontSize: '0.85rem' }}>Nothing is registered.</p>
|
|
)}
|
|
|
|
{triggers.map((t) => (
|
|
<div className="panel" key={t.id} style={{ padding: 18, marginBottom: 14 }}>
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 16, flexWrap: 'wrap' }}>
|
|
<div>
|
|
<h3 className="sans" style={{ margin: '0 0 2px', fontSize: '0.98rem' }}>{t.label}</h3>
|
|
<p className="sans dim" style={{ margin: 0, fontSize: '0.78rem' }}>
|
|
<code>{t.id}</code> · from {t.owner} · v{t.version}
|
|
</p>
|
|
</div>
|
|
<div style={{ textAlign: 'right' }}>
|
|
<div className="field-label" style={{ marginBottom: 2 }}>Can reach at most</div>
|
|
<div className="sans" style={{ fontSize: '0.84rem' }}>
|
|
{t.ceiling}
|
|
<span className="dim"> — {CEILING_NOTE[t.ceiling] || 'see the design document'}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{t.description && (
|
|
<p className="sans" style={{ margin: '10px 0 0', fontSize: '0.84rem', color: 'var(--muted)' }}>
|
|
{t.description}
|
|
</p>
|
|
)}
|
|
|
|
{(t.variables || []).length > 0 && (
|
|
<table className="adm-table" style={{ marginTop: 14 }}>
|
|
<thead>
|
|
<tr>
|
|
<th className="adm-th">Variable</th>
|
|
<th className="adm-th">Type</th>
|
|
<th className="adm-th">Example</th>
|
|
<th className="adm-th">What it is</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{t.variables.map((v) => (
|
|
<tr key={v.name}>
|
|
{/* `nowrap`: without it the "always set" pill wraps between its
|
|
two words on a longer variable name, orphaning "set" on a
|
|
line of its own and making the row read as two facts. */}
|
|
<td className="adm-td" style={{ whiteSpace: 'nowrap' }}>
|
|
<code style={{ fontSize: '0.8rem' }}>{`{{${v.name}}}`}</code>
|
|
{v.required && <span className="pill" style={{ marginLeft: 6, fontSize: '0.66rem' }}>always set</span>}
|
|
</td>
|
|
<td className="adm-td">{v.type}</td>
|
|
<td className="adm-td" style={{ maxWidth: 260, overflowWrap: 'anywhere' }}>
|
|
<span className="dim" style={{ fontSize: '0.8rem' }}>
|
|
{/* A list variable's example is an array of objects; showing
|
|
it as JSON is honest and short, and it is the shape an
|
|
item list repeats over. */}
|
|
{typeof v.example === 'string' ? v.example : JSON.stringify(v.example)}
|
|
</span>
|
|
</td>
|
|
<td className="adm-td" style={{ fontSize: '0.82rem' }}>{v.description || ''}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
)}
|
|
</div>
|
|
))}
|
|
</section>
|
|
)
|
|
}
|