Hub 2.9.0: whether people can sign in

- An Events install's page shows its sign-in mode, whether it's linked to the church's Accounts,
  and the last sign-in failure (Events 3.5.0 heartbeat, contracts 1.13.0 vendored).
- Alerts: signs in through Accounts but isn't linked (critical), linked to the wrong Accounts, a
  sign-in failed in the last 24 hours, an Accounts nothing is linked to while the church has Events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 12:56:41 +02:00
co-authored by Claude Opus 5.5
parent 1150a82ecc
commit 894f2b2771
12 changed files with 130 additions and 19 deletions
+10 -6
View File
@@ -12,7 +12,7 @@ const { ymd, today } = require('../utils/billing/dates');
const { linkedProductsFor } = require('../utils/protocol');
const { audit } = require('../utils/audit');
const { getSettings, setSettings } = require('../utils/settings');
const { problems, compareVersions } = require('../utils/alerts');
const { problems, compareVersions, churchesOf } = require('../utils/alerts');
const licenceToken = require('../utils/licenceToken');
const { smtpConfigured, testSmtp } = require('../utils/mail');
const { VERSION_RE, sortReleases, syncLatestVersion, latestVersions, unmetRequirementsFor } = require('../utils/releases');
@@ -43,8 +43,9 @@ function dateOrNull(v) {
}
// The health of an install at a glance, for lists. `latest` is the latest version per product.
function summary(install, settings, latest = {}, now = new Date()) {
const current = problems(install, { ...settings, latest_versions: latest }, now);
function summary(install, settings, latest = {}, now = new Date(), church = undefined) {
// Hub 2.9.0: `church` (churchesOf) lets the sign-in checks compare with the church's Accounts.
const current = problems({ ...install, church }, { ...settings, latest_versions: latest }, now);
const latestForProduct = latest[install.product] || null;
const worst = current.some(p => p.level === 'critical') ? 'critical' : current.some(p => p.level === 'warning') ? 'warning' : 'ok';
return {
@@ -69,7 +70,8 @@ function summary(install, settings, latest = {}, now = new Date()) {
router.get('/dashboard', wrap(async (req, res) => {
const [settings, latest] = await Promise.all([getSettings(), latestVersions()]);
const installs = await prisma.install.findMany({ where: { releasedAt: null }, include: { licence: true, customer: true }, orderBy: { name: 'asc' } });
const rows = installs.map(i => summary(i, settings, latest));
const churches = churchesOf(installs);
const rows = installs.map(i => summary(i, settings, latest, new Date(), churches.get(i.customerId)));
const [customers, licences, openAlerts, billed, sentInvoices] = await Promise.all([
prisma.customer.count(),
prisma.licence.groupBy({ by: ['product', 'status'], _count: { _all: true } }),
@@ -227,7 +229,8 @@ router.post('/licences/:id/release', wrap(async (req, res) => {
router.get('/installs', wrap(async (req, res) => {
const [settings, latest] = await Promise.all([getSettings(), latestVersions()]);
const installs = await prisma.install.findMany({ include: { licence: true, customer: true }, orderBy: { name: 'asc' } });
res.json(installs.map(i => summary(i, settings, latest)));
const churches = churchesOf(installs.filter(i => !i.releasedAt));
res.json(installs.map(i => summary(i, settings, latest, new Date(), churches.get(i.customerId))));
}));
router.get('/installs/:id', wrap(async (req, res) => {
@@ -251,12 +254,13 @@ router.get('/installs/:id', wrap(async (req, res) => {
}
const target = latest[install.product] || null;
const behind = !!(target && install.version && compareVersions(install.version, target) < 0);
const church = churchesOf(await prisma.install.findMany({ where: { customerId: install.customerId, releasedAt: null }, select: { id: true, product: true, customerId: true } })).get(install.customerId);
const [aiStatus, aiMonths, aiHelpers, unmet] = await Promise.all([
ai.statusFor(install), ai.usageByMonth(install.id), ai.usageByHelper(install.id),
behind ? unmetRequirementsFor(install, target) : [],
]);
res.json({
...safe, licence, summary: summary(install, settings, latest), heartbeats, ai: { status: aiStatus, months: aiMonths, helpers: aiHelpers },
...safe, licence, summary: summary(install, settings, latest, new Date(), church), heartbeats, ai: { status: aiStatus, months: aiMonths, helpers: aiHelpers },
// What updating to the latest version needs from the church's other products (Hub 2.0).
update: { latestVersion: target, behind, unmetRequirements: unmet },
// The church's other installs this one is told about (protocol v2), and the ones it isn't.
+51 -2
View File
@@ -76,6 +76,41 @@ function problems(install, settings, now = new Date()) {
if (latest && install.version && compareVersions(install.version, latest) < 0) {
out.push({ type: 'behind', level: 'info', message: `Runs ${install.version}; latest is ${latest}` });
}
if (lastSeen) out.push(...signInProblems(install, now));
return out;
}
/**
* Hub 2.9.0: whether people can sign in (contracts 1.13.0). `install.church` (filled in by
* runAlerts): { accountsInstallIds, hasEvents } for the install's customer.
* - Events (heartbeat `stats.signIn`, Events 3.5.0+): signs in through Accounts but isn't linked
* (nobody can sign in), linked to an Accounts that isn't this church's, or a sign-in that failed
* in the last 24 hours.
* - Accounts: the church has Events but no product is linked to Accounts.
*/
function signInProblems(install, now = new Date()) {
const out = [];
const church = install.church || {};
if ((install.product || 'events') === 'events') {
const s = install.stats?.signIn;
if (!s) return out;
if (s.mode === 'accounts' && !s.accounts) {
out.push({ type: 'signin_not_linked', level: 'critical', message: 'Signs in through Accounts but isn\'t linked to it: nobody can sign in. Connect Accounts under Settings → Linked products (Events 3.5.0+ reconnects by itself at its next heartbeat when the Hub lists the church\'s Accounts).' });
} else if (s.accounts && Array.isArray(church.accountsInstallIds) && !church.accountsInstallIds.includes(s.accounts.installId)) {
out.push({ type: 'signin_wrong_accounts', level: 'warning', message: church.accountsInstallIds.length
? `Linked to an Accounts (${s.accounts.url}) that isn't this church's Accounts on the Hub.`
: `Linked to an Accounts (${s.accounts.url}) the Hub doesn't list for this church.` });
}
const err = s.lastError;
if (err && now - new Date(err.at) < DAY) {
out.push({ type: 'signin_failing', level: 'warning', message: `A sign-in failed ${new Date(err.at).toISOString()} (${err.code}): ${err.message}` });
}
} else if (install.product === 'accounts') {
const linked = install.stats?.linkedProducts;
if (church.hasEvents && linked === 0) {
out.push({ type: 'accounts_unlinked', level: 'warning', message: 'No product is linked to this Accounts, though the church has Cross Events: Events can\'t sign anyone in through it.' });
}
}
return out;
}
@@ -89,6 +124,19 @@ async function latestVersionsNow() {
return out;
}
/** Per customer: its Accounts install ids, and whether it has Cross Events (for signInProblems). */
function churchesOf(installs) {
const out = new Map();
for (const i of installs) {
if (!i.customerId) continue;
const c = out.get(i.customerId) || { accountsInstallIds: [], hasEvents: false };
if (i.product === 'accounts') c.accountsInstallIds.push(i.id);
if ((i.product || 'events') === 'events') c.hasEvents = true;
out.set(i.customerId, c);
}
return out;
}
async function runAlerts(now = new Date()) {
const settings = { ...(await getSettings()), latest_versions: await latestVersionsNow() };
const installs = await prisma.install.findMany({
@@ -98,8 +146,9 @@ async function runAlerts(now = new Date()) {
let opened = 0;
let resolved = 0;
const newAlerts = [];
const churches = churchesOf(installs);
for (const install of installs) {
const current = problems(install, settings, now);
const current = problems({ ...install, church: churches.get(install.customerId) }, settings, now);
// Update requests are opened by the install and resolved by its heartbeat, not by these checks.
const openByType = new Map(install.events.filter(e => !['registered', 'version', 'update_requested', 'update_request_withdrawn'].includes(e.type)).map(e => [e.type, e]));
for (const p of current) {
@@ -139,4 +188,4 @@ async function rollupHeartbeats(now = new Date(), db = prisma) {
return { deleted: res };
}
module.exports = { compareVersions, problems, runAlerts, rollupHeartbeats };
module.exports = { compareVersions, problems, signInProblems, churchesOf, runAlerts, rollupHeartbeats };