[NEW] Button to remove closed LiveChat rooms (#10301)

* New button added to current chat list, allowing to remove closed livechat rooms.
pull/10388/head
Renato Becker 8 years ago committed by Diego Sampaio
parent bcbb97bf02
commit 7689f2e9ba
  1. 2
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 2
      packages/rocketchat-i18n/i18n/pt-BR.i18n.json
  3. 2
      packages/rocketchat-i18n/i18n/pt.i18n.json
  4. 12
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html
  5. 31
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js
  6. 1
      packages/rocketchat-livechat/package.js
  7. 31
      packages/rocketchat-livechat/server/methods/removeRoom.js
  8. 20
      server/startup/migrations/v127.js

@ -1063,7 +1063,9 @@
"error-remove-last-owner": "This is the last owner. Please set a new owner before removing this one.",
"error-role-in-use": "Cannot delete role because it's in use",
"error-role-name-required": "Role name is required",
"error-room-is-not-closed": "Room is not closed",
"error-the-field-is-required": "The field __field__ is required.",
"error-this-is-not-a-livechat-room": "This is not a Livechat room",
"error-too-many-requests": "Error, too many requests. Please slow down. You must wait __seconds__ seconds before trying again.",
"error-user-has-no-roles": "User has no roles",
"error-user-is-not-activated": "User is not activated",

@ -1059,7 +1059,9 @@
"error-remove-last-owner": "Este é o último proprietário. Por favor, defina um novo proprietário antes de remover este.",
"error-role-in-use": "Não é possível remover o papel pois ele está em uso",
"error-role-name-required": "Nome do papel é obrigatório",
"error-room-is-not-closed": "Sala não está fechada",
"error-the-field-is-required": "O campo __field__ é obrigatório.",
"error-this-is-not-a-livechat-room": "Esta não é uma sala de Livechat",
"error-too-many-requests": "Erro, muitas solicitações. Por favor, diminua a velocidade. Você deve esperar __seconds__ segundos antes de tentar novamente.",
"error-user-has-no-roles": "O usuário não possui permissões",
"error-user-is-not-activated": "O usuário não está ativo",

@ -1059,7 +1059,9 @@
"error-remove-last-owner": "Este é o último proprietário. Por favor, defina um novo proprietário antes de remover este.",
"error-role-in-use": "Não é possível remover o papel pois ele está em uso",
"error-role-name-required": "Nome do papel é obrigatório",
"error-room-is-not-closed": "Sala não está fechada",
"error-the-field-is-required": "O campo __field__ é obrigatório.",
"error-this-is-not-a-livechat-room": "Esta não é uma sala de Livechat",
"error-too-many-requests": "Erro, muitas solicitações. Por favor, diminua a velocidade. Você deve esperar __seconds__ segundos antes de tentar novamente.",
"error-user-has-no-roles": "O usuário não possui papéis",
"error-user-is-not-activated": "O usuário não está ativo",

@ -41,7 +41,8 @@
<th width="25%">{{_ "Served_By"}}</th>
<th width="15%">{{_ "Started_At"}}</th>
<th width="15%">{{_ "Last_Message_At"}}</th>
<th width="10%">{{_ "Status"}}</th>
<th width="20%">{{_ "Status"}}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
@ -52,6 +53,15 @@
<td>{{startedAt}}</td>
<td>{{lastMessage}}</td>
<td>{{status}}</td>
{{#requiresPermission 'remove-closed-livechat-rooms'}}
{{#if isClosed}}
<td><a href="#remove" class="remove-livechat-room"><i class="icon-trash"></i></a></td>
{{else}}
<td>&nbsp;</td>
{{/if}}
{{else}}
<td>&nbsp;</td>
{{/requiresPermission}}
</tr>
{{/each}}
</tbody>

@ -21,6 +21,9 @@ Template.livechatCurrentChats.helpers({
},
agents() {
return AgentUsers.find({}, { sort: { name: 1 } });
},
isClosed() {
return !this.open;
}
});
@ -55,6 +58,34 @@ Template.livechatCurrentChats.events({
instance.filter.set(filter);
instance.limit.set(20);
},
'click .remove-livechat-room'(event) {
event.preventDefault();
event.stopPropagation();
modal.open({
title: t('Are_you_sure'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, () => {
Meteor.call('livechat:removeRoom', this._id, function(error/*, result*/) {
if (error) {
return handleError(error);
}
modal.open({
title: t('Deleted'),
text: t('Room_has_been_deleted'),
type: 'success',
timer: 1000,
showConfirmButton: false
});
});
});
}
});

@ -160,6 +160,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/removeDepartment.js', 'server');
api.addFiles('server/methods/removeManager.js', 'server');
api.addFiles('server/methods/removeTrigger.js', 'server');
api.addFiles('server/methods/removeRoom.js', 'server');
api.addFiles('server/methods/saveAppearance.js', 'server');
api.addFiles('server/methods/saveCustomField.js', 'server');
api.addFiles('server/methods/saveDepartment.js', 'server');

@ -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…
Cancel
Save