Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/meteor/server/api/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import {
import { Meteor } from 'meteor/meteor';
import type { FindOptions } from 'mongodb';
import _ from 'underscore';

import { SettingValidationError } from '../../lib/settingValidationRules';
import { validateSetting } from '../../settings/validateSetting';
import { hasPermissionAsync } from '../../lib/authorization/hasPermission';
import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../lib/notifyListener';
import { SettingValidationError, validateSettingRules } from '../../lib/settingValidationRules';
import { disableCustomScripts } from '../../lib/shared/disableCustomScripts';
import { addOAuthServiceMethod } from '../../meteor-methods/auth/addOAuthService';
import { SettingsEvents, settings } from '../../settings';
import { checkSettingValueBounds } from '../../settings/checkSettingValueBonds';
import { updateAuditedByUser } from '../../settings/lib/auditedSettingUpdates';
import { saveSettingsBulk } from '../../settings/lib/saveSettingsBulk';
import { setValue } from '../../settings/raw';
Expand Down Expand Up @@ -390,14 +389,18 @@ API.v1.post(

if (isSettingsUpdatePropDefault(bodyParams)) {
// TODO(next major): unify both validations into one function with a common API error response
checkSettingValueBounds(setting, bodyParams.value);

try {
validateSettingRules([{ _id, value: bodyParams.value }]);
validateSetting(setting, bodyParams.value);
} catch (error) {
if (error instanceof SettingValidationError) {
return API.v1.failure(error.message, 'error-setting-validation-failed');
}

if (error instanceof Meteor.Error && error.error === 'error-invalid-setting-value') {
return API.v1.failure(error.reason ?? error.message, 'error-setting-validation-failed');
Comment thread
Pr241singh marked this conversation as resolved.
}
Comment thread
Pr241singh marked this conversation as resolved.

Comment thread
Pr241singh marked this conversation as resolved.
throw error;
}

Expand Down
9 changes: 9 additions & 0 deletions apps/meteor/server/settings/validateSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ISetting } from '@rocket.chat/core-typings';

import { validateSettingRules } from '../lib/settingValidationRules';
import { checkSettingValueBounds } from './checkSettingValueBonds';

export const validateSetting = (setting: ISetting, value?: ISetting['value']): void => {
Comment thread
Pr241singh marked this conversation as resolved.
Comment thread
Pr241singh marked this conversation as resolved.
checkSettingValueBounds(setting, value);
validateSettingRules([{ _id: setting._id, value }]);
};