mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Fix import/clone of inconsistent board JSON so the newest WeKan can import board exports from any newer or older WeKan version. A syntactically valid export can still be internally inconsistent (a board member whose user account was deleted is no longer in the export's `users`, cards pointing at a missing `listId`, orphaned checklists, or a missing `lists` array). Such exports previously failed import as "error-json-malformed" or silently dropped data (cards with an undefined list never rendered). The importer now skips dangling user references in the member mapper (client `wekanMembersMapper`, server `wekanmapper` used by board cloning, and `WekanCreator`), falls back to the first imported list — creating one default list when the export has none — for cards with a dangling `listId`, and skips orphaned checklists whose card is missing. The importer remains version-agnostic: it never reads `_format`, normalizes old `id` vs `_id` fields, and ignores the source `boardId`. Added `tests/wekanCreator.inconsistent.test.js` covering these cases. Thanks to titver968, xet7 and Claude ! Fixes #6371
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
export async function getMembersToMap(data) {
|
|
// we will work on the list itself (an ordered array of objects) when a
|
|
// mapping is done, we add a 'wekan' field to the object representing the
|
|
// imported member
|
|
const membersToMap = data.members || [];
|
|
const users = data.users || [];
|
|
// auto-map based on username
|
|
const mappable = [];
|
|
for (const importedMember of membersToMap) {
|
|
importedMember.id = importedMember.userId;
|
|
delete importedMember.userId;
|
|
const user = users.filter(user => {
|
|
return user._id === importedMember.id;
|
|
})[0];
|
|
// Skip dangling user references (e.g. a board member whose account was
|
|
// deleted): the export only includes users that still exist, so `user`
|
|
// can be undefined. Dereferencing it would throw and abort the clone.
|
|
if (!user) {
|
|
continue;
|
|
}
|
|
if (user.profile && user.profile.fullname) {
|
|
importedMember.fullName = user.profile.fullname;
|
|
}
|
|
importedMember.username = user.username;
|
|
const wekanUser = await ReactiveCache.getUser({ username: importedMember.username });
|
|
if (wekanUser) {
|
|
importedMember.wekanId = wekanUser._id;
|
|
}
|
|
mappable.push(importedMember);
|
|
}
|
|
return mappable;
|
|
}
|