fix: use $ne operator in findCustomRoles to include roles without protected field#41329
fix: use $ne operator in findCustomRoles to include roles without protected field#41329prathamesh04 wants to merge 1 commit into
Conversation
…roles without protected field Closes RocketChat#40798
|
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 |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (3)📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-05-06T12:21:44.083ZApplied to files:
🔇 Additional comments (1)
WalkthroughCustom role retrieval and counting now exclude only roles with ChangesCustom role filtering
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
Description
This PR fixes a bug in
findCustomRolesandcountCustomRolesmethods inpackages/models/src/models/Roles.tswhere roles without theprotectedfield were being excluded from results.Problem
The original query used
protected: falsewhich only matches documents where theprotectedfield exists and is explicitlyfalse. It does NOT match documents where theprotectedfield is missing/undefined.This causes issues on older Rocket.Chat instances where custom roles were created before the
protectedfield was added to the schema. These roles are invisible tofindCustomRolesandcountCustomRoles.Solution
Changed the query from
protected: falsetoprotected: { $ne: true }which:protectedisfalseprotectedisundefined/missingprotectedis explicitlytrueThis is consistent with how MongoDB's
$neoperator works and handles the edge case of missing fields properly.Related Issue
Closes #40798
Changes
packages/models/src/models/Roles.ts: UpdatedfindCustomRolesandcountCustomRolesquery filtersSummary by CodeRabbit