Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter to allow/deny @all #3703

Merged
merged 7 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/server/startup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Meteor.startup ->
{ _id: 'manage-integrations', roles : ['admin'] }
{ _id: 'manage-own-integrations', roles : ['bot'] }
{ _id: 'manage-oauth-apps', roles : ['admin'] }
{ _id: 'mention-all', roles : ['admin', 'moderator', 'owner', 'user'] }
{ _id: 'mute-user', roles : ['admin', 'moderator', 'owner'] }
{ _id: 'remove-user', roles : ['admin', 'moderator', 'owner'] }
{ _id: 'run-import', roles : ['admin'] }
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/setEmail.js', 'server');
api.addFiles('server/methods/restartServer.coffee', 'server');
api.addFiles('server/methods/filterBadWords.js', ['server']);
api.addFiles('server/methods/filterATAllTag.js', 'server');

// SERVER STARTUP
api.addFiles('server/startup/settingsOnLoadCdnPrefix.coffee', 'server');
Expand Down
38 changes: 38 additions & 0 deletions packages/rocketchat-lib/server/methods/filterATAllTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
RocketChat.callbacks.add('beforeSaveMessage', function(message) {

// Test if the message mentions include @all.
if (message.mentions != null &&
_.pluck(message.mentions, '_id').some((item) => item === 'all')) {

// Check if the user has permissions to use @all.
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'mention-all')) {

// Get the language of the user for the error notification.
let language = Meteor.user().language;
let action = TAPi18n.__('Notify_all_in_this_room', {}, language);

// Add a notification to the chat, informing the user that this
// action is not allowed.
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: message.rid,
ts: new Date,
msg: TAPi18n.__('error-action-not-allowed', { action }, language)
});

// Also throw to stop propagation of 'sendMessage'.
throw new Meteor.Error(
'error-action-not-allowed',
'Notify all in this room not allowed',
{
method: 'filterATAllTag',
action: 'Notify_all_in_this_room'
}
);
}
}

return message;

}, 1);