Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] The first users was not set as admin some times #10878

Merged
merged 1 commit into from
May 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions server/startup/initialData.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import _ from 'underscore';

Meteor.startup(function() {
Meteor.defer(function() {
Meteor.defer(() => RocketChat.models._CacheControl.withValue(false, function() {
if (!RocketChat.models.Rooms.findOneById('GENERAL')) {
RocketChat.models.Rooms.createWithIdTypeAndName('GENERAL', 'c', 'general', {
'default': true
});
}

if (!RocketChat.models.Users.db.findOneById('rocket.cat')) {
if (!RocketChat.models.Users.findOneById('rocket.cat')) {
RocketChat.models.Users.create({
_id: 'rocket.cat',
name: 'Rocket.Cat',
Expand Down Expand Up @@ -143,10 +143,14 @@ Meteor.startup(function() {

if (oldestUser) {
RocketChat.authz.addUserRoles(oldestUser._id, 'admin');
if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') {
RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}
console.log(`No admins are found. Set ${ oldestUser.username } as admin for being the oldest user`);
console.log(`No admins are found. Set ${ oldestUser.username || oldestUser.name } as admin for being the oldest user`);
}
}

if (!_.isEmpty(RocketChat.authz.getUsersInRole('admin').fetch())) {
if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') {
console.log('Setting Setup Wizard to "in_progress" because, at least, one admin was found');
RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}
}

Expand Down Expand Up @@ -177,7 +181,7 @@ Meteor.startup(function() {
console.log((`Username: ${ adminUser.username }`).green);
console.log((`Password: ${ adminUser._id }`).green);

if (RocketChat.models.Users.db.findOneByEmailAddress(adminUser.emails[0].address)) {
if (RocketChat.models.Users.findOneByEmailAddress(adminUser.emails[0].address)) {
throw new Meteor.Error(`Email ${ adminUser.emails[0].address } already exists`, 'Rocket.Chat can\'t run in test mode');
}

Expand All @@ -197,5 +201,5 @@ Meteor.startup(function() {

return RocketChat.addUserToDefaultChannels(adminUser, true);
}
});
}));
});