forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Omnichannel Tags available to be used in the wrong department (R…
…ocketChat#29169) Co-authored-by: Martin Schoeler <20868078+MartinSchoeler@users.noreply.github.com>
- Loading branch information
1 parent
dbc79dd
commit eecd9fc
Showing
18 changed files
with
301 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
"@rocket.chat/rest-typings": patch | ||
--- | ||
|
||
fix: Omnichannel Tags available to be used in the wrong department |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
apps/meteor/client/components/Omnichannel/hooks/useLivechatTags.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }), | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
apps/meteor/ee/app/livechat-enterprise/server/api/lib/departments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.