fix: Omnichannel Tags available to be used in the wrong department (#29169)
Co-authored-by: Martin Schoeler <20868078+MartinSchoeler@users.noreply.github.com>pull/28783/head^2
parent
dbc79dd3ee
commit
eecd9fc99a
@ -0,0 +1,6 @@ |
||||
--- |
||||
"@rocket.chat/meteor": patch |
||||
"@rocket.chat/rest-typings": patch |
||||
--- |
||||
|
||||
fix: Omnichannel Tags available to be used in the wrong department |
||||
@ -0,0 +1,19 @@ |
||||
import { useEndpoint } from '@rocket.chat/ui-contexts'; |
||||
import { useQuery } from '@tanstack/react-query'; |
||||
|
||||
type Props = { |
||||
department?: string; |
||||
text?: string; |
||||
}; |
||||
|
||||
export const useLivechatTags = (options: Props) => { |
||||
const getTags = useEndpoint('GET', '/v1/livechat/tags'); |
||||
|
||||
const { department, text } = options; |
||||
return useQuery(['/v1/livechat/tags', text, department], () => |
||||
getTags({ |
||||
text: text || '', |
||||
...(department && { department }), |
||||
}), |
||||
); |
||||
}; |
||||
@ -0,0 +1,38 @@ |
||||
import { LivechatDepartment, LivechatDepartmentAgents, LivechatUnit } from '@rocket.chat/models'; |
||||
|
||||
import { helperLogger } from '../../lib/logger'; |
||||
|
||||
export const getDepartmentsWhichUserCanAccess = async (userId: string): Promise<string[]> => { |
||||
const departments = await LivechatDepartmentAgents.find( |
||||
{ |
||||
agentId: userId, |
||||
}, |
||||
{ |
||||
projection: { |
||||
departmentId: 1, |
||||
}, |
||||
}, |
||||
).toArray(); |
||||
|
||||
const monitoredDepartments = await LivechatUnit.findMonitoredDepartmentsByMonitorId(userId); |
||||
const combinedDepartments = [ |
||||
...departments.map((department) => department.departmentId), |
||||
...monitoredDepartments.map((department) => department._id), |
||||
]; |
||||
|
||||
return [...new Set(combinedDepartments)]; |
||||
}; |
||||
|
||||
export const hasAccessToDepartment = async (userId: string, departmentId: string): Promise<boolean> => { |
||||
const department = await LivechatDepartmentAgents.findOneByAgentIdAndDepartmentId(userId, departmentId); |
||||
if (department) { |
||||
helperLogger.debug(`User ${userId} has access to department ${departmentId} because they are an agent`); |
||||
return true; |
||||
} |
||||
|
||||
const monitorAccess = await LivechatDepartment.checkIfMonitorIsMonitoringDepartmentById(userId, departmentId); |
||||
helperLogger.debug( |
||||
`User ${userId} ${monitorAccess ? 'has' : 'does not have'} access to department ${departmentId} because they are a monitor`, |
||||
); |
||||
return monitorAccess; |
||||
}; |
||||
Loading…
Reference in new issue