-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/external-avatars
- Loading branch information
Showing
18 changed files
with
982 additions
and
49 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,7 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/model-typings": minor | ||
"@rocket.chat/rest-typings": minor | ||
--- | ||
|
||
Added support for specifying a unit on departments' creation and update |
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
53 changes: 53 additions & 0 deletions
53
apps/meteor/ee/app/livechat-enterprise/server/hooks/manageDepartmentUnit.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,53 @@ | ||
import type { ILivechatDepartment, IOmnichannelBusinessUnit } from '@rocket.chat/core-typings'; | ||
import { LivechatDepartment, LivechatUnit } from '@rocket.chat/models'; | ||
|
||
import { hasAnyRoleAsync } from '../../../../../app/authorization/server/functions/hasRole'; | ||
import { callbacks } from '../../../../../lib/callbacks'; | ||
import { getUnitsFromUser } from '../methods/getUnitsFromUserRoles'; | ||
|
||
export const manageDepartmentUnit = async ({ userId, departmentId, unitId }: { userId: string; departmentId: string; unitId: string }) => { | ||
const accessibleUnits = await getUnitsFromUser(userId); | ||
const isLivechatManager = await hasAnyRoleAsync(userId, ['admin', 'livechat-manager']); | ||
const department = await LivechatDepartment.findOneById<Pick<ILivechatDepartment, '_id' | 'ancestors' | 'parentId'>>(departmentId, { | ||
projection: { ancestors: 1, parentId: 1 }, | ||
}); | ||
|
||
const isDepartmentAlreadyInUnit = unitId && department?.ancestors?.includes(unitId); | ||
if (!department || isDepartmentAlreadyInUnit) { | ||
return; | ||
} | ||
|
||
const currentDepartmentUnitId = department.parentId; | ||
const canManageNewUnit = !unitId || isLivechatManager || (Array.isArray(accessibleUnits) && accessibleUnits.includes(unitId)); | ||
const canManageCurrentUnit = | ||
!currentDepartmentUnitId || isLivechatManager || (Array.isArray(accessibleUnits) && accessibleUnits.includes(currentDepartmentUnitId)); | ||
if (!canManageNewUnit || !canManageCurrentUnit) { | ||
return; | ||
} | ||
|
||
if (unitId) { | ||
const unit = await LivechatUnit.findOneById<Pick<IOmnichannelBusinessUnit, '_id' | 'ancestors'>>(unitId, { | ||
projection: { ancestors: 1 }, | ||
}); | ||
|
||
if (!unit) { | ||
return; | ||
} | ||
|
||
if (currentDepartmentUnitId) { | ||
await LivechatUnit.decrementDepartmentsCount(currentDepartmentUnitId); | ||
} | ||
|
||
await LivechatDepartment.addDepartmentToUnit(departmentId, unitId, [unitId, ...(unit.ancestors || [])]); | ||
await LivechatUnit.incrementDepartmentsCount(unitId); | ||
return; | ||
} | ||
|
||
if (currentDepartmentUnitId) { | ||
await LivechatUnit.decrementDepartmentsCount(currentDepartmentUnitId); | ||
} | ||
|
||
await LivechatDepartment.removeDepartmentFromUnit(departmentId); | ||
}; | ||
|
||
callbacks.add('livechat.manageDepartmentUnit', manageDepartmentUnit, callbacks.priority.HIGH, 'livechat-manage-department-unit'); |
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.