[FIX] Hipchat importer was not importing users without emails and uploaded files (#11910)

pull/11918/head
Rodrigo Nascimento 7 years ago committed by Diego Sampaio
parent 2cd3958100
commit 02bc5ecb2f
No known key found for this signature in database
GPG Key ID: 16752D335AC4C231
  1. 53
      packages/rocketchat-importer-hipchat-enterprise/server/importer.js
  2. 5
      packages/rocketchat-importer/server/classes/ImporterBase.js

@ -51,9 +51,9 @@ export class HipChatEnterpriseImporter extends Base {
if (info.base === 'users.json') {
super.updateProgress(ProgressStep.PREPARING_USERS);
for (const u of file) {
if (!u.User.email) {
continue;
}
// if (!u.User.email) {
// // continue;
// }
tempUsers.push({
id: u.User.id,
email: u.User.email,
@ -91,6 +91,8 @@ export class HipChatEnterpriseImporter extends Base {
receiverId: m.PrivateUserMessage.receiver.id,
text: m.PrivateUserMessage.message.indexOf('/me ') === -1 ? m.PrivateUserMessage.message : `${ m.PrivateUserMessage.message.replace(/\/me /, '_') }_`,
ts: new Date(m.PrivateUserMessage.timestamp.split(' ')[0]),
attachment: m.PrivateUserMessage.attachment,
attachment_path: m.PrivateUserMessage.attachment_path,
});
}
}
@ -272,7 +274,11 @@ export class HipChatEnterpriseImporter extends Base {
}
Meteor.runAsUser(startedByUserId, () => {
let existantUser = RocketChat.models.Users.findOneByEmailAddress(u.email);
let existantUser;
if (u.email) {
RocketChat.models.Users.findOneByEmailAddress(u.email);
}
// If we couldn't find one by their email address, try to find an existing user by their username
if (!existantUser) {
@ -284,7 +290,13 @@ export class HipChatEnterpriseImporter extends Base {
u.rocketId = existantUser._id;
RocketChat.models.Users.update({ _id: u.rocketId }, { $addToSet: { importIds: u.id } });
} else {
const userId = Accounts.createUser({ email: u.email, password: Random.id() });
const user = { email: u.email, password: Random.id() };
if (!user.email) {
delete user.email;
user.username = u.username;
}
const userId = Accounts.createUser(user);
Meteor.runAsUser(userId, () => {
Meteor.call('setUsername', u.username, { joinDefaultChannelsSilenced: true });
// TODO: Use moment timezone to calc the time offset - Meteor.call 'userSetUtcOffset', user.tz_offset / 3600
@ -435,16 +447,27 @@ export class HipChatEnterpriseImporter extends Base {
}
Meteor.runAsUser(sender._id, () => {
RocketChat.sendMessage(sender, {
_id: msg.id,
ts: msg.ts,
msg: msg.text,
rid: room._id,
u: {
_id: sender._id,
username: sender.username,
},
}, room, true);
if (msg.attachment_path) {
const details = {
message_id: msg.id,
name: msg.attachment.name,
size: msg.attachment.size,
userId: sender._id,
rid: room._id,
};
this.uploadFile(details, msg.attachment.url, sender, room, msg.ts);
} else {
RocketChat.sendMessage(sender, {
_id: msg.id,
ts: msg.ts,
msg: msg.text,
rid: room._id,
u: {
_id: sender._id,
username: sender.username,
},
}, room, true);
}
});
}
}

@ -271,6 +271,11 @@ export class Base {
const fileStore = FileUpload.getStore('Uploads');
return requestModule.get(fileUrl, Meteor.bindEnvironment(function(res) {
const contentType = res.headers['content-type'];
if (!details.type && contentType) {
details.type = contentType;
}
const rawData = [];
res.on('data', (chunk) => rawData.push(chunk));
res.on('end', Meteor.bindEnvironment(() => {

Loading…
Cancel
Save