mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Regression from c0a1a2784 (v10.12): it dropped `importMapMembers` from the import
wizard's `steps` array and hardcoded an empty membersMapping in finishImport, so the
map-users screen never rendered and every imported card/member/comment was assigned
to the importing user even when the person existed in WeKan.
Client (client/components/import/import.js):
- restore `steps = ['importTextarea', 'importMapMembers']` so the (auto-suggesting)
map-members step shows again;
- finishImport builds membersMapping from the members the user mapped
(member.wekanId), instead of sending `{}`. The step stays OPTIONAL — the Skip
button and the textarea "import without mapping" button still bypass it.
Server — unmapped members become virtual users instead of collapsing onto the importer:
- models/trelloCreator.js: new createPlaceholderUsers(board), run in create() before
the board is built, so it covers BOTH the Trello JSON import and the Trello API
(all-boards background) import. For each member not already mapped it maps to an
existing WeKan user by username / recorded importUsername, else inserts an inert
virtual user (loginDisabled, isActive:false, authenticationMethod:'imported')
reusing the Trello member id, so board membership and authorship keep the original
person;
- models/wekanCreator.js: createPlaceholderUsers no longer overwrites an explicit UI
mapping (skip members already in this.members) so a member mapped to a real account
is not clobbered by the identity placeholder.
A board admin can still map a virtual member to a real user later from the sidebar
(that feature is unchanged). Tests updated: tests/importVirtualMembers.test.cjs and
tests/importMemberMapping.test.cjs.
Thanks to AmigaAbattoir and xet7 !
Fixes #6506,
65 lines
3.3 KiB
JavaScript
65 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
// Guards for the JSON/board import "Assign members" (map members) step.
|
|
//
|
|
// A user reported (board migration from an old WeKan): in the "Select member" popup,
|
|
// typed suggestions appear but cannot be selected — neither clicking nor Enter assigns
|
|
// the user. Root cause: the click handler mapped `Template.currentData().__originalId`,
|
|
// a field that is NEVER set on the search results (they are plain WeKan user docs with
|
|
// `_id`), so it mapped `undefined` and silently did nothing. Fixed to map `._id`, plus
|
|
// Enter now selects the first result. Member mapping stays OPTIONAL: both a step-1
|
|
// "import without mapping" and an in-step "skip mapping" button import immediately.
|
|
//
|
|
// Run: node tests/importMemberMapping.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
|
|
console.log('importMemberMapping:');
|
|
|
|
const js = read('client/components/import/import.js');
|
|
const jade = read('client/components/import/import.jade');
|
|
|
|
test('selecting a searched user maps its _id (not the never-set __originalId)', () => {
|
|
assert.ok(!/\.__originalId\b/.test(js), 'the bogus .__originalId property access must be gone');
|
|
// The click handler maps the clicked user document by _id.
|
|
const clickIdx = js.indexOf("'click .js-select-import'");
|
|
assert.ok(clickIdx > -1, 'the select-import click handler exists');
|
|
const clickBlock = js.slice(clickIdx, clickIdx + 600);
|
|
assert.ok(/mapSelectedMember|importMapToUser/.test(clickBlock), 'the click maps the selected member');
|
|
assert.ok(/Template\.currentData\(\)\._id/.test(js), 'maps the search result by its _id');
|
|
});
|
|
|
|
test('Enter selects the first search result (keyboard, no mouse needed)', () => {
|
|
assert.ok(/'keydown \.js-search-member-input'/.test(js), 'a keydown handler exists on the search input');
|
|
const kd = js.slice(js.indexOf("'keydown .js-search-member-input'"));
|
|
assert.ok(/keyCode === 13/.test(kd), 'Enter (13) is handled');
|
|
assert.ok(/results\[0\]\._id/.test(kd), 'Enter maps the first result by _id');
|
|
});
|
|
|
|
test('the search-result template binds each user by _id', () => {
|
|
assert.ok(/a\.name\.js-select-import\(title=.*data-id="\{\{_id\}\}"/.test(jade),
|
|
'each search result carries its user _id');
|
|
});
|
|
|
|
test('member mapping is OPTIONAL: skip buttons import immediately', () => {
|
|
// Step 1 (textarea): import without mapping at all.
|
|
assert.ok(/js-import-without-mapping/.test(jade), 'step-1 "import without mapping" button exists');
|
|
assert.ok(/'click \.js-import-without-mapping'/.test(js), 'its handler exists');
|
|
assert.ok(/importData\(evt, Session\.get\('importSource'\), true\)/.test(js),
|
|
'import without mapping calls importData with skipMapping=true');
|
|
// Map step: skip remaining mapping and import now.
|
|
assert.ok(/js-import-skip-mapping/.test(jade), 'in-step "skip mapping" button exists');
|
|
assert.ok(/'click \.js-import-skip-mapping'/.test(js), 'its handler exists');
|
|
// Both surfaces use the same clear label.
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
assert.ok(typeof en['import-without-mapping-members'] === 'string', 'label i18n key exists');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|