-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Room Roles * Replace arunoda:streams by rocketchat:streamer * Getting user roles * Add stream notifications for adding/removing user and room roles * Fix event broadcast * Update version of rocketchat:streamer to 0.2.0 * Call subscribe after adding user to role * Update rocketchat:streamer to version 0.3.0 * Notify broadcast * Notify and broadcast as default * Update rocketchat:streamer to version 0.3.1 * Update rocketchat:streamer to 0.3.2 * Improve broadcast auth * Fix LiveChat Streamer
- Loading branch information
1 parent
43efe6d
commit 4d89802
Showing
32 changed files
with
233 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* globals UserRoles, RoomRoles */ | ||
|
||
Meteor.startup(function() { | ||
Tracker.autorun(function() { | ||
if (Meteor.userId()) { | ||
Meteor.call('getUserRoles', (error, results) => { | ||
if (error) { | ||
return toastr.error(TAPi18n.__(error.error)); | ||
} | ||
|
||
for (let record of results) { | ||
UserRoles.upsert({ _id: record._id }, record); | ||
} | ||
}); | ||
|
||
RocketChat.Notifications.onAll('roles-change', function(role) { | ||
if (role.type === 'added') { | ||
if (role.scope) { | ||
RoomRoles.upsert({ rid: role.scope, 'u._id': role.u._id }, { $setOnInsert: { u: role.u }, $addToSet: { roles: role._id } }); | ||
} else { | ||
UserRoles.upsert({ _id: role.u._id }, { $addToSet: { roles: role._id }, $set: { username: role.u.username } }); | ||
ChatMessage.update({ 'u._id': role.u._id }, { $addToSet: { roles: role._id } }, { multi: true }); | ||
} | ||
} else if (role.type === 'removed') { | ||
if (role.scope) { | ||
RoomRoles.update({ rid: role.scope, 'u._id': role.u._id }, { $pull: { roles: role._id } }); | ||
} else { | ||
UserRoles.update({ _id: role.u._id }, { $pull: { roles: role._id } }); | ||
ChatMessage.update({ 'u._id': role.u._id }, { $pull: { roles: role._id } }, { multi: true }); | ||
} | ||
} else if (role.type === 'changed') { | ||
ChatMessage.update({ roles: role._id }, { $inc: { rerender: 1 } }, { multi: true }); | ||
} | ||
}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Meteor.methods({ | ||
getRoomRoles(rid) { | ||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomRoles' }); | ||
} | ||
|
||
check(rid, String); | ||
|
||
const options = { | ||
sort: { | ||
'u.username': 1 | ||
}, | ||
fields: { | ||
rid: 1, | ||
u: 1, | ||
roles: 1 | ||
} | ||
}; | ||
|
||
const roles = RocketChat.models.Roles.find({ scope: 'Subscriptions', description: { $exists: 1, $ne: '' } }).fetch(); | ||
return RocketChat.models.Subscriptions.findByRoomIdAndRoles(rid, _.pluck(roles, '_id'), options).fetch(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Meteor.methods({ | ||
getUserRoles() { | ||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getUserRoles' }); | ||
} | ||
|
||
const options = { | ||
sort: { | ||
'username': 1 | ||
}, | ||
fields: { | ||
username: 1, | ||
roles: 1 | ||
} | ||
}; | ||
|
||
const roles = RocketChat.models.Roles.find({ scope: 'Users', description: { $exists: 1, $ne: '' } }).fetch(); | ||
const roleIds = _.pluck(roles, '_id'); | ||
|
||
// Security issue: we should not send all user's roles to all clients, only the 'public' roles | ||
// We must remove all roles that are not part of the query from the returned users | ||
let users = RocketChat.models.Users.findUsersInRoles(roleIds, null, options).fetch(); | ||
for (let user of users) { | ||
user.roles = _.intersection(user.roles, roleIds); | ||
} | ||
return users; | ||
} | ||
}); |
Oops, something went wrong.