Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 34 commits into from
Sep 18, 2024

Conversation

matheusbsilva137
Copy link
Member

@matheusbsilva137 matheusbsilva137 commented Jun 27, 2024

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\":\"my-new-testdep5@example.com\",\"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

Copy link
Contributor

dionisio-bot bot commented Jun 27, 2024

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

Copy link

changeset-bot bot commented Jun 27, 2024

🦋 Changeset detected

Latest commit: e625cb2

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

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@matheusbsilva137 matheusbsilva137 added this to the 6.11 milestone Jun 27, 2024
@matheusbsilva137 matheusbsilva137 marked this pull request as ready for review June 27, 2024 20:50
@matheusbsilva137 matheusbsilva137 requested review from a team as code owners June 27, 2024 20:50
@matheusbsilva137 matheusbsilva137 changed the title feat: Allow monitors to manage departments in units they supervise feat: Allow managing association to business units on departments' creation and update Jun 27, 2024
KevLehman
KevLehman previously approved these changes Jul 29, 2024
@jessicaschelly jessicaschelly added the stat: QA assured Means it has been tested and approved by a company insider label Aug 1, 2024
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 1, 2024
@kodiakhq kodiakhq bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 8, 2024
Copy link
Contributor

kodiakhq bot commented Aug 8, 2024

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

@KevLehman KevLehman added the stat: ready to merge PR tested and approved waiting for merge label Aug 16, 2024
@scuciatto scuciatto modified the milestones: 6.12, 6.13 Aug 23, 2024
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Sep 16, 2024
Copy link
Contributor

github-actions bot commented Sep 16, 2024

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

@scuciatto scuciatto added the stat: ready to merge PR tested and approved waiting for merge label Sep 18, 2024
@kodiakhq kodiakhq bot merged commit 9a38c8e into develop Sep 18, 2024
50 checks passed
@kodiakhq kodiakhq bot deleted the improve/monitors-manage-departments-units branch September 18, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad: core stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants