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

[NEW] Add mention-here permission #7631 #9228

Merged
merged 2 commits into from
Jan 15, 2018
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.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Meteor.startup(function() {
{ _id: 'manage-own-integrations', roles : ['admin', 'bot'] },
{ _id: 'manage-oauth-apps', roles : ['admin'] },
{ _id: 'mention-all', roles : ['admin', 'owner', 'moderator', 'user'] },
{ _id: 'mention-here', roles : ['admin', 'owner', 'moderator', 'user'] },
{ _id: 'mute-user', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'remove-user', roles : ['admin', 'owner', 'moderator'] },
{ _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 @@ -166,6 +166,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/deleteUserOwnAccount.js', 'server');
api.addFiles('server/methods/filterBadWords.js', ['server']);
api.addFiles('server/methods/filterATAllTag.js', 'server');
api.addFiles('server/methods/filterATHereTag.js', 'server');
api.addFiles('server/methods/getChannelHistory.js', 'server');
api.addFiles('server/methods/getFullUserData.js', 'server');
api.addFiles('server/methods/getRoomJoinCode.js', 'server');
Expand Down
34 changes: 34 additions & 0 deletions packages/rocketchat-lib/server/methods/filterATHereTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import _ from 'underscore';

RocketChat.callbacks.add('beforeSaveMessage', function(message) {
// Test if the message mentions include @here.
if (message.mentions != null &&
_.pluck(message.mentions, '_id').some((item) => item === 'here')) {

// Check if the user has permissions to use @here in both global and room scopes.
if (!RocketChat.authz.hasPermission(message.u._id, 'mention-here') && !RocketChat.authz.hasPermission(message.u._id, 'mention-here', message.rid)) {

// Get the language of the user for the error notification.
const language = RocketChat.models.Users.findOneById(message.u._id).language;
const action = TAPi18n.__('Notify_active_in_this_room', {}, language);

// Add a notification to the chat, informing the user that this
// action is not allowed.
RocketChat.Notifications.notifyUser(message.u._id, '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 here in this room not allowed', {
method: 'filterATHereTag',
action: 'Notify_active_in_this_room'
});
}
}

return message;

}, 1, 'filterATHereTag');