mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A saved List Sync operation whose list was removed, recreated or reconfigured, or whose actor lost full-list write access, could never be replayed. The replay job refused it every minute with only a console line, and because a new Sync of the list resumes the pending operation first, that list could not Sync at all. Such an operation is now marked once, with one Recovery event, and a blocked manual Sync says why. Admin Panel / Problems / Recovery lists these operations with what they applied and their live replayability. An instance administrator can discard one only while the same checks a replay makes still fail. The discard holds the list's Sync lease, records one immutable decision, then removes the saved steps and the operation marker, reading each removal back. It writes no card: changes already applied stay and the rest are never written. A retry or a second administrator only finishes the removal, and a replay that finds a decided discard completes it instead of resuming. The intent stays as evidence and the discard is audited in Recovery. Unit, source-wiring and negative tests cover recording once, refusing non-administrators and replayable operations, and discarding twice; an app test and a Playwright case cover the Recovery page. New interface text is in English, pending Transifex. Thanks to xet7 !
71 lines
3.7 KiB
JavaScript
71 lines
3.7 KiB
JavaScript
// Admin Panel -> Problems -> Recovery: list Sync operations that can no longer
|
|
// be replayed, and an administrator's discard (server/lib/listSyncStuck.js).
|
|
// Instance administrators only, checked before and after every read and write.
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { check, Match } from 'meteor/check';
|
|
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
|
|
import Boards from '/models/boards';
|
|
import { withListSyncLease } from '/server/lib/listSyncLease';
|
|
import { listStuckListSyncOperations, discardStuckListSyncOperation } from '/server/lib/listSyncOperations';
|
|
import { inspectListSyncOperation } from '/server/lib/listSyncApplication';
|
|
import { recordRecoveryAudit } from '/server/lib/recoveryAudit';
|
|
import RecoveryEvents from '/models/recoveryEvents';
|
|
|
|
const ListId = Match.Where(value => typeof value === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(value));
|
|
const OperationId = Match.Where(value => typeof value === 'string' &&
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(value));
|
|
const REFUSALS = ['missing', 'not-stuck', 'replayable', 'invalid'];
|
|
|
|
async function assertAdmin(userId) {
|
|
const user = userId && await Meteor.users.findOneAsync(userId, { fields: { isAdmin: 1, loginDisabled: 1, username: 1 } });
|
|
if (!user?.isAdmin || user.loginDisabled) throw new Meteor.Error('not-authorized');
|
|
return user;
|
|
}
|
|
// Known refusals keep their reason so the page can say why; anything else is
|
|
// reported without its text.
|
|
function translate(error) {
|
|
if (error?.error === 'not-authorized') return error;
|
|
if (REFUSALS.includes(error?.reason) && error.message === `list-sync-stuck-${error.reason}`) {
|
|
return new Meteor.Error(`list-sync-stuck-${error.reason}`);
|
|
}
|
|
if (error?.error === 'sync-busy' || error?.error === 'sync-lease-lost') return new Meteor.Error('list-sync-stuck-busy');
|
|
return new Meteor.Error('list-sync-stuck-failed');
|
|
}
|
|
|
|
Meteor.methods({
|
|
async listSyncStuckOperations() {
|
|
await assertAdmin(this.userId);
|
|
let result;
|
|
try { result = await listStuckListSyncOperations({ inspect: inspectListSyncOperation }); }
|
|
catch (error) { throw translate(error); }
|
|
await assertAdmin(this.userId);
|
|
return result;
|
|
},
|
|
async listSyncStuckDiscard({ listId, operationId }) {
|
|
check(listId, ListId);
|
|
check(operationId, OperationId);
|
|
const admin = await assertAdmin(this.userId);
|
|
let result;
|
|
try {
|
|
// The list lease: the same one a replay and a new run take, so the
|
|
// discard never interleaves with them, on this server or another.
|
|
result = await withListSyncLease(listId, async ({ assertCurrent }) =>
|
|
discardStuckListSyncOperation({ listId, operationId, operator: admin.username || admin._id,
|
|
inspect: inspectListSyncOperation,
|
|
assertCurrent: async () => { await assertCurrent(); await assertAdmin(this.userId); } }));
|
|
} catch (error) { throw translate(error); }
|
|
// One audit row per decision; a retry that only finished the removal adds none.
|
|
if (result.decidedNow) {
|
|
const board = result.boardId ? await Boards.findOneAsync(result.boardId, { fields: { title: 1 } }) : null;
|
|
await recordRecoveryAudit({ type: RecoveryEvents.types.LIST_SYNC_OPERATION_DISCARDED, user: admin,
|
|
connection: this.connection, done: true, deletedData: true, boards: board ? [board] : [],
|
|
detail: `Discarded the saved List Sync operation ${operationId} of list ${listId}; ` +
|
|
`${result.applied} of ${result.total} steps had been applied, the rest were not.` });
|
|
}
|
|
return result;
|
|
},
|
|
});
|
|
|
|
DDPRateLimiter.addRule({ type: 'method', name: 'listSyncStuckOperations', connectionId: () => true }, 10, 10000);
|
|
DDPRateLimiter.addRule({ type: 'method', name: 'listSyncStuckDiscard', connectionId: () => true }, 10, 10000);
|