fix: update custom roles queries to include missing protected fields#40937
fix: update custom roles queries to include missing protected fields#40937Herorishi1234 wants to merge 1 commit into
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 |
|
WalkthroughMongoDB filter logic in ChangesCustom Role Filtering
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Proposed changes
Fix an issue where custom roles created in older Rocket.Chat versions are not displayed in the Administration → Permissions → Custom Roles panel.
The root cause is that legacy role documents may not contain the
protectedfield. The existing query uses a strict filter:This excludes documents where the field is missing, causing them to not appear in query results.
MongoDB’s
$neoperator matches documents where the field is not equal to a specified value, including documents where the field does not exist.By updating the query to use
{ protected: { $ne: true } }, both explicitly unprotected roles (false) and legacy roles without the field are correctly returned.Changes:
findCustomRolesquery:protected: false→protected: { $ne: true }countCustomRolesto use the same filter to ensure consistency between results and paginationIssue(s)
Closes #40798
Steps to test or reproduce
Create a custom role from:
Administration → Permissions → Custom Roles
Remove the
protectedfield manually:Before this fix:
After this fix:
Further comments
protected: true.protected: true) are still excluded as expected.Summary by CodeRabbit