Skip to content

feat: close rooms in delete queue and sector endpoints#929

Open
MarcusviniciusLsantos wants to merge 5 commits intomainfrom
feat/close-rooms-in-delete-queue-and-sector-endpoints
Open

feat: close rooms in delete queue and sector endpoints#929
MarcusviniciusLsantos wants to merge 5 commits intomainfrom
feat/close-rooms-in-delete-queue-and-sector-endpoints

Conversation

@MarcusviniciusLsantos
Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added / updated (for bug fixes / features)
  • Do we need to implement analytics?

What

Add support for the end_all_chats query parameter on the DELETE endpoints for Sector (DELETE /api/v1/sector/{uuid}/) and Queue (DELETE /api/v1/queue/{uuid}/). When ?end_all_chats=true is provided, all active rooms (both ongoing with an assigned agent and waiting without an agent) are closed in batches before the sector/queue is deleted. The implementation reuses the existing BulkCloseService, preserving all business logic (tags, pins, InService status, CSAT, WebSocket notifications, metrics, and queue priority routing).

Key behaviors:

  • Flag absent or false: existing behavior is unchanged.
  • Flag true, no active rooms: deletion proceeds normally.
  • Flag true, all rooms closed successfully: deletion proceeds.
  • Flag true, partial failure: logs a warning and proceeds with deletion.
  • Flag true, all rooms failed to close: returns 400 and aborts deletion.

Files changed:

  • chats/apps/api/v1/sectors/viewsets.py — added _close_active_rooms and updated perform_destroy
  • chats/apps/api/v1/queues/viewsets.py — added _close_active_rooms and updated perform_destroy
  • chats/apps/sectors/tests/test_viewsets.py — added SectorEndAllChatsTests (6 test cases)
  • chats/apps/queues/tests/test_viewsets.py — added QueueEndAllChatsTests (6 test cases)

Why

When a sector or queue is deleted, any active rooms associated with it remain open in a broken state — they reference a queue/sector that no longer exists, which can lead to inconsistent data and a poor user experience. By allowing the caller to pass end_all_chats=true, the API ensures all conversations are properly closed (with notifications, metrics, and CSAT flows triggered) before the resource is removed, maintaining data integrity and a clean shutdown of ongoing chats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants