Skip to content

Commit

Permalink
[FIX] User can't invite or join other Omnichannel rooms (#18852)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatobecker authored Sep 10, 2020
1 parent bb52d5d commit 66b872d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/lib/server/functions/addUserToRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const addUserToRoom = function(rid, user, inviter, silenced) {
throw error;
}

if (room.t === 'c' || room.t === 'p') {
if (room.t === 'c' || room.t === 'p' || room.t === 'l') {
// Add a new event, with an optional inviter
callbacks.run('beforeAddedToRoom', { user, inviter }, room);

Expand Down
6 changes: 5 additions & 1 deletion app/livechat/lib/LivechatRoomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatRoom } from '../../models';
import { settings } from '../../settings';
import { hasPermission } from '../../authorization';
import { openRoom } from '../../ui-utils';
import { RoomSettingsEnum, UiTextContext, RoomTypeRouteConfig, RoomTypeConfig } from '../../utils';
import { RoomMemberActions, RoomSettingsEnum, UiTextContext, RoomTypeRouteConfig, RoomTypeConfig } from '../../utils';
import { getAvatarURL } from '../../utils/lib/getAvatarURL';

let LivechatInquiry;
Expand Down Expand Up @@ -85,6 +85,10 @@ export default class LivechatRoomType extends RoomTypeConfig {
}
}

allowMemberAction(room, action) {
return [RoomMemberActions.INVITE, RoomMemberActions.JOIN].includes(action);
}

getUiText(context) {
switch (context) {
case UiTextContext.HIDE_WARNING:
Expand Down
8 changes: 8 additions & 0 deletions app/livechat/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ Meteor.startup(async () => {
}));
}, callbacks.priority.LOW, 'cant-leave-room');

callbacks.add('beforeJoinRoom', function(user, room) {
if (room.t === 'l' && !hasPermission(user._id, 'view-l-room')) {
throw new Meteor.Error('error-user-is-not-agent', 'User is not an Omnichannel Agent', { method: 'beforeJoinRoom' });
}

return user;
}, callbacks.priority.LOW, 'cant-join-room');

createLivechatQueueView();

const monitor = new LivechatAgentActivityMonitor();
Expand Down
2 changes: 1 addition & 1 deletion app/tokenpass/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Meteor.startup(function() {
throw new Meteor.Error('error-not-allowed', 'Token required', { method: 'joinRoom' });
}

return room;
return user;
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@
"error-transcript-already-requested": "Transcript already requested",
"error-user-has-no-roles": "User has no roles",
"error-user-is-not-activated": "User is not activated",
"error-user-is-not-agent": "User is not a Omnichannel Agent",
"error-user-is-not-agent": "User is not an Omnichannel Agent",
"error-user-is-offline": "User if offline",
"error-user-limit-exceeded": "The number of users you are trying to invite to #channel_name exceeds the limit set by the administrator",
"error-user-not-in-room": "User is not in this room",
Expand Down

0 comments on commit 66b872d

Please sign in to comment.