[NEW] REST endpoint to forward livechat rooms (#13308)

* Add new rest endpoint allowing agents/managers to forward livechat rooms.
pull/13323/head
Renato Becker 6 years ago committed by Diego Sampaio
parent 6fb5b00c2a
commit bb9b51e633
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 6
      packages/rocketchat-livechat/server/api/v1/room.js
  2. 7
      packages/rocketchat-livechat/server/methods/transfer.js

@ -153,3 +153,9 @@ RocketChat.API.v1.addRoute('livechat/room.survey', {
}
},
});
RocketChat.API.v1.addRoute('livechat/room.forward', { authRequired: true }, {
post() {
RocketChat.API.v1.success(Meteor.runAsUser(this.userId, () => Meteor.call('livechat:transfer', this.bodyParams)));
},
});

@ -16,14 +16,17 @@ Meteor.methods({
});
const room = RocketChat.models.Rooms.findOneById(transferData.roomId);
const guest = LivechatVisitors.findOneById(room.v._id);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:transfer' });
}
const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, Meteor.userId(), { fields: { _id: 1 } });
if (!subscription && !RocketChat.authz.hasRole(Meteor.userId(), 'livechat-manager')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:transfer' });
}
const guest = LivechatVisitors.findOneById(room.v && room.v._id);
return RocketChat.Livechat.transfer(room, guest, transferData);
},
});

Loading…
Cancel
Save