Skip to content

Commit

Permalink
[FIX] Hipchat importer was not importing users without emails and upl…
Browse files Browse the repository at this point in the history
…oaded files (#11910)
  • Loading branch information
rodrigok authored and sampaiodiego committed Aug 31, 2018
1 parent 2cd3958 commit 02bc5ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
53 changes: 38 additions & 15 deletions packages/rocketchat-importer-hipchat-enterprise/server/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-importer/server/classes/ImporterBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 02bc5ec

Please sign in to comment.