Skip to content

refactor: unify settings validation in REST API#41465

Open
Pr241singh wants to merge 2 commits into
RocketChat:developfrom
Pr241singh:refactor/41460-unify-setting-validation
Open

refactor: unify settings validation in REST API#41465
Pr241singh wants to merge 2 commits into
RocketChat:developfrom
Pr241singh:refactor/41460-unify-setting-validation

Conversation

@Pr241singh

@Pr241singh Pr241singh commented Jul 19, 2026

Copy link
Copy Markdown

Proposed changes (including videos or screenshots)

This PR refactors the settings validation flow by introducing a shared validateSetting helper that combines:

  • checkSettingValueBounds
  • validateSettingRules

The 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

  1. Start the Rocket.Chat server.
  2. Navigate to Administration → Workspace → Settings.
  3. Update a valid setting and verify it is saved successfully.
  4. Enter an invalid value that violates a setting's bounds and verify the API returns the expected validation error.
  5. Enter a value that violates a validation rule and verify the API returns the same validation error response.

Further comments

This is a refactoring change intended to reduce duplicated validation logic in the REST API while keeping the existing validation behavior unchanged.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation when updating settings through the API.
    • Invalid setting values now return a consistent validation error, including clearer error details when available.
    • Numeric limits and setting-specific validation rules are applied consistently.

@Pr241singh
Pr241singh requested a review from a team as a code owner July 19, 2026 09:13
@dionisio-bot

dionisio-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: df72dba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The settings API now uses a shared validateSetting helper that performs bounds and rule validation, while mapping invalid setting values to the standard validation failure response.

Changes

Settings validation

Layer / File(s) Summary
Shared validation helper
apps/meteor/server/settings/validateSetting.ts
Adds a helper that validates setting bounds and rules using the setting identifier and provided value.
Settings API integration
apps/meteor/server/api/v1/settings.ts
Replaces inline validation for default updates and maps error-invalid-setting-value errors to error-setting-validation-failed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type: chore

Suggested reviewers: sampaiodiego

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: unifying settings validation in the REST API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a360be and df72dba.

📒 Files selected for processing (2)
  • apps/meteor/server/api/v1/settings.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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.ts
  • apps/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.ts
  • apps/meteor/server/api/v1/settings.ts
🔇 Additional comments (1)
apps/meteor/server/settings/validateSetting.ts (1)

6-9: LGTM!

Comment thread apps/meteor/server/api/v1/settings.ts
Comment thread apps/meteor/server/api/v1/settings.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/server/settings/validateSetting.ts
Comment thread apps/meteor/server/api/v1/settings.ts
Comment thread apps/meteor/server/settings/validateSetting.ts
@ricardogarim

Copy link
Copy Markdown
Member

Hey @Pr241singh, thanks for that! I didn't quite understand the value of this helper. Could you explain it to us?

@Pr241singh

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants