refactor: unify settings validation in REST API#41465
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 |
|
WalkthroughThe settings API now uses a shared ChangesSettings validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@apps/meteor/server/api/v1/settings.ts`:
- Around line 395-403: Append a fallback `throw error;` to the catch block
handling validation in the settings API, after the existing
`SettingValidationError` and invalid `Meteor.Error` branches, so unexpected
errors propagate and prevent saving. Do not alter the existing mapped failure
responses.
- Around line 400-402: Update the E2E assertions in the settings API tests to
expect the new error-setting-validation-failed response and its reason/message
text, replacing expectations for the old error-invalid-setting-value message.
Locate the relevant validation-failure assertions in the settings test flow and
preserve all other response expectations.
🪄 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: 3d292570-06f3-44ad-9d7b-dbd37923bbe2
📒 Files selected for processing (2)
apps/meteor/server/api/v1/settings.tsapps/meteor/server/settings/validateSetting.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/server/settings/validateSetting.tsapps/meteor/server/api/v1/settings.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/server/settings/validateSetting.tsapps/meteor/server/api/v1/settings.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/server/settings/validateSetting.tsapps/meteor/server/api/v1/settings.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/server/settings/validateSetting.tsapps/meteor/server/api/v1/settings.ts
🔇 Additional comments (1)
apps/meteor/server/settings/validateSetting.ts (1)
6-9: LGTM!
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Hey @Pr241singh, thanks for that! I didn't quite understand the value of this helper. Could you explain it to us? |
|
Thanks for taking a look, @ricardogarim! My intention with introducing validateSetting wasn't primarily to reduce two lines of code. The TODO in this endpoint mentions unifying both validations into a single function with a common API validation flow. The helper provides a single entry point for settings validation, encapsulating the required validation order (bounds first, then validation rules). This avoids future callers having to remember both validation functions or accidentally applying only one of them. My goal was to centralize that validation pipeline while keeping the existing behavior unchanged. If you think this level of abstraction isn't justified yet, I'm happy to adjust the implementation. |
Proposed changes (including videos or screenshots)
This PR refactors the settings validation flow by introducing a shared
validateSettinghelper that combines:checkSettingValueBoundsvalidateSettingRulesThe REST API now uses this helper instead of performing both validations separately, reducing duplicated validation logic while preserving the existing behavior.
Additionally, both bounds validation and rule validation now return a consistent API error response, addressing the existing TODO in
settings.ts.Issue(s)
Related to #41460
Steps to test or reproduce
Further comments
This is a refactoring change intended to reduce duplicated validation logic in the REST API while keeping the existing validation behavior unchanged.
Summary by CodeRabbit