[NEW] Button to remove closed LiveChat rooms (#10301)
* New button added to current chat list, allowing to remove closed livechat rooms.pull/10388/head
parent
bcbb97bf02
commit
7689f2e9ba
@ -0,0 +1,31 @@ |
||||
Meteor.methods({ |
||||
'livechat:removeRoom'(rid) { |
||||
if (!Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'remove-closed-livechat-rooms')) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeRoom' }); |
||||
} |
||||
|
||||
const room = RocketChat.models.Rooms.findOneById(rid); |
||||
|
||||
if (!room) { |
||||
throw new Meteor.Error('error-invalid-room', 'Invalid room', { |
||||
method: 'livechat:removeRoom' |
||||
}); |
||||
} |
||||
|
||||
if (room.t !== 'l') { |
||||
throw new Meteor.Error('error-this-is-not-a-livechat-room', 'This is not a Livechat room', { |
||||
method: 'livechat:removeRoom' |
||||
}); |
||||
} |
||||
|
||||
if (room.open) { |
||||
throw new Meteor.Error('error-room-is-not-closed', 'Room is not closed', { |
||||
method: 'livechat:removeRoom' |
||||
}); |
||||
} |
||||
|
||||
RocketChat.models.Messages.removeByRoomId(rid); |
||||
RocketChat.models.Subscriptions.removeByRoomId(rid); |
||||
return RocketChat.models.Rooms.removeById(rid); |
||||
} |
||||
}); |
||||
@ -0,0 +1,20 @@ |
||||
RocketChat.Migrations.add({ |
||||
version: 127, |
||||
up() { |
||||
if (RocketChat.models && RocketChat.models.Permissions) { |
||||
|
||||
const newPermission = RocketChat.models.Permissions.findOne('view-livechat-manager'); |
||||
if (newPermission && newPermission.roles.length) { |
||||
RocketChat.models.Permissions.upsert({ _id: 'remove-closed-livechat-rooms' }, { $set: { roles: newPermission.roles } }); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
down() { |
||||
if (RocketChat.models && RocketChat.models.Permissions) { |
||||
|
||||
// Revert permission
|
||||
RocketChat.models.Permissions.remove({ _id: 'remove-closed-livechat-rooms' }); |
||||
} |
||||
} |
||||
}); |
||||
Loading…
Reference in new issue