fix: validate user group exists in UpdateUser (fixes #5236)#5259
Conversation
Add group existence validation in UpdateUser to prevent writing non-existent group names to the database. - Add IsUserUsableGroup() helper to setting/user_usable_group.go - Validate updatedUser.Group in controller/user.go UpdateUser handler - Return error with descriptive message when group does not exist
|
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)
WalkthroughAdds a thread-safe group existence check and an early guard in UpdateUser: the handler now rejects non-empty unknown group names (using ratio_setting) before applying updates. ChangesUser Group Validation
🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@controller/user.go`:
- Around line 594-597: The current validation uses setting.IsUserUsableGroup
which checks the description map and can allow groups that lack ratio/channel
config; change the guard to validate updatedUser.Group against the authoritative
ratio-setting map returned by ratio_setting.GetGroupRatioCopy() (the same source
used in controller/group.go and channel selection). Specifically, replace the
IsUserUsableGroup check with a lookup in the map from GetGroupRatioCopy() and
return the same ApiErrorI18n if the group key is missing or empty so only groups
with configured ratios/channels are accepted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f52e9527-276f-4a64-aaba-99f2d277d41e
📒 Files selected for processing (2)
controller/user.gosetting/user_usable_group.go
Replace setting.IsUserUsableGroup (description map) with ratio_setting.ContainsGroupRatio (authoritative ratio config) as suggested by code review.
fix: validate user group exists in UpdateUser (fixes #5236)
Add group existence validation in UpdateUser to prevent writing
non-existent group names to the database.
Summary by CodeRabbit
Bug Fixes
New Features