This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 830
Fix config override of other settings levels #12593
Merged
langleyd
merged 19 commits into
develop
from
langleyd/fix_config_override_setting_value
Jun 14, 2024
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
86e1914
Make config override other settings levels and add tests
langleyd c65c6ef
fix documentation
langleyd 845a2c3
lint
langleyd c7bda77
Use a const for finalLevel.
langleyd c63522a
respect the explicit parameter
langleyd 871c0b6
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd 1147afb
Use supportedLevelsAreOrdered for config overrides rather than a sepa…
langleyd eeb2795
Fix typos
langleyd 53bc93d
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd c4e8931
Fix mock in UserSetttingsDialog-test
langleyd 0f7cf3c
Merge branch 'langleyd/fix_config_override_setting_value' of https://…
langleyd ee18a7d
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd bedf253
Special case disabling of setting tos use config overrides.
langleyd d90c36c
Merge branch 'langleyd/fix_config_override_setting_value' of https://…
langleyd 6fc476b
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd d8955de
remove logs
langleyd 49c65cd
Merge branch 'langleyd/fix_config_override_setting_value' of https://…
langleyd 0fa1b98
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd 2350c01
Merge branch 'develop' into langleyd/fix_config_override_setting_value
langleyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,41 +505,70 @@ export default class SettingsStore { | |
* set for a particular room, otherwise it should be supplied. | ||
* | ||
* This takes into account both the value of {@link SettingController#settingDisabled} of the | ||
* `SettingController`, if any; and, for settings where {@link IBaseSetting#configDisablesSetting} is true, | ||
* whether the setting has been given a value in `config.json`. | ||
* `SettingController`, if any; and, for settings where {@link IBaseSetting#supportedLevelsAreOrdered} is true, | ||
* checks whether a level of higher precedence is set. | ||
* | ||
* Typically, if the user cannot set the setting, it should be hidden, to declutter the UI; | ||
* however some settings (typically, the labs flags) are exposed but greyed out, to unveil | ||
* what features are available with the right server support. | ||
* | ||
* @param {string} settingName The name of the setting to check. | ||
* @param {String} roomId The room ID to check in, may be null. | ||
* @param {SettingLevel} level The level to | ||
* check at. | ||
* @param {SettingLevel} level The level to check at. | ||
* @return {boolean} True if the user may set the setting, false otherwise. | ||
*/ | ||
public static canSetValue(settingName: string, roomId: string | null, level: SettingLevel): boolean { | ||
const setting = SETTINGS[settingName]; | ||
// Verify that the setting is actually a setting | ||
if (!SETTINGS[settingName]) { | ||
if (!setting) { | ||
throw new Error("Setting '" + settingName + "' does not appear to be a setting."); | ||
} | ||
|
||
if (SETTINGS[settingName].controller?.settingDisabled) { | ||
if (setting.controller?.settingDisabled) { | ||
return false; | ||
} | ||
|
||
// For some config settings (mostly: non-beta features), a value in config.json overrides the local setting | ||
// (ie: we force them as enabled or disabled). | ||
if (SETTINGS[settingName]?.configDisablesSetting) { | ||
const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true); | ||
if (configVal === true || configVal === false) return false; | ||
// (ie: we force them as enabled or disabled). In this case we should not let the user change the setting. | ||
if ( | ||
setting?.supportedLevelsAreOrdered && | ||
SettingsStore.settingIsOveriddenAtConfigLevel(settingName, roomId, level) | ||
) { | ||
return false; | ||
} | ||
|
||
const handler = SettingsStore.getHandler(settingName, level); | ||
if (!handler) return false; | ||
return handler.canSetValue(settingName, roomId); | ||
} | ||
|
||
/** | ||
* Determines if the setting at the specified level is overidden by one at a config level. | ||
* @param settingName The name of the setting to check. | ||
* @param roomId The room ID to check in, may be null. | ||
* @param level The level to check at. | ||
* @returns | ||
*/ | ||
public static settingIsOveriddenAtConfigLevel( | ||
settingName: string, | ||
roomId: string | null, | ||
level: SettingLevel, | ||
): boolean { | ||
const setting = SETTINGS[settingName]; | ||
const levelOrders = getLevelOrder(setting); | ||
const configIndex = levelOrders.indexOf(SettingLevel.CONFIG); | ||
const levelIndex = levelOrders.indexOf(level); | ||
console.log("settingIsOveriddenAtConfigLevel"); | ||
console.log(settingName); | ||
console.log(configIndex); | ||
console.log(levelIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should probably not land |
||
if (configIndex === -1 || levelIndex === -1 || configIndex >= levelIndex) { | ||
return false; | ||
} | ||
const configVal = SettingsStore.getValueAt(SettingLevel.CONFIG, settingName, roomId, true, true); | ||
return configVal === true || configVal === false; | ||
} | ||
|
||
/** | ||
* Determines if the given level is supported on this device. | ||
* @param {SettingLevel} level The level | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need the
!!
here given its a booleanThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is identified by Sonar: https://sonarcloud.io/project/issues?id=matrix-react-sdk&pullRequest=12593&resolved=false&sinceLeakPeriod=true