Skip to content
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
20 changes: 8 additions & 12 deletions client/views/room/Header/Omnichannel/QuickActions/QuickActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useContext, useCallback, useState, useEffect, useMemo } from 'react';
import React, { memo, useContext, useCallback, useState, useEffect } from 'react';
import { BoxProps, ButtonGroup } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { FlowRouter } from 'meteor/kadira:flow-router';
Expand All @@ -17,7 +17,7 @@ import TranscriptModal from '../../../../../components/Omnichannel/modals/Transc
import CloseChatModal from '../../../../../components/Omnichannel/modals/CloseChatModal';
import { handleError } from '../../../../../../app/utils/client';
import { IRoom } from '../../../../../../definition/IRoom';
import { useAtLeastOnePermission, usePermission, useRole } from '../../../../../contexts/AuthorizationContext';
import { usePermission, useRole } from '../../../../../contexts/AuthorizationContext';
import { useUserId } from '../../../../../contexts/UserContext';
import { useOmnichannelRouteConfig } from '../../../../../contexts/OmnichannelContext';
import { useEndpoint, useMethod } from '../../../../../contexts/ServerContext';
Expand Down Expand Up @@ -185,13 +185,15 @@ const QuickActions = ({ room, className }: { room: IRoom; className: BoxProps['c

const hasManagerRole = useRole('livechat-manager');

const roomOpen = room?.open && ((room.u?._id === uid) || hasManagerRole);
const roomOpen = room?.open && ((room.u?._id === uid) || hasManagerRole) && room?.lastMessage?.t !== 'livechat-close';

const canForwardGuest = usePermission('transfer-livechat-guest');

const canSendTranscript = usePermission('send-omnichannel-chat-transcript');

const canCloseRoom = usePermission('close-others-livechat-room');
const canCloseOthersRoom = usePermission('close-others-livechat-room');

const canCloseRoom = usePermission('close-livechat-room');

const canMoveQueue = !!omnichannelRouteConfig?.returnQueue && room?.u !== undefined;

Expand All @@ -206,7 +208,7 @@ const QuickActions = ({ room, className }: { room: IRoom; className: BoxProps['c
case QuickActionsEnum.Transcript:
return !!email && canSendTranscript;
case QuickActionsEnum.CloseChat:
return !!roomOpen && canCloseRoom;
return !!roomOpen && (canCloseRoom || canCloseOthersRoom);
case QuickActionsEnum.OnHoldChat:
return !!roomOpen && canPlaceChatOnHold;
default:
Expand All @@ -215,12 +217,6 @@ const QuickActions = ({ room, className }: { room: IRoom; className: BoxProps['c
return false;
};

const hasPermissionGroup = useAtLeastOnePermission(
useMemo(() => [
'close-others-livechat-room', 'transfer-livechat-guest',
], []),
);

return <ButtonGroup mi='x4' medium>
{ visibleActions.map(({ id, color, icon, title, action = actionDefault }, index) => {
const props = {
Expand All @@ -237,7 +233,7 @@ const QuickActions = ({ room, className }: { room: IRoom; className: BoxProps['c
key: id,
};

if (!hasPermissionGroup || !hasPermissionButtons(id)) {
if (!hasPermissionButtons(id)) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions definition/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface IMessage extends IRocketChatRecord {

dcount?: number;
tcount?: number;
t?: string;
}
4 changes: 2 additions & 2 deletions ee/app/livechat-enterprise/server/api/lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { escapeRegExp } from '../../../../../../lib/escapeRegExp';
import LivechatTag from '../../../../models/server/raw/LivechatTag';

export async function findTags({ userId, text, pagination: { offset, count, sort } }) {
if (!await hasPermissionAsync(userId, 'manage-livechat-tags')) {
if (!await hasPermissionAsync(userId, 'manage-livechat-tags') && !await hasPermissionAsync(userId, 'view-l-room')) {
throw new Error('error-not-authorized');
}
const filterReg = new RegExp(escapeRegExp(text), 'i');
Expand All @@ -28,7 +28,7 @@ export async function findTags({ userId, text, pagination: { offset, count, sort
}

export async function findTagById({ userId, tagId }) {
if (!await hasPermissionAsync(userId, 'manage-livechat-tags')) {
if (!await hasPermissionAsync(userId, 'manage-livechat-tags') && !await hasPermissionAsync(userId, 'view-l-room')) {
throw new Error('error-not-authorized');
}
return LivechatTag.findOneById(tagId);
Expand Down