Skip to content

Commit

Permalink
Hide livechat users and rooms from the admin pages (#2820)
Browse files Browse the repository at this point in the history
* New field 'type' for users

* Show only default room types on Admin > Rooms

* Rename migration 40 to 41
  • Loading branch information
sampaiodiego authored and engelgabriel committed Apr 8, 2016
1 parent 6b79286 commit 3fa0644
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/rocketchat-lib/server/models/Users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
@tryEnsureIndex { 'status': 1 }
@tryEnsureIndex { 'active': 1 }, { sparse: 1 }
@tryEnsureIndex { 'statusConnection': 1 }, { sparse: 1 }
@tryEnsureIndex { 'type': 1 }


# FIND ONE
Expand Down Expand Up @@ -111,6 +112,9 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
{username: nameOrUsername}
]

type:
$in: ['user']

return @find query, options

findByUsernameNameOrEmailAddress: (usernameNameOrEmailAddress, options) ->
Expand All @@ -120,6 +124,8 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
{username: usernameNameOrEmailAddress}
{'emails.address': usernameNameOrEmailAddress}
]
type:
$in: ['user', 'bot']

return @find query, options

Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-livechat/server/methods/registerGuest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Meteor.methods({
userData = {
username: user,
globalRoles: ['livechat-guest'],
department: department
department: department,
type: 'visitor'
};

userData.userAgent = this.connection.httpHeaders['user-agent'];
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-ui-admin/admin/rooms/adminRooms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Template.adminRooms.onCreated ->
@autorun ->
filter = instance.filter.get()
types = instance.types.get()

if types.length is 0
types = ['c', 'd', 'p']

limit = instance.limit.get()
subscription = instance.subscribe 'adminRooms', filter, types, limit
instance.ready.set subscription.ready()
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-ui-admin/admin/users/adminUsers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Template.adminUsers.onCreated ->
else
query = {}

query.type =
$in: ['user', 'bot']

return Meteor.users.find(query, { limit: instance.limit?.get(), sort: { username: 1, name: 1 } }).fetch()

Template.adminUsers.onRendered ->
Expand Down
2 changes: 2 additions & 0 deletions server/lib/accounts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc, options,

delete user.globalRoles

user.type ?= 'user'

_id = insertUserDoc.call(Accounts, options, user)

if roles.length is 0
Expand Down
1 change: 1 addition & 0 deletions server/publications/fullUserData.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Meteor.publish 'fullUserData', (filter, limit) ->
username: 1
status: 1
utcOffset: 1
type: 1

if RocketChat.authz.hasPermission( @userId, 'view-full-other-user-info') is true
fields = _.extend fields,
Expand Down
2 changes: 1 addition & 1 deletion server/startup/initialData.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Meteor.startup ->
statusDefault: "online"
utcOffset: 0
active: true
bot: true
type: 'bot'

rs = RocketChatFile.bufferToStream new Buffer(Assets.getBinary('avatars/rocketcat.png'), 'utf8')
RocketChatFileAvatarInstance.deleteFile "rocket.cat.jpg"
Expand Down
10 changes: 10 additions & 0 deletions server/startup/migrations/v41.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RocketChat.Migrations.add({
version: 41,
up: function() {
if (RocketChat && RocketChat.models && RocketChat.models.Users) {
RocketChat.models.Users.update({ bot: true }, { $set: { type: 'bot' } }, { multi: true });
RocketChat.models.Users.update({ 'profile.guest': true }, { $set: { type: 'visitor' } }, { multi: true });
RocketChat.models.Users.update({ type: { $exists: false } }, { $set: { type: 'user' } }, { multi: true });
}
}
});

0 comments on commit 3fa0644

Please sign in to comment.