mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Board import no longer asks for member mapping up front. Every imported member is
brought in as a virtual (placeholder) user carrying its avatar, username and full
name (the existing createPlaceholderUsers path), added to the board inactive with
no permissions. The client import flow is now a single step that imports
immediately with an empty mapping -- no map-members screen, nothing to get stuck
on.
Mapping a virtual member to an existing user is a deliberate, later action done by
a board admin from the board sidebar member-avatar popup ("Map to existing user"),
and CANNOT be used to gain privileges: the new board-scoped method
mapImportedBoardMember only maps a virtual member onto an existing ACTIVE, REAL
member of the SAME board and never changes that member's role (so no new
membership is created and nothing is escalated); authorization and this guarantee
live in the pure planBoardMemberMapping helper. The mapping reassigns the virtual
member's cards/comments/activities ON THAT BOARD to the target and removes the
placeholder from the board.
Automatic hang mitigation so an import can never spin forever: a client watchdog
surfaces an import-timeout and clears the spinner if importBoard does not answer in
WEKAN_IMPORT_TIMEOUT_MS (default 2 min), and the server bounds creator.create with
the same deadline via a new generic withDeadline() wrapper.
Covered by tests/boardMemberMapPlan.test.cjs (no-escalation + auth matrix),
tests/withDeadline.test.cjs (deadline wrapper) and tests/importVirtualMembers.test.cjs
(wiring).
Thanks to xet7 !
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
// Bound a promise so a hung or stalled operation can never block forever. Resolves
|
|
// with the promise's value if it settles within `ms`; otherwise rejects with a timeout
|
|
// error (from `onTimeout()` if given, else a generic Error). The underlying promise is
|
|
// not cancelled — JavaScript cannot cancel a promise — but the caller is freed, so a
|
|
// method/handler returns an error to the client instead of spinning indefinitely.
|
|
//
|
|
// Pure and dependency-free so it can be unit-tested and reused anywhere a long
|
|
// operation needs a hard deadline (imports, migrations, external fetches, …).
|
|
//
|
|
// Usage:
|
|
// await withDeadline(doWork(), 120000, () => new Meteor.Error('op-timeout'));
|
|
|
|
function withDeadline(promise, ms, onTimeout) {
|
|
// A non-positive / invalid deadline means "no deadline": just await the promise.
|
|
if (!(ms > 0)) {
|
|
return Promise.resolve(promise);
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
let done = false;
|
|
|
|
const timer = setTimeout(() => {
|
|
if (done) return;
|
|
done = true;
|
|
const err =
|
|
typeof onTimeout === 'function' ? onTimeout() : new Error('operation-timeout');
|
|
reject(err);
|
|
}, ms);
|
|
|
|
// Do not keep the process alive just for this timer (Node only; harmless elsewhere).
|
|
if (timer && typeof timer.unref === 'function') {
|
|
timer.unref();
|
|
}
|
|
|
|
Promise.resolve(promise).then(
|
|
value => {
|
|
if (done) return;
|
|
done = true;
|
|
clearTimeout(timer);
|
|
resolve(value);
|
|
},
|
|
error => {
|
|
if (done) return;
|
|
done = true;
|
|
clearTimeout(timer);
|
|
reject(error);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
module.exports = { withDeadline };
|