Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

feat: Allow managing association to business units on departments' creation and update

Open matheusbsilva137 opened this issue 1 year ago • 4 comments

Proposed changes (including videos or screenshots)

  • Added a new optional departmentUnit object param to livechat:saveDepartment Meteor method, livechat/department (POST) endpoint and livechat/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 } or null triggers 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 _id field in the object ({ _id: "unit-id" }), the department will be associated to the unit with the specified _id IF the user has the permission to do so.
  • In order to use any of the updated endpoints, the user must have the manage-livechat-departments permission (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 admin or livechat-manager), any unit can be associated to the department (on creation or update).
  • Providing any value different from a string to the _id field 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

SUP-613

matheusbsilva137 avatar Jun 27 '24 00:06 matheusbsilva137

Looks like this PR is ready to merge! 🎉 If you have any trouble, please check the PR guidelines

dionisio-bot[bot] avatar Jun 27 '24 00:06 dionisio-bot[bot]

🦋 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

changeset-bot[bot] avatar Jun 27 '24 00:06 changeset-bot[bot]

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

Impacted file tree graph

@@             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.

codecov[bot] avatar Jun 27 '24 00:06 codecov[bot]

This PR currently has a merge conflict. Please resolve this and then re-add the ['stat: ready to merge', 'automerge'] label.

kodiakhq[bot] avatar Aug 08 '24 19:08 kodiakhq[bot]

PR Preview Action v1.4.8 :---: Preview removed because the pull request was closed. 2024-09-18 12:31 UTC

github-actions[bot] avatar Sep 16 '24 11:09 github-actions[bot]