mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -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 !
98 lines
3.8 KiB
JavaScript
98 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
// Unit tests for the board-scoped virtual->real member mapping planner
|
|
// (models/lib/boardMemberMapPlan.js). This is the security gate for mapping an imported
|
|
// VIRTUAL (placeholder) board member to an existing REAL board user from the sidebar:
|
|
// it must be usable only by a board (or site) admin, only onto an existing ACTIVE real
|
|
// member of the board, and it must NEVER change any role — so it can never escalate.
|
|
//
|
|
// Run: node tests/boardMemberMapPlan.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const { planBoardMemberMapping } = require('../models/lib/boardMemberMapPlan.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
// A board: admin (real), normal member "bob" (real), a virtual placeholder "ph".
|
|
const members = [
|
|
{ userId: 'admin', isAdmin: true, isActive: true },
|
|
{ userId: 'bob', isAdmin: false, isActive: true },
|
|
{ userId: 'ph', isAdmin: false, isActive: false },
|
|
];
|
|
const base = {
|
|
members,
|
|
placeholderId: 'ph',
|
|
targetId: 'bob',
|
|
callerId: 'admin',
|
|
placeholderIsImported: true,
|
|
targetIsImported: false,
|
|
callerIsSiteAdmin: false,
|
|
};
|
|
|
|
console.log('boardMemberMapPlan:');
|
|
|
|
test('board admin maps a virtual member onto an existing active real member', () => {
|
|
const r = planBoardMemberMapping(base);
|
|
assert.strictEqual(r.ok, true);
|
|
// The placeholder entry is removed; every other entry (incl. the target and its role)
|
|
// is left EXACTLY as it was — no escalation.
|
|
assert.deepStrictEqual(r.newMembers, [
|
|
{ userId: 'admin', isAdmin: true, isActive: true },
|
|
{ userId: 'bob', isAdmin: false, isActive: true },
|
|
]);
|
|
const bob = r.newMembers.find(m => m.userId === 'bob');
|
|
assert.strictEqual(bob.isAdmin, false, 'target keeps its own (non-admin) role');
|
|
});
|
|
|
|
test('a non-admin board member cannot map', () => {
|
|
const r = planBoardMemberMapping({ ...base, callerId: 'bob' });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'not-authorized' });
|
|
});
|
|
|
|
test('a site admin who is not a board member may map', () => {
|
|
const r = planBoardMemberMapping({ ...base, callerId: 'someSiteAdmin', callerIsSiteAdmin: true });
|
|
assert.strictEqual(r.ok, true);
|
|
});
|
|
|
|
test('source must be an imported placeholder', () => {
|
|
const r = planBoardMemberMapping({ ...base, placeholderIsImported: false });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'not-a-placeholder' });
|
|
});
|
|
|
|
test('target must be a REAL (non-imported) user', () => {
|
|
const r = planBoardMemberMapping({ ...base, targetIsImported: true });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'target-not-real' });
|
|
});
|
|
|
|
test('target must be an ACTIVE member of this board', () => {
|
|
const inactiveTarget = members.map(m => (m.userId === 'bob' ? { ...m, isActive: false } : m));
|
|
const r = planBoardMemberMapping({ ...base, members: inactiveTarget });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'target-not-board-member' });
|
|
|
|
const r2 = planBoardMemberMapping({ ...base, targetId: 'stranger' });
|
|
assert.deepStrictEqual(r2, { ok: false, error: 'target-not-board-member' });
|
|
});
|
|
|
|
test('placeholder must be a member of this board', () => {
|
|
const r = planBoardMemberMapping({ ...base, placeholderId: 'ghost' });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'placeholder-not-member' });
|
|
});
|
|
|
|
test('placeholder and target must differ', () => {
|
|
const r = planBoardMemberMapping({ ...base, targetId: 'ph' });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'bad-map' });
|
|
});
|
|
|
|
test('an inactive board-admin entry does not authorize', () => {
|
|
const inactiveAdmin = [
|
|
{ userId: 'admin', isAdmin: true, isActive: false },
|
|
{ userId: 'bob', isAdmin: false, isActive: true },
|
|
{ userId: 'ph', isAdmin: false, isActive: false },
|
|
];
|
|
const r = planBoardMemberMapping({ ...base, members: inactiveAdmin });
|
|
assert.deepStrictEqual(r, { ok: false, error: 'not-authorized' });
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|