From dab6fbcff6e74c20ab61fc1cf3468932162dafc0 Mon Sep 17 00:00:00 2001 From: Joshua Oosthuizen Date: Thu, 19 Nov 2026 22:15:58 +0200 Subject: [PATCH] Hub 2.7.1: one click is one update Buttons are off from the click until the Hub answers (the Updates page and every action on an install's page); the server refuses a second update for an install with one planned or running (ALREADY_PLANNED). Test. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 10 ++++ backend/package-lock.json | 4 +- backend/package.json | 2 +- backend/src/utils/jobs.js | 3 ++ backend/tests/servers.test.js | 13 ++++++ frontend/package-lock.json | 4 +- frontend/package.json | 2 +- .../app/(hub)/servers/installs/[id]/page.tsx | 46 ++++++++++++++----- .../src/app/(hub)/servers/updates/page.tsx | 18 ++++++-- 9 files changed, 81 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bff5fa0..adfc40d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [2.7.1] - 2026-11-19 + +### Fixed + +- **A double click could plan an update twice.** The update buttons (Updates page, an install's + Schedule / Update now) and every other action on an install's page are off from the click until + the Hub answers ("Working…"). The server also refuses a second update for an install that already + has one planned or running (`ALREADY_PLANNED`: cancel that job first), so a second tab can't + either. + ## [2.7.0] - 2026-11-19 ### Added diff --git a/backend/package-lock.json b/backend/package-lock.json index 046cba0..89b7fc5 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,12 +1,12 @@ { "name": "events-hub-backend", - "version": "2.7.0", + "version": "2.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-backend", - "version": "2.7.0", + "version": "2.7.1", "hasInstallScript": true, "dependencies": { "@anthropic-ai/sdk": "^1.3.0", diff --git a/backend/package.json b/backend/package.json index 37b7e88..7e2927b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-backend", - "version": "2.7.0", + "version": "2.7.1", "private": true, "description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats", "main": "src/index.js", diff --git a/backend/src/utils/jobs.js b/backend/src/utils/jobs.js index bad920e..d3e2a34 100644 --- a/backend/src/utils/jobs.js +++ b/backend/src/utils/jobs.js @@ -757,6 +757,9 @@ async function scheduleUpdate({ deploymentIds, product: wanted = null, version, } for (const d of deployments) { if (d.status !== 'live') throw fail(409, 'NOT_LIVE', `${d.shortName} isn't live (${d.status}).`); + // 2.7.1: one update at a time per install, so a second click (or a second tab) can't plan another. + const pending = await prisma.job.findFirst({ where: { deploymentId: d.id, type: 'deploy', status: { in: ['scheduled', 'queued', 'delivered'] } } }); + if (pending) throw fail(409, 'ALREADY_PLANNED', `${d.shortName} already has an update ${pending.status === 'delivered' ? 'running' : `planned for ${sast(pending.notBefore)}`}. Cancel it first (its job) to plan another.`); if (d.server.removedAt) throw fail(409, 'SERVER_REMOVED', `${d.shortName}'s server was removed.`); if (d.install) { // Accounts is handled below (kept, updated, or installed first); anything else must be met. diff --git a/backend/tests/servers.test.js b/backend/tests/servers.test.js index 7c863a1..1f53408 100644 --- a/backend/tests/servers.test.js +++ b/backend/tests/servers.test.js @@ -730,3 +730,16 @@ describe('emergency updates as soon as possible, and events on now (2.7.0)', () expect((await urgent([stale.id, older.id], { asap: true })).jobs).toHaveLength(2); }); }); + +describe('one update at a time per install (2.7.1)', () => { + test('a second update for an install with one planned is refused, and none is made', async () => { + const { server } = await joinServer(); + await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); + await db.install.create({ data: { id: 'inst-twice', customerId: 'cust-1', product: 'events', name: 'Twice', url: 'https://events.twice.co.za', secret: 'x', version: '2.3.0' } }); + const d = await db.deployment.create({ data: { id: 'dep-twice', serverId: server.id, customerId: 'cust-1', installId: 'inst-twice', product: 'events', shortName: 'twice', domain: 'events.twice.co.za', webPort: 24000, apiPort: 24001, status: 'live' } }); + const at = new Date(NOW.getTime() + 5 * 3600e3); + await jobs.scheduleUpdate({ deploymentIds: [d.id], version: '2.4.0', at }, admin, NOW); + await expect(jobs.scheduleUpdate({ deploymentIds: [d.id], version: '2.4.0', at }, admin, NOW)).rejects.toMatchObject({ code: 'ALREADY_PLANNED' }); + expect(await db.job.count({ where: { deploymentId: d.id, type: 'deploy' } })).toBe(1); + }); +}); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 1c2ea2d..7a41365 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "events-hub-frontend", - "version": "2.7.0", + "version": "2.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "events-hub-frontend", - "version": "2.7.0", + "version": "2.7.1", "dependencies": { "lucide-react": "^0.536.0", "next": "^15.5.24", diff --git a/frontend/package.json b/frontend/package.json index a042604..e60653d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "events-hub-frontend", - "version": "2.7.0", + "version": "2.7.1", "private": true, "scripts": { "dev": "next dev -p 3200", diff --git a/frontend/src/app/(hub)/servers/installs/[id]/page.tsx b/frontend/src/app/(hub)/servers/installs/[id]/page.tsx index b1abddb..7653eef 100644 --- a/frontend/src/app/(hub)/servers/installs/[id]/page.tsx +++ b/frontend/src/app/(hub)/servers/installs/[id]/page.tsx @@ -44,7 +44,27 @@ export default function DeploymentPage() { useEffect(() => { load(); }, [load]); useEffect(() => { api("/api/admin/releases").then(setReleases).catch(() => {}); }, []); - const act = async (path: string, body: Record, ok: string) => { + // 2.7.1: every button here is off from a click until the Hub answers, so one click is one job. + const [busy, setBusy] = useState(false); + const withBusy = async (fn: () => Promise) => { + if (busy) return; + setBusy(true); + try { + await fn(); + } finally { + setBusy(false); + } + }; + const act = async (path: string, body: Record, ok: string): Promise => { + if (busy && !body.confirmLive) return; + setBusy(true); + try { + await doAct(path, body, ok); + } finally { + setBusy(false); + } + }; + const doAct = async (path: string, body: Record, ok: string): Promise => { setMsg(null); try { const r = await api<{ warnings?: string[] }>(path, { method: "POST", body }); @@ -52,11 +72,12 @@ export default function DeploymentPage() { load(); } catch (e) { // Hub 2.7.0: an event is on there now: ask once more, then go ahead. - if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return act(path, { ...body, confirmLive: true }, ok); + if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return doAct(path, { ...body, confirmLive: true }, ok); setMsg({ type: "err", text: errorText(e) }); } }; - const proxyDone = async () => { + const proxyDone = () => withBusy(proxyDoneNow); + const proxyDoneNow = async () => { setMsg(null); try { const r = await api<{ live: boolean; problems: string[] }>(`/api/admin/deployments/${id}/proxy-done`, { method: "POST" }); @@ -66,7 +87,8 @@ export default function DeploymentPage() { } catch (e) { setMsg({ type: "err", text: errorText(e) }); } }; - const removeRecord = async () => { + const removeRecord = () => withBusy(removeRecordNow); + const removeRecordNow = async () => { if (!d || !window.confirm(`Remove the record of ${d.deployment.shortName}? Its install failed, so nothing of it is on the server.`)) return; setMsg(null); try { @@ -98,7 +120,7 @@ export default function DeploymentPage() {

Set up the site in FastPanel

{d.fastPanel}
- + {x.status === "installing" &&

Waiting for the install to finish (see its job below).

}
)} @@ -126,7 +148,7 @@ export default function DeploymentPage() {
setUpd({ ...upd, reason: e.target.value })} />
setUpd({ ...upd, totp: e.target.value })} />
} -
+
)} @@ -138,7 +160,7 @@ export default function DeploymentPage() {
setAdopt({ ...adopt, address: e.target.value })} />
setAdopt({ ...adopt, version: e.target.value })} />
setAdopt({ ...adopt, at: e.target.value })} />
-
+
)} @@ -149,7 +171,7 @@ export default function DeploymentPage() {
{ e.preventDefault(); act(`/api/admin/deployments/${x.id}/demo`, { isDemo: true, confirm: demo.markConfirm }, "Marked as a demo site."); }}>

A demo site's data can be replaced with demo data from here. Only mark sites used for showing Cross Events, never a church's real site.

setDemo({ ...demo, markConfirm: e.target.value })} />
- +
) : ( <> @@ -164,7 +186,7 @@ export default function DeploymentPage() {
setDemo({ ...demo, confirm: e.target.value })} />
- + @@ -180,7 +202,7 @@ export default function DeploymentPage() { {j.type}{j.emergency && emergency} {fmtDate(j.notBefore)}{j.message} - {["queued", "scheduled"].includes(j.status) && } + {["queued", "scheduled"].includes(j.status) && } ))} @@ -198,7 +220,7 @@ export default function DeploymentPage() {

Remove the record

This install failed and the server already removed what it made, so there's nothing to export or uninstall. Removing the record frees the short name.

- +
)} @@ -209,7 +231,7 @@ export default function DeploymentPage() {
setUn({ ...un, at: e.target.value })} />
setUn({ ...un, confirm: e.target.value })} />
setUn({ ...un, totp: e.target.value })} />
-
+
)} diff --git a/frontend/src/app/(hub)/servers/updates/page.tsx b/frontend/src/app/(hub)/servers/updates/page.tsx index 67ce4df..38a2db9 100644 --- a/frontend/src/app/(hub)/servers/updates/page.tsx +++ b/frontend/src/app/(hub)/servers/updates/page.tsx @@ -32,6 +32,8 @@ export default function UpdatesPage() { const [chosen, setChosen] = useState([]); const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" }); const [msg, setMsg] = useState(null); + // 2.7.1: the button is off from the click until the Hub answers, so one click is one update. + const [busy, setBusy] = useState(false); const load = useCallback(() => { api<{ deployments: Deployment[] }>("/api/admin/deployments?status=live").then(r => setAll(r.deployments)).catch(e => setMsg({ type: "err", text: errorText(e) })); @@ -54,8 +56,18 @@ export default function UpdatesPage() { setMsg(null); }; - const submit = async (e: React.FormEvent | null, confirmLive = false) => { + const submit = async (e: React.FormEvent | null, confirmLive = false): Promise => { e?.preventDefault(); + if (busy && !confirmLive) return; + setBusy(true); + try { + await send(confirmLive); + } finally { + setBusy(false); + } + }; + + const send = async (confirmLive: boolean): Promise => { setMsg(null); const asap = form.emergency && form.asap; try { @@ -67,7 +79,7 @@ export default function UpdatesPage() { load(); } catch (err) { // Hub 2.7.0: an event is on at one of them: ask once more, then go ahead. - if (err instanceof ApiError && err.code === "LIVE_EVENT" && !confirmLive && window.confirm(err.message)) return submit(null, true); + if (err instanceof ApiError && err.code === "LIVE_EVENT" && !confirmLive && window.confirm(err.message)) return send(true); setMsg({ type: "err", text: errorText(err) }); } }; @@ -122,7 +134,7 @@ export default function UpdatesPage() {
setForm({ ...form, totp: e.target.value })} />
} - + )}