Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
98 lines
3.0 KiB
TypeScript
98 lines
3.0 KiB
TypeScript
import type { IUser, IOmnichannelRoom } from '@rocket.chat/core-typings';
|
|
import { LivechatDepartmentAgents, LivechatInquiry, LivechatRooms, LivechatDepartment } from '@rocket.chat/models';
|
|
|
|
import { RoutingManager } from './RoutingManager';
|
|
import { hasPermissionAsync } from '../authorization/hasPermission';
|
|
import { hasRoleAsync } from '../authorization/hasRole';
|
|
|
|
type OmnichannelRoomAccessValidator = (
|
|
room: IOmnichannelRoom,
|
|
user?: Pick<IUser, '_id'>,
|
|
extraData?: Record<string, any>,
|
|
) => boolean | Promise<boolean>;
|
|
|
|
export const validators: OmnichannelRoomAccessValidator[] = [
|
|
async function (_room, user) {
|
|
if (!user?._id) {
|
|
return false;
|
|
}
|
|
return hasPermissionAsync(user._id, 'view-livechat-rooms');
|
|
},
|
|
async function (room, user) {
|
|
if (!user?._id) {
|
|
return false;
|
|
}
|
|
|
|
const { _id: userId } = user;
|
|
const { servedBy: { _id: agentId } = {} } = room;
|
|
return userId === agentId || (!room.open && hasPermissionAsync(user._id, 'view-livechat-room-closed-by-another-agent'));
|
|
},
|
|
async function (room, _user, extraData) {
|
|
if (extraData?.rid) {
|
|
const dbRoom = await LivechatRooms.findOneById(extraData.rid);
|
|
if (dbRoom) {
|
|
room = dbRoom;
|
|
}
|
|
}
|
|
|
|
return extraData?.visitorToken && room.v && room.v.token === extraData.visitorToken && room.open === true;
|
|
},
|
|
async function (room, user) {
|
|
if (!user?._id) {
|
|
return false;
|
|
}
|
|
if (!RoutingManager.getConfig()?.previewRoom) {
|
|
return;
|
|
}
|
|
|
|
let departmentIds;
|
|
if (!(await hasRoleAsync(user._id, 'livechat-manager'))) {
|
|
const departmentAgents = (await LivechatDepartmentAgents.findByAgentId(user._id, { projection: { departmentId: 1 } }).toArray()).map(
|
|
(d) => d.departmentId,
|
|
);
|
|
departmentIds = (await LivechatDepartment.findEnabledInIds(departmentAgents, { projection: { _id: 1 } }).toArray()).map((d) => d._id);
|
|
}
|
|
|
|
const filter = {
|
|
rid: room._id,
|
|
$or: [
|
|
{
|
|
$and: [{ defaultAgent: { $exists: true } }, { 'defaultAgent.agentId': user._id }],
|
|
},
|
|
{
|
|
...(departmentIds && departmentIds.length > 0 && { department: { $in: departmentIds } }),
|
|
},
|
|
{
|
|
department: { $exists: false }, // No department == public queue
|
|
},
|
|
],
|
|
};
|
|
|
|
// TODO: findone filtering if the inquiry is queued instead of checking here
|
|
const inquiry = await LivechatInquiry.findOne(filter, { projection: { status: 1 } });
|
|
return inquiry && inquiry.status === 'queued';
|
|
},
|
|
async function (room, user) {
|
|
if (!room.departmentId || room.open || !user?._id) {
|
|
return;
|
|
}
|
|
const agentOfDepartment = await LivechatDepartmentAgents.findOneByAgentIdAndDepartmentId(user._id, room.departmentId, {
|
|
projection: { _id: 1 },
|
|
});
|
|
if (!agentOfDepartment) {
|
|
return;
|
|
}
|
|
return hasPermissionAsync(user._id, 'view-livechat-room-closed-same-department');
|
|
},
|
|
function (_room, user) {
|
|
// Check if user is rocket.cat
|
|
if (!user?._id) {
|
|
return false;
|
|
}
|
|
|
|
// This opens the ability for rocketcat to upload files to a livechat room without being included in it :)
|
|
// Worst case, someone manages to log in as rocketcat lol
|
|
return user._id === 'rocket.cat';
|
|
},
|
|
];
|