feat: Allow managing association to business units on departments' creation and update
Proposed changes (including videos or screenshots)
- Added a new optional
departmentUnitobject param tolivechat:saveDepartmentMeteor method,livechat/department(POST) endpoint andlivechat/department(PUT) endpoint;- Providing an empty object (
{}) to this param removes the department from its associated unit (or just doesn't add the department to any unit, if provided on the creation of a new department). Providing{ _id: undefined }ornulltriggers the same effect; - If no value is provided to this new param, then the association between the department and its unit (if it exists) won't be changed, nor created or removed;
- When providing a string
_idfield in the object ({ _id: "unit-id" }), the department will be associated to the unit with the specified_idIF the user has the permission to do so.
- Providing an empty object (
- In order to use any of the updated endpoints, the user must have the
manage-livechat-departmentspermission (this is already the current behavior), but there are additional conditions to associate a department with a specific unit when the new param is provided:- If the user is a monitor (role
livechat-monitor), then they must be a supervisor of the specified unit. That is, they must be linked (as monitor) to the specified unit in order to add or remove departments from it; - If the user is not a monitor (such as an
adminorlivechat-manager), any unit can be associated to the department (on creation or update).
- If the user is a monitor (role
- Providing any value different from a string to the
_idfield to the new param's object will trigger an error. - This is an additional/non-blocking operation. No errors are thrown (yet) even if the user tries to add a department to a unit they don't have the permission to manage.
Issue(s)
Steps to test or reproduce
Example request to the livechat:saveDepartment method (the new param is the last one that should be provided -- {\"_id\":\"unit-id\"} in the example):
curl --request POST \
--url http://localhost:3000/api/v1/method.call/livechat%3AsaveDepartment \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: f4U57vG-drmhd8hZbKAT_9TTJqW48Y_VB1zle6HWiRf' \
--header 'X-User-Id: WM8KyWfu6qXDCRZrq' \
--data '{"message":"{\"msg\":\"method\",\"id\":\"15\",\"method\":\"livechat:saveDepartment\",\"params\":[null,{\"enabled\":false,\"name\":\"My new department5\",\"description\":\"\",\"showOnRegistration\":false,\"showOnOfflineForm\":false,\"requestTagBeforeClosingChat\":false,\"email\":\"[email protected]\",\"chatClosingTags\":[],\"offlineMessageChannelName\":\"\",\"abandonedRoomsCloseCustomMessage\":\"\",\"waitingQueueMessage\":\"\",\"departmentsAllowedToForward\":[],\"fallbackForwardDepartment\":\"\",\"allowReceiveForwardOffline\":false},[],{\"_id\":\"unit-id\"}]}"}'
The command above triggers the creation of a new department associated with the unit with id unit-id. Change the first null param to a valid department string to edit it.
Example request to the livechat/department POST endpoint (check the new departmentUnit param):
curl --request POST \
--url http://localhost:3000/api/v1/livechat/department \
--header 'X-Auth-Token: f4U57vG-drmhd8hZbKAT_9TTJqW48Y_VB1zle6HWiRf' \
--header 'X-User-Id: WM8KyWfu6qXDCRZrq' \
--data '{
"department": {
"name": "Test23456",
"enabled": true,
"showOnOfflineForm": true,
"showOnRegistration": true,
"email": "bla@bla"
},
"departmentUnit": { "_id": "unit-id" }
}'
Example request to the livechat/department/:id PUT endpoint (check the new departmentUnit param -- providing an empty object to it will remove the department from its associated unit):
curl --request PUT \
--url http://localhost:3000/api/v1/livechat/department/666cc15cd32e4e47b82332fd \
--header 'X-Auth-Token: f4U57vG-drmhd8hZbKAT_9TTJqW48Y_VB1zle6HWiRf' \
--header 'X-User-Id: WM8KyWfu6qXDCRZrq' \
--data '{
"department": {
"name": "Test23456",
"enabled": true,
"showOnOfflineForm": true,
"showOnRegistration": true,
"email": "bla@bla"
},
"departmentUnit": {}
}'
Further comments
Looks like this PR is ready to merge! 🎉 If you have any trouble, please check the PR guidelines
🦋 Changeset detected
Latest commit: e625cb223e0e78f531bb67ee066fbb1fbb1a2f4c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 32 packages
| Name | Type |
|---|---|
| @rocket.chat/meteor | Minor |
| @rocket.chat/model-typings | Minor |
| @rocket.chat/rest-typings | Minor |
| @rocket.chat/apps | Patch |
| @rocket.chat/models | Patch |
| @rocket.chat/account-service | Patch |
| @rocket.chat/authorization-service | Patch |
| @rocket.chat/ddp-streamer | Patch |
| @rocket.chat/omnichannel-transcript | Patch |
| @rocket.chat/presence-service | Patch |
| @rocket.chat/queue-worker | Patch |
| @rocket.chat/stream-hub-service | Patch |
| @rocket.chat/omnichannel-services | Patch |
| rocketchat-services | Patch |
| @rocket.chat/api-client | Patch |
| @rocket.chat/core-services | Patch |
| @rocket.chat/ddp-client | Patch |
| @rocket.chat/ui-contexts | Major |
| @rocket.chat/presence | Patch |
| @rocket.chat/cron | Patch |
| @rocket.chat/instance-status | Patch |
| @rocket.chat/livechat | Patch |
| @rocket.chat/uikit-playground | Patch |
| @rocket.chat/fuselage-ui-kit | Major |
| @rocket.chat/gazzodown | Major |
| @rocket.chat/ui-avatar | Major |
| @rocket.chat/ui-client | Major |
| @rocket.chat/ui-video-conf | Major |
| @rocket.chat/web-ui-registration | Major |
| @rocket.chat/core-typings | Minor |
| @rocket.chat/license | Patch |
| @rocket.chat/pdf-worker | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 59.84%. Comparing base (
4202d65) to head (e625cb2). Report is 1 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #32682 +/- ##
===========================================
+ Coverage 59.74% 59.84% +0.09%
===========================================
Files 2552 2554 +2
Lines 62869 63020 +151
Branches 14123 14133 +10
===========================================
+ Hits 37562 37713 +151
Misses 22900 22900
Partials 2407 2407
| Flag | Coverage Δ | |
|---|---|---|
| unit | 77.14% <100.00%> (+0.18%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
This PR currently has a merge conflict. Please resolve this and then re-add the ['stat: ready to merge', 'automerge'] label.
PR Preview Action v1.4.8 :---: Preview removed because the pull request was closed. 2024-09-18 12:31 UTC