mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Every import page now asks once what the people named in the file become (models/lib/importMembersMode.js): existing users chosen in the map-members step, placeholder users that keep the original username and name and cannot log in, to be mapped to real users later, or all the person importing. All five creators read the same mapping. The generalized importer, which used to drop people nobody mapped, now makes placeholders for them, as Trello and WeKan imports do, and offers its people for mapping by reading the file with the same parser (importBoard with previewPeople, which creates nothing). Import many boards offers placeholders or the importer. The REST import, the WeKan .zip route and the Trello route take the mode too. A WeKan .zip imported as a new board no longer puts its attachment files inline in memory within a 512 MB budget: the full-board importer streams each from the archive into storage, as the import into an existing board does. Both, and the Trello importer when given a stream, go through one helper (server/lib/importAttachmentStream.js) that holds every imported attachment to the Admin Panel's upload limit and to none when none is set, skipping a file whose stated size is over it and stopping one that grows past it. The import page instructions name Jira's current search (GET /rest/api/3/search/jql with fields=*all, paged by nextPageToken), Todoist's Manage data > Export as CSV and Planner's Export as Excel. Thanks to xet7 !
53 lines
2.2 KiB
JavaScript
53 lines
2.2 KiB
JavaScript
// Placeholder users for the people of an imported file who were not mapped to
|
|
// an existing user (models/lib/importMembersMode.js): one account per person
|
|
// that cannot log in, is inactive and holds no secrets, carrying the original
|
|
// username and name - so the board keeps who did what - and the name in
|
|
// importUsernames, where a board admin maps it to a real user later. The same
|
|
// placeholders Trello and WeKan imports make (#6506), for every source.
|
|
const { Random } = require('meteor/random');
|
|
|
|
async function uniqueUsername(base) {
|
|
const name = String(base || '').trim().replace(/\s+/g, '-').slice(0, 60) || 'imported';
|
|
let candidate = name;
|
|
for (let n = 1; await Meteor.users.findOneAsync({ username: candidate }, { fields: { _id: 1 } }); n += 1) {
|
|
candidate = `${name}-${n}`;
|
|
}
|
|
return candidate;
|
|
}
|
|
|
|
// people: [{ key, name }]; `mapping` is the creator's members mapping, which
|
|
// gets an entry for each placeholder made. Returns the placeholders' ids.
|
|
async function createImportPlaceholders(people, mapping, { source } = {}) {
|
|
const Users = Meteor.users;
|
|
const made = [];
|
|
for (const person of people || []) {
|
|
if (!person || !person.key || mapping[person.key]) continue;
|
|
try {
|
|
const _id = Random.id();
|
|
// .direct bypasses the after.insert hooks (identity sync, the
|
|
// registration/invitation gate) that would reject a non-account.
|
|
await Users.direct.insertAsync({
|
|
_id,
|
|
username: await uniqueUsername(person.name || person.key),
|
|
profile: { fullname: person.name || person.key, initials: String(person.name || person.key).slice(0, 2).toUpperCase() },
|
|
authenticationMethod: 'imported',
|
|
loginDisabled: true,
|
|
isActive: false,
|
|
importUsernames: [person.key],
|
|
importedFrom: source || null,
|
|
importedAt: new Date(),
|
|
createdAt: new Date(),
|
|
services: {},
|
|
});
|
|
mapping[person.key] = _id;
|
|
made.push(_id);
|
|
} catch (e) {
|
|
// Best effort: a person who cannot be made a placeholder stays text.
|
|
if (process.env.DEBUG === 'true') console.warn('import placeholder user:', person.key, e && e.message);
|
|
}
|
|
}
|
|
return made;
|
|
}
|
|
|
|
module.exports = { createImportPlaceholders };
|