Skip to content

Commit

Permalink
[NEW] REST endpoint to forward livechat rooms (RocketChat#13308)
Browse files Browse the repository at this point in the history
* Add new rest endpoint allowing agents/managers to forward livechat rooms.
  • Loading branch information
renatobecker authored and Montel committed Feb 13, 2019
1 parent 71f6eb4 commit fc70afe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/rocketchat-livechat/server/api/v1/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
},
});
7 changes: 5 additions & 2 deletions packages/rocketchat-livechat/server/methods/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});

0 comments on commit fc70afe

Please sign in to comment.