Skip to content

Commit

Permalink
Merge pull request #836 from RocketChat/admin-not-assigned-first-user
Browse files Browse the repository at this point in the history
Fix issue where the first inserted user is not assigned the 'admin' role
  • Loading branch information
rodrigok committed Sep 19, 2015
2 parents d6b0dca + fe1b88c commit 9ea9ee9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/lib/accounts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc) ->
_id = insertUserDoc(options, user)

# when inserting first user give them admin privileges otherwise make a regular user
roleName = if Meteor.users.findOne() then 'user' else 'admin'
firstUser = Meteor.users.findOne({},{sort:{createdAt:1}})
roleName = if firstUser?._id is _id then 'admin' else 'user'

RocketChat.authz.addUsersToRoles(_id, roleName)
RocketChat.callbacks.run 'afterCreateUser', options, user
Expand Down

0 comments on commit 9ea9ee9

Please sign in to comment.