Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Add Permissions to deal with Omnichannel visitor past chats history #17580

Merged
merged 6 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/authorization/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ Meteor.startup(function() {
{ _id: 'add-livechat-department-agents', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-current-chats', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-real-time-monitoring', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-triggers', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-customfields', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-installation', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-appearance', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-webhooks', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-facebook', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-officeHours', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-triggers', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-customfields', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-installation', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-appearance', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-webhooks', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-facebook', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-officeHours', roles: ['livechat-manager', 'admin'] },
MarcosSpessatto marked this conversation as resolved.
Show resolved Hide resolved
{ _id: 'view-livechat-room-closed-same-department', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-room-closed-by-another-agent', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-room-customfields', roles: ['livechat-manager', 'livechat-agent', 'admin'] },
{ _id: 'edit-livechat-room-customfields', roles: ['livechat-manager', 'livechat-agent', 'admin'] },
];
Expand Down
15 changes: 14 additions & 1 deletion app/livechat/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import { RoutingManager } from './lib/RoutingManager';
import { createLivechatQueueView } from './lib/Helper';
import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor';

function allowAccessClosedRoomOfSameDepartment(room, user) {
if (!room || !user || room.t !== 'l' || !room.departmentId || room.open) {
return;
}
const agentOfDepartment = LivechatDepartmentAgents.findOneByAgentIdAndDepartmentId(user._id, room.departmentId);
if (!agentOfDepartment) {
return;
}
return hasPermission(user._id, 'view-livechat-room-closed-same-department');
}

Meteor.startup(() => {
roomTypes.setRoomFind('l', (_id) => LivechatRooms.findOneById(_id));

Expand All @@ -24,7 +35,7 @@ Meteor.startup(() => {
}
const { _id: userId } = user;
const { servedBy: { _id: agentId } = {} } = room;
return userId === agentId;
return userId === agentId || (!room.open && hasPermission(user._id, 'view-livechat-room-closed-by-another-agent'));
});

addRoomAccessValidator(function(room, user, extraData) {
Expand Down Expand Up @@ -59,6 +70,8 @@ Meteor.startup(() => {
return inquiry && inquiry.status === 'queued';
});

addRoomAccessValidator(allowAccessClosedRoomOfSameDepartment);

callbacks.add('beforeLeaveRoom', function(user, room) {
if (room.t !== 'l') {
return user;
Expand Down
4 changes: 4 additions & 0 deletions app/models/server/models/LivechatDepartmentAgents.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class LivechatDepartmentAgents extends Base {
return this.find({ agentId });
}

findOneByAgentIdAndDepartmentId(agentId, departmentId) {
return this.findOne({ agentId, departmentId });
}

saveAgent(agent) {
return this.upsert({
agentId: agent.agentId,
Expand Down
2 changes: 2 additions & 0 deletions ee/app/livechat-enterprise/server/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const createPermissions = () => {
'view-livechat-real-time-monitoring',
'view-livechat-officeHours',
'manage-livechat-agents',
'view-livechat-room-closed-same-department',
'view-livechat-room-closed-by-another-agent',
'view-livechat-room-customfields',
'edit-livechat-room-customfields',
];
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3655,6 +3655,8 @@
"view-l-room": "View Omnichannel Rooms",
"view-l-room_description": "Permission to view Omnichannel rooms",
"view-livechat-analytics": "View Omnichannel Analytics",
"view-livechat-room-closed-by-another-agent": "View Omnichannel Rooms closed by another agent",
"view-livechat-room-closed-same-department": "View Omnichannel Rooms closed by another agent in the same department",
"view-livechat-departments": "View Omnichannel Departments",
"view-livechat-manager": "View Omnichannel Manager",
"view-livechat-manager_description": "Permission to view other Omnichannel managers",
Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,8 @@
"view-l-room": "Ver salas de Omnichannel",
"view-l-room_description": "Permissão para ver salas de Omnichannel",
"view-livechat-analytics": "Ver o Omnichannel Analytics",
"view-livechat-room-closed-by-another-agent": "Ver Salas Omnichannel fechadas por outro agente",
"view-livechat-room-closed-same-department": "Ver Salas Omnichannel fechadas por outro agente do mesmo departamento",
"view-livechat-manager": "Ver o Gerente Omnichannel",
"view-livechat-manager_description": "Permissão para ver outros gerentes de Omnichannel",
"view-livechat-rooms": "Ver Salas de Omnichannel",
Expand Down Expand Up @@ -3429,4 +3431,4 @@
"Your_question": "A sua pergunta",
"Your_server_link": "O link do seu servidor",
"Your_workspace_is_ready": "O seu espaço de trabalho está pronto a usar 🎉"
}
}