Make the admin users admins inside of Rocket.Chat

pull/8966/head
Bradley Hilton 8 years ago
parent 4eab9160be
commit df9901ee67
No known key found for this signature in database
GPG Key ID: 0666B2C24C43C358
  1. 12
      packages/rocketchat-importer-slack-users/server/importer.js

@ -11,7 +11,7 @@ export class SlackUsersImporter extends Base {
this.csvParser = Npm.require('csv-parse/lib/sync'); this.csvParser = Npm.require('csv-parse/lib/sync');
this.userMap = new Map(); this.userMap = new Map();
this.admins = []; //Array of usernames of the admins this.admins = []; //Array of ids of the users which are admins
} }
prepare(dataURI, sentContentType, fileName) { prepare(dataURI, sentContentType, fileName) {
@ -36,7 +36,7 @@ export class SlackUsersImporter extends Base {
switch (user[2]) { switch (user[2]) {
case 'Admin': case 'Admin':
this.admins.push(username); this.admins.push(id);
break; break;
case 'Bot': case 'Bot':
isBot = true; isBot = true;
@ -90,6 +90,7 @@ export class SlackUsersImporter extends Base {
Meteor.runAsUser(startedByUserId, () => { Meteor.runAsUser(startedByUserId, () => {
const existantUser = RocketChat.models.Users.findOneByEmailAddress(u.email) || RocketChat.models.Users.findOneByUsername(u.username); const existantUser = RocketChat.models.Users.findOneByEmailAddress(u.email) || RocketChat.models.Users.findOneByUsername(u.username);
let userId = existantUser._id;
if (existantUser) { if (existantUser) {
//since we have an existing user, let's try a few things //since we have an existing user, let's try a few things
u.rocketId = existantUser._id; u.rocketId = existantUser._id;
@ -98,7 +99,8 @@ export class SlackUsersImporter extends Base {
RocketChat.models.Users.setEmail(existantUser._id, u.email); RocketChat.models.Users.setEmail(existantUser._id, u.email);
RocketChat.models.Users.setEmailVerified(existantUser._id, u.email); RocketChat.models.Users.setEmailVerified(existantUser._id, u.email);
} else { } else {
const userId = Accounts.createUser({ username: u.username + Random.id(), password: Date.now() + u.name + u.email.toUpperCase() }); userId = Accounts.createUser({ username: u.username + Random.id(), password: Date.now() + u.name + u.email.toUpperCase() });
if (!userId) { if (!userId) {
console.warn('An error happened while creating a user.'); console.warn('An error happened while creating a user.');
return; return;
@ -114,6 +116,10 @@ export class SlackUsersImporter extends Base {
}); });
} }
if (this.admins.includes(u.user_id)) {
Meteor.call('setAdminStatus', userId, true);
}
super.addCountCompleted(1); super.addCountCompleted(1);
}); });
} }

Loading…
Cancel
Save