Skip to content

Commit

Permalink
[FIX] Settings not being overwritten to their default values (#25891)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
  • Loading branch information
sampaiodiego committed Jul 20, 2022
1 parent 06c24de commit 0ac8502
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions apps/meteor/app/settings/server/SettingsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,25 @@ export class SettingsRegistry {
throw new Error(`Enterprise setting ${_id} is missing the invalidValue option`);
}

const settingFromCodeOverwritten = overwriteSetting(settingFromCode);

const settingStored = this.store.getSetting(_id);
const settingOverwritten = overwriteSetting(settingFromCode);
const settingStoredOverwritten = settingStored && overwriteSetting(settingStored);

try {
validateSetting(settingFromCode._id, settingFromCode.type, settingFromCode.value);
} catch (e) {
IS_DEVELOPMENT && SystemLogger.error(`Invalid setting code ${_id}: ${(e as Error).message}`);
}

const isOverwritten = settingFromCode !== settingOverwritten;
const isOverwritten = settingFromCode !== settingFromCodeOverwritten || (settingStored && settingStored !== settingStoredOverwritten);

const { _id: _, ...settingProps } = settingOverwritten;
const { _id: _, ...settingProps } = settingFromCodeOverwritten;

if (settingStored && !compareSettings(settingStored, settingOverwritten)) {
const { value: _value, ...settingOverwrittenProps } = settingOverwritten;
if (settingStored && !compareSettings(settingStored, settingFromCodeOverwritten)) {
const { value: _value, ...settingOverwrittenProps } = settingFromCodeOverwritten;

const overwrittenKeys = Object.keys(settingOverwritten);
const overwrittenKeys = Object.keys(settingFromCodeOverwritten);
const removedKeys = Object.keys(settingStored).filter((key) => !['_updatedAt'].includes(key) && !overwrittenKeys.includes(key));

this.model.upsert(
Expand All @@ -168,7 +170,7 @@ export class SettingsRegistry {
}

if (settingStored && isOverwritten) {
if (settingStored.value !== settingOverwritten.value) {
if (settingStored.value !== settingFromCodeOverwritten.value) {
this.model.upsert({ _id }, settingProps);
}
return;
Expand All @@ -185,7 +187,7 @@ export class SettingsRegistry {

const settingOverwrittenDefault = overrideSetting(settingFromCode);

const setting = isOverwritten ? settingOverwritten : settingOverwrittenDefault;
const setting = isOverwritten ? settingFromCodeOverwritten : settingOverwrittenDefault;

this.model.insert(setting); // no need to emit unless we remove the oplog

Expand Down

0 comments on commit 0ac8502

Please sign in to comment.