From b20e8aa04502cda71b8e9ef4edf7aac3b48e058b Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sat, 12 Dec 2015 11:06:17 -0600 Subject: [PATCH 1/2] Fix rocket.cat user messing up the first real user being made admin. --- server/lib/accounts.coffee | 3 ++- server/startup/initialData.coffee | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/lib/accounts.coffee b/server/lib/accounts.coffee index a6d678fcb4a3..ae3f72ac3df2 100644 --- a/server/lib/accounts.coffee +++ b/server/lib/accounts.coffee @@ -75,8 +75,9 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc) -> _id = insertUserDoc.call(Accounts, options, user) # when inserting first user give them admin privileges otherwise make a regular user - firstUser = RocketChat.models.Users.findOne({},{sort:{createdAt:1}}) + firstUser = RocketChat.models.Users.findOne({ _id: { $ne: 'rocket.cat' }}, { sort: { createdAt: 1 }}) roleName = if firstUser?._id is _id then 'admin' else 'user' + console.log "The role for #{_id} is #{roleName}." RocketChat.authz.addUsersToRoles(_id, roleName) RocketChat.callbacks.run 'afterCreateUser', options, user diff --git a/server/startup/initialData.coffee b/server/startup/initialData.coffee index dbfafd86f223..47ba296a93f5 100644 --- a/server/startup/initialData.coffee +++ b/server/startup/initialData.coffee @@ -53,7 +53,7 @@ Meteor.startup -> # Set oldest user as admin, if none exists yet if _.isEmpty( RocketChat.authz.getUsersInRole( 'admin' ).fetch()) # get oldest user - oldestUser = RocketChat.models.Users.findOne({}, { fields: { username: 1 }, sort: {createdAt: 1}}) + oldestUser = RocketChat.models.Users.findOne({ _id: { $ne: 'rocket.cat' }}, { fields: { username: 1 }, sort: {createdAt: 1}}) if oldestUser RocketChat.authz.addUsersToRoles( oldestUser._id, 'admin') console.log "No admins are found. Set #{oldestUser.username} as admin for being the oldest user" From cebb602af652b3667b5d5de0dc17a28494ce35ab Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sat, 12 Dec 2015 11:07:03 -0600 Subject: [PATCH 2/2] Remove the debugging message on account creation. --- server/lib/accounts.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/server/lib/accounts.coffee b/server/lib/accounts.coffee index ae3f72ac3df2..81f619cfeb11 100644 --- a/server/lib/accounts.coffee +++ b/server/lib/accounts.coffee @@ -77,7 +77,6 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc) -> # when inserting first user give them admin privileges otherwise make a regular user firstUser = RocketChat.models.Users.findOne({ _id: { $ne: 'rocket.cat' }}, { sort: { createdAt: 1 }}) roleName = if firstUser?._id is _id then 'admin' else 'user' - console.log "The role for #{_id} is #{roleName}." RocketChat.authz.addUsersToRoles(_id, roleName) RocketChat.callbacks.run 'afterCreateUser', options, user