Files
wekan/client/lib/historyKeyRecovery.js
T
Lauri Ojansivu 9ad9813c09 Let a board admin resolve a Scrum undo or redo that stopped on a conflict.
A Scrum History undo, redo or restore keeps a checkpoint that blocks every
Scrum edit on its board until it finishes, and only its author could retry
it, with the same plan. When somebody else had changed one of its records,
its History row changed or its author lost write access, every retry failed
the same way, the checkpoint could not be discarded online or offline, and
the board's Scrum edits stayed blocked for good.

A retry that fails for a reason the next one would meet again now marks its
checkpoint. A board administrator sees such a checkpoint in the History
recovery notice and can roll it back, which restores every record it wrote
to the saved "before" value and revision and is offered only when nobody
changed those records since and none of its History was written, or keep the
board as it is, which removes the checkpoint and writes nothing while
reporting how much of the operation had been written. A checkpoint that has
not stopped on a conflict stays its author's to retry. The resolution names
the checkpoint it resolves, so a repeat is a no-op; it claims the checkpoint
by compare-and-set, fencing the author's workers, waits for an in-flight
write, and checks every record before and after its own writes. Each one is
recorded in Admin Panel / Problems / Recovery. The offline command
releases/recover-scrum-history.cjs does the same with every writer stopped.

Unit, integration (against MongoDB 7), Meteor and Playwright tests cover
rollback, discard, refusals, concurrency and the offline command. New text
is in English, pending Transifex.

Thanks to xet7 !
2026-10-08 12:06:49 +03:00

56 lines
2.6 KiB
JavaScript

// The visible half of keyboard undo/redo recovery (client/lib/historyKeyRequest.js).
// An undo or redo whose reply never came stays in sessionStorage and is
// retried by the next keystroke - but nothing on screen said so, so the person
// could not tell that their Ctrl+Z was still waiting. The notice
// (historyRecoveryNotice) shows while the current board has such a request,
// with "Try again", which repeats the SAME request ID and so cannot undo a
// second change, and "Forget it", which drops the request.
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { readStoredRequest, writeStoredRequest } from '/client/lib/historyKeyRequest';
export const pendingHistoryRequest = new ReactiveVar(null);
const memory = { value: null, getItem() { return this.value; }, setItem(k, v) { this.value = v; }, removeItem() { this.value = null; } };
export function historyRequestStorage() {
try { return window.sessionStorage || memory; } catch (e) { return memory; }
}
export function refreshPendingHistoryRequest(storage = historyRequestStorage()) {
pendingHistoryRequest.set(readStoredRequest(storage));
}
export function forgetPendingHistoryRequest(storage = historyRequestStorage()) {
writeStoredRequest(storage, null);
refreshPendingHistoryRequest(storage);
}
// A Scrum History undo or redo that stopped on a conflict keeps a checkpoint
// on the server that blocks every Scrum edit on its board, and retrying it
// fails the same way each time (server/lib/scrumHistoryRecovery.js). The
// notice shows it to anyone who can write on the board, and to a board
// administrator the two ways out: roll back, or keep the board as it is.
export const scrumHistoryCheckpoint = new ReactiveVar(null);
const callServer = (...args) => Meteor.callAsync(...args);
export async function refreshScrumHistoryCheckpoint(boardId, call = callServer) {
let report = null;
if (boardId) {
try { report = await call('scrum.inspectHistoryCheckpoint', boardId); } catch (e) { report = null; }
}
const shown = report && report.present && report.stuck ? { ...report, boardId } : null;
scrumHistoryCheckpoint.set(shown);
return shown;
}
// Resolve the checkpoint the notice showed, by its key: one already resolved
// (by another administrator or server) is a no-op on the server, never
// another checkpoint.
export async function resolveScrumHistoryCheckpoint(checkpoint, action, call = callServer) {
try {
return await call('scrum.resolveHistoryCheckpoint', checkpoint.boardId, checkpoint.key, action);
} finally {
await refreshScrumHistoryCheckpoint(checkpoint.boardId, call);
}
}