Skip to content

Commit

Permalink
Improve verification of new user as admin or user
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Mar 24, 2016
1 parent 3662cd3 commit 6157e77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/server/models/Users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
constructor: ->
@model = Meteor.users

@tryEnsureIndex { 'roles': 1 }, { sparse: 1 }


# FIND ONE
findOneById: (_id, options) ->
Expand Down
8 changes: 4 additions & 4 deletions server/lib/accounts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc, options,

if roles.length is 0
# 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 }})
if firstUser?._id is _id
roles.push 'admin'
else
hasAdmin = RocketChat.models.Users.findOne({ roles: 'admin' }, {fields: {_id: 1}})
if hasAdmin?
roles.push 'user'
else
roles.push 'admin'

RocketChat.authz.addUserRoles(_id, roles)

Expand Down

0 comments on commit 6157e77

Please sign in to comment.