Merge pull request #9584 from kb0304/bugfix-7268

[NEW] Add leave public channel & leave private channel permissions
pull/10221/head^2
Rodrigo Nascimento 8 years ago committed by GitHub
commit 46366fa72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/rocketchat-authorization/server/startup.js
  2. 2
      packages/rocketchat-i18n/i18n/en.i18n.json
  3. 2
      packages/rocketchat-lib/server/methods/leaveRoom.js
  4. 3
      packages/rocketchat-ui-sidenav/client/sidebarItem.js
  5. 11
      server/startup/migrations/v108.js

@ -34,6 +34,8 @@ Meteor.startup(function() {
{ _id: 'edit-room', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'force-delete-message', roles : ['admin', 'owner'] },
{ _id: 'join-without-join-code', roles : ['admin', 'bot'] },
{ _id: 'leave-c', roles : ['admin', 'user', 'bot', 'anonymous'] },
{ _id: 'leave-p', roles : ['admin', 'user', 'bot', 'anonymous'] },
{ _id: 'manage-assets', roles : ['admin'] },
{ _id: 'manage-emoji', roles : ['admin'] },
{ _id: 'manage-integrations', roles : ['admin'] },

@ -1135,6 +1135,8 @@
"Lead_capture_email_regex": "Lead capture email regex",
"Lead_capture_phone_regex": "Lead capture phone regex",
"Least_Amount": "Least Amount",
"leave-c": "Leave Channels",
"leave-p": "Leave Private Groups",
"Leave_Group_Warning": "Are you sure you want to leave the group \"%s\"?",
"Leave_Livechat_Warning": "Are you sure you want to leave the livechat with \"%s\"?",
"Leave_Private_Warning": "Are you sure you want to leave the discussion with \"%s\"?",

@ -12,7 +12,7 @@ Meteor.methods({
const room = RocketChat.models.Rooms.findOneById(rid);
const user = Meteor.user();
if (room.t === 'd') {
if (room.t === 'd' || (room.t === 'c' && !RocketChat.authz.hasPermission(user._id, 'leave-c')) || (room.t === 'p' && !RocketChat.authz.hasPermission(user._id, 'leave-p'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'leaveRoom' });
}

@ -90,6 +90,9 @@ Template.sidebarItem.events({
if (!roomData) { return false; }
if (roomData.t === 'c' && !RocketChat.authz.hasAtLeastOnePermission('leave-c')) { return false; }
if (roomData.t === 'p' && !RocketChat.authz.hasAtLeastOnePermission('leave-p')) { return false; }
return !(((roomData.cl != null) && !roomData.cl) || (['d', 'l'].includes(roomData.t)));
};

@ -0,0 +1,11 @@
RocketChat.Migrations.add({
version: 107,
up() {
const roles = RocketChat.models.Roles.find({
_id: { $ne: 'guest' },
scope: 'Users'
}).fetch().map((role)=>{ return role._id; });
RocketChat.models.Permissions.createOrUpdate('leave-c', roles);
RocketChat.models.Permissions.createOrUpdate('leave-d', roles);
}
});
Loading…
Cancel
Save