-
Notifications
You must be signed in to change notification settings - Fork 13k
fix: API method rooms.delete deleting main team room
#36790
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
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: 655b39c The changes in this PR will be included in the next version bump. This PR includes changesets to release 42 packages
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. Additional details and impacted files@@ Coverage Diff @@
## develop #36790 +/- ##
===========================================
- Coverage 67.59% 67.58% -0.02%
===========================================
Files 3341 3341
Lines 114018 114016 -2
Branches 20668 20669 +1
===========================================
- Hits 77076 77055 -21
- Misses 34266 34284 +18
- Partials 2676 2677 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
6f4e465 to
723f8d2
Compare
|
I don't know if this is still the case, but worth mentioning: Originally the teams system was supposed to allow executing operations like this in either entitity and it should then reflect on the other. So from that initial concept, you should be able to delete a team's main room, but doing so should cause the whole team to be deleted along with it. |
|
Please add a test to the |
|
While testing the current behavior, I found that Although the team no longer appears in the sidebar, the orphaned team record still occupies space in the DB and also prevents the creation of a new team with the same name. The PR prevents deletion of the team since it throws error when the code tries to delete team's main room. We should move the logic introduced in the eraseRoom function by this pr upwards to the api level. |
723f8d2 to
61e9072
Compare
WalkthroughAdds a pre-check in the rooms.delete API to fetch the room and block deletion if it's a team's main room. Updates eraseRoom to accept either a room id or an IRoom object and operate on the resolved room. Tests extended to cover the new guard and adjust setup/teardown. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant API as rooms.delete (API)
participant DB as Rooms Store
participant Guard as teamMain check
participant Eraser as eraseRoom()
participant Delete as deleteRoom()
C->>API: DELETE /api/v1/rooms.delete (roomId)
API->>DB: findOneById(roomId)
DB-->>API: room | null
alt room not found
API-->>C: error (invalid-room)
else room found
API->>Guard: isTeamMain(room)?
alt is teamMain
API-->>C: error (cannot-delete-team-main)
else not teamMain
API->>Eraser: eraseRoom(room, currentUserId)
Eraser->>Delete: deleteRoom(room._id)
Delete-->>Eraser: ok
Eraser-->>API: done
API-->>C: success: true
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The current behavior first deletes the rooms listed in If the team’s main room ID is included in To fix this, I’ll filter out the team’s main room ID from The fix related to this should in the pr #36807 |
Proposed changes (including videos or screenshots)
What’s Changed
This PR fixes a critical bug where the API method rooms.delete inadvertently deletes the main (primary) room of a team. The change ensures the main team room remains protected and is not removed when this endpoint is invoked. Also
Background
On Rocket.Chat, teams often have a designated “main room” that serves as the central hub. Deleting this primary room via the rooms.delete API was unintended, potentially disrupting team workflows and causing data loss.
Testing
New test case specifically targeting rooms.delete to confirm the main team room remains intact.
Issue(s)
Steps to test or reproduce
Further comments
SUP-836
Summary by CodeRabbit
Bug Fixes
Tests
Chores