Merge branch 't3chguy/fix/15182' into travis/uifeat/paranoia

This commit is contained in:
Travis Ralston 2020-09-18 11:13:43 -06:00
commit 72f53e2cae
6 changed files with 31 additions and 9 deletions

View file

@ -23,7 +23,6 @@ import Field from "../../../elements/Field";
import * as sdk from "../../../../.."; import * as sdk from "../../../../..";
import PlatformPeg from "../../../../../PlatformPeg"; import PlatformPeg from "../../../../../PlatformPeg";
import {SettingLevel} from "../../../../../settings/SettingLevel"; import {SettingLevel} from "../../../../../settings/SettingLevel";
import {UIFeature} from "../../../../../settings/UIFeature";
export default class PreferencesUserSettingsTab extends React.Component { export default class PreferencesUserSettingsTab extends React.Component {
static ROOM_LIST_SETTINGS = [ static ROOM_LIST_SETTINGS = [
@ -138,12 +137,10 @@ export default class PreferencesUserSettingsTab extends React.Component {
}; };
_renderGroup(settingIds) { _renderGroup(settingIds) {
if (!SettingsStore.getValue(UIFeature.URLPreviews)) {
settingIds = settingIds.filter(i => i !== 'urlPreviewsEnabled');
}
const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag"); const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag");
return settingIds.map(i => <SettingsFlag key={i} name={i} level={SettingLevel.ACCOUNT} />); return settingIds.filter(SettingsStore.isEnabled).map(i => {
return <SettingsFlag key={i} name={i} level={SettingLevel.ACCOUNT} />;
});
} }
render() { render() {

View file

@ -332,6 +332,8 @@ export const SETTINGS: {[setting: string]: ISetting} = {
displayName: _td('Enable Community Filter Panel'), displayName: _td('Enable Community Filter Panel'),
default: true, default: true,
invertedSettingName: 'TagPanel.disableTagPanel', invertedSettingName: 'TagPanel.disableTagPanel',
// We force the value to true because the invertedSettingName causes it to flip
controller: new UIFeatureController(UIFeature.Communities, true),
}, },
"theme": { "theme": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS, supportedLevels: LEVELS_ACCOUNT_SETTINGS,
@ -659,6 +661,12 @@ export const SETTINGS: {[setting: string]: ISetting} = {
[UIFeature.Flair]: { [UIFeature.Flair]: {
supportedLevels: LEVELS_UI_FEATURE, supportedLevels: LEVELS_UI_FEATURE,
default: true, default: true,
// Disable Flair when Communities are disabled
controller: new UIFeatureController(UIFeature.Communities),
},
[UIFeature.Communities]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
}, },
[UIFeature.AdvancedSettings]: { [UIFeature.AdvancedSettings]: {
supportedLevels: LEVELS_UI_FEATURE, supportedLevels: LEVELS_UI_FEATURE,

View file

@ -257,6 +257,11 @@ export default class SettingsStore {
return SETTINGS[settingName].isFeature; return SETTINGS[settingName].isFeature;
} }
public static isEnabled(settingName: string) {
if (!SETTINGS[settingName]) return false;
return SETTINGS[settingName].controller ? !SETTINGS[settingName].controller.settingDisabled : true;
}
/** /**
* Gets the value of a setting. The room ID is optional if the setting is not to * Gets the value of a setting. The room ID is optional if the setting is not to
* be applied to any particular room, otherwise it should be supplied. * be applied to any particular room, otherwise it should be supplied.

View file

@ -28,5 +28,6 @@ export enum UIFeature {
IdentityServer = "UIFeature.identityServer", IdentityServer = "UIFeature.identityServer",
ThirdPartyID = "UIFeature.thirdPartyId", ThirdPartyID = "UIFeature.thirdPartyId",
Flair = "UIFeature.flair", Flair = "UIFeature.flair",
Communities = "UIFeature.communities",
AdvancedSettings = "UIFeature.advancedSettings", AdvancedSettings = "UIFeature.advancedSettings",
} }

View file

@ -55,4 +55,11 @@ export default abstract class SettingController {
public onChange(level: SettingLevel, roomId: string, newValue: any) { public onChange(level: SettingLevel, roomId: string, newValue: any) {
// do nothing by default // do nothing by default
} }
/**
* Gets whether the setting has been disabled due to this controller.
*/
public get settingDisabled() {
return false;
}
} }

View file

@ -26,7 +26,7 @@ import SettingsStore from "../SettingsStore";
* Settings using this controller are assumed to return `false` when disabled. * Settings using this controller are assumed to return `false` when disabled.
*/ */
export default class UIFeatureController extends SettingController { export default class UIFeatureController extends SettingController {
public constructor(private uiFeatureName: string) { public constructor(private uiFeatureName: string, private forcedValue = false) {
super(); super();
} }
@ -36,10 +36,14 @@ export default class UIFeatureController extends SettingController {
calculatedValue: any, calculatedValue: any,
calculatedAtLevel: SettingLevel, calculatedAtLevel: SettingLevel,
): any { ): any {
if (!SettingsStore.getValue(this.uiFeatureName)) { if (this.settingDisabled) {
// per the docs: we force a disabled state when the feature isn't active // per the docs: we force a disabled state when the feature isn't active
return false; return this.forcedValue;
} }
return null; // no override return null; // no override
} }
public get settingDisabled(): boolean {
return !SettingsStore.getValue(this.uiFeatureName);
}
} }