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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Generated
+2
-2
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Generated
+2
-2
@@ -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",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "2.7.0",
|
||||
"version": "2.7.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
@@ -44,7 +44,27 @@ export default function DeploymentPage() {
|
||||
useEffect(() => { load(); }, [load]);
|
||||
useEffect(() => { api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {}); }, []);
|
||||
|
||||
const act = async (path: string, body: Record<string, unknown>, 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<void>) => {
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const act = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
|
||||
if (busy && !body.confirmLive) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await doAct(path, body, ok);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const doAct = async (path: string, body: Record<string, unknown>, ok: string): Promise<void> => {
|
||||
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() {
|
||||
<div className="card">
|
||||
<h2 className="font-medium">Set up the site in FastPanel</h2>
|
||||
<pre className="mt-3 overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-50 p-3 text-xs">{d.fastPanel}</pre>
|
||||
<button className="btn-primary mt-3" disabled={x.status !== "waiting_for_proxy"} onClick={proxyDone}>Proxy done</button>
|
||||
<button className="btn-primary mt-3" disabled={x.status !== "waiting_for_proxy" || busy} onClick={proxyDone}>Proxy done</button>
|
||||
{x.status === "installing" && <p className="mt-2 text-xs text-slate-500">Waiting for the install to finish (see its job below).</p>}
|
||||
</div>
|
||||
)}
|
||||
@@ -126,7 +148,7 @@ export default function DeploymentPage() {
|
||||
<div><label className="label" htmlFor="u-r">Reason (shown to the church)</label><input id="u-r" className="input" required value={upd.reason} onChange={e => setUpd({ ...upd, reason: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="u-t">Two-factor code</label><input id="u-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={upd.totp} onChange={e => setUpd({ ...upd, totp: e.target.value })} /></div>
|
||||
</>}
|
||||
<div className="md:col-span-2"><button className="btn-primary">{upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
|
||||
<div className="md:col-span-2"><button className="btn-primary" disabled={busy} aria-busy={busy}>{busy ? "Working…" : upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
@@ -138,7 +160,7 @@ export default function DeploymentPage() {
|
||||
<div><label className="label" htmlFor="a-a">The church's address</label><input id="a-a" className="input" required={!x.domain.startsWith("events.")} placeholder={x.domain.startsWith("events.") ? x.domain.slice("events.".length) : "hope.co.za"} value={adopt.address} onChange={e => setAdopt({ ...adopt, address: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="a-v">Release</label><input id="a-v" className="input" placeholder="latest" value={adopt.version} onChange={e => setAdopt({ ...adopt, version: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="a-at">When</label><input id="a-at" type="datetime-local" className="input" value={adopt.at} onChange={e => setAdopt({ ...adopt, at: e.target.value })} /></div>
|
||||
<div className="md:col-span-3"><button className="btn-primary">Plan the move</button></div>
|
||||
<div className="md:col-span-3"><button className="btn-primary" disabled={busy}>Plan the move</button></div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
@@ -149,7 +171,7 @@ export default function DeploymentPage() {
|
||||
<form className="grid gap-3 md:grid-cols-[1fr_auto] md:items-end" onSubmit={e => { e.preventDefault(); act(`/api/admin/deployments/${x.id}/demo`, { isDemo: true, confirm: demo.markConfirm }, "Marked as a demo site."); }}>
|
||||
<p className="text-sm text-slate-500 md:col-span-2">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.</p>
|
||||
<div><label className="label" htmlFor="d-m">Type {x.shortName}</label><input id="d-m" className="input" value={demo.markConfirm} onChange={e => setDemo({ ...demo, markConfirm: e.target.value })} /></div>
|
||||
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName}>Mark as a demo site</button>
|
||||
<button className="btn-secondary" disabled={demo.markConfirm !== x.shortName || busy}>Mark as a demo site</button>
|
||||
</form>
|
||||
) : (
|
||||
<>
|
||||
@@ -164,7 +186,7 @@ export default function DeploymentPage() {
|
||||
</select>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="d-c">Type {x.shortName}</label><input id="d-c" className="input" value={demo.confirm} onChange={e => setDemo({ ...demo, confirm: e.target.value })} /></div>
|
||||
<button className="btn-danger" disabled={demo.confirm !== x.shortName}>Load demo data</button>
|
||||
<button className="btn-danger" disabled={demo.confirm !== x.shortName || busy}>Load demo data</button>
|
||||
</form>
|
||||
<button type="button" className="text-sm text-slate-500 underline" onClick={() => act(`/api/admin/deployments/${x.id}/demo`, { isDemo: false }, "No longer a demo site.")}>It isn't a demo site any more</button>
|
||||
</>
|
||||
@@ -180,7 +202,7 @@ export default function DeploymentPage() {
|
||||
<tr key={j.id} className="border-t">
|
||||
<td className="px-5 py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link>{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td>
|
||||
<td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td><td className="max-w-md truncate text-xs text-slate-500">{j.message}</td>
|
||||
<td className="pr-5">{["queued", "scheduled"].includes(j.status) && <button className="btn-secondary px-2 py-1 text-xs" onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
|
||||
<td className="pr-5">{["queued", "scheduled"].includes(j.status) && <button className="btn-secondary px-2 py-1 text-xs" disabled={busy} onClick={() => act(`/api/admin/jobs/${j.id}/cancel`, {}, "Cancelled; the church was told.")}>Cancel</button>}</td>
|
||||
</tr>
|
||||
))}</tbody>
|
||||
</table>
|
||||
@@ -198,7 +220,7 @@ export default function DeploymentPage() {
|
||||
<div className="card border-red-200">
|
||||
<h2 className="font-medium text-red-800">Remove the record</h2>
|
||||
<p className="mt-1 text-sm text-slate-500">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.</p>
|
||||
<button className="btn-danger mt-3" onClick={removeRecord}>Remove the record</button>
|
||||
<button className="btn-danger mt-3" disabled={busy} onClick={removeRecord}>Remove the record</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -209,7 +231,7 @@ export default function DeploymentPage() {
|
||||
<div><label className="label" htmlFor="x-at">When</label><input id="x-at" type="datetime-local" className="input" value={un.at} onChange={e => setUn({ ...un, at: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="x-c">Type {x.shortName}</label><input id="x-c" className="input" required value={un.confirm} onChange={e => setUn({ ...un, confirm: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="x-t">Two-factor code</label><input id="x-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={un.totp} onChange={e => setUn({ ...un, totp: e.target.value })} /></div>
|
||||
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName}>Plan the uninstall</button></div>
|
||||
<div className="md:col-span-3"><button className="btn-danger" disabled={un.confirm !== x.shortName || busy}>Plan the uninstall</button></div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -32,6 +32,8 @@ export default function UpdatesPage() {
|
||||
const [chosen, setChosen] = useState<string[]>([]);
|
||||
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" });
|
||||
const [msg, setMsg] = useState<Msg>(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<void> => {
|
||||
e?.preventDefault();
|
||||
if (busy && !confirmLive) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await send(confirmLive);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const send = async (confirmLive: boolean): Promise<void> => {
|
||||
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() {
|
||||
<div><label className="label" htmlFor="b-t">Two-factor code</label><input id="b-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={form.totp} onChange={e => setForm({ ...form, totp: e.target.value })} /></div>
|
||||
</>}
|
||||
</div>
|
||||
<button className="btn-primary" disabled={!chosen.length}>{form.emergency && form.asap ? `Update ${chosen.length} ${name} install(s) now` : `Plan the ${name} update for ${chosen.length} install(s)`}</button>
|
||||
<button className="btn-primary" disabled={!chosen.length || busy} aria-busy={busy}>{busy ? "Working…" : form.emergency && form.asap ? `Update ${chosen.length} ${name} install(s) now` : `Plan the ${name} update for ${chosen.length} install(s)`}</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user