mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -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
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
export function wekanGetMembersToMap(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 = [];
|
|
membersToMap.forEach(importedMember => {
|
|
importedMember.id = importedMember.userId;
|
|
delete importedMember.userId;
|
|
const user = users.filter(user => {
|
|
return user._id === importedMember.id;
|
|
})[0];
|
|
// The exported `users` array only contains users that still exist in the
|
|
// source instance, so a member whose account was deleted (or any other
|
|
// dangling user reference, e.g. from an older export) has no matching
|
|
// user. Skip it instead of dereferencing `undefined`, which would throw
|
|
// and make the whole import fail as "error-json-malformed".
|
|
if (!user) {
|
|
return;
|
|
}
|
|
if (user.profile && user.profile.fullname) {
|
|
importedMember.fullName = user.profile.fullname;
|
|
}
|
|
importedMember.username = user.username;
|
|
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
|
|
if (wekanUser) {
|
|
importedMember.wekanId = wekanUser._id;
|
|
}
|
|
mappable.push(importedMember);
|
|
});
|
|
return mappable;
|
|
}
|