Merge pull request #5544 from matrix-org/jryans/guest-allow-widget
Use device storage for allowed widgets if account data not supported
This commit is contained in:
commit
266162fa32
7 changed files with 35 additions and 7 deletions
|
@ -26,7 +26,6 @@ import {WidgetMessagingStore} from "../../../stores/widgets/WidgetMessagingStore
|
|||
import RoomContext from "../../../contexts/RoomContext";
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import {SettingLevel} from "../../../settings/SettingLevel";
|
||||
import Modal from "../../../Modal";
|
||||
import QuestionDialog from "../dialogs/QuestionDialog";
|
||||
import {WidgetType} from "../../../widgets/WidgetType";
|
||||
|
@ -127,7 +126,8 @@ const WidgetContextMenu: React.FC<IProps> = ({
|
|||
console.info("Revoking permission for widget to load: " + app.eventId);
|
||||
const current = SettingsStore.getValue("allowedWidgets", roomId);
|
||||
current[app.eventId] = false;
|
||||
SettingsStore.setValue("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, current).catch(err => {
|
||||
const level = SettingsStore.firstSupportedLevel("allowedWidgets");
|
||||
SettingsStore.setValue("allowedWidgets", roomId, level, current).catch(err => {
|
||||
console.error(err);
|
||||
// We don't really need to do anything about this - the user will just hit the button again.
|
||||
});
|
||||
|
|
|
@ -33,7 +33,6 @@ import SettingsStore from "../../../settings/SettingsStore";
|
|||
import {aboveLeftOf, ContextMenuButton} from "../../structures/ContextMenu";
|
||||
import PersistedElement, {getPersistKey} from "./PersistedElement";
|
||||
import {WidgetType} from "../../../widgets/WidgetType";
|
||||
import {SettingLevel} from "../../../settings/SettingLevel";
|
||||
import {StopGapWidget} from "../../../stores/widgets/StopGapWidget";
|
||||
import {ElementWidgetActions} from "../../../stores/widgets/ElementWidgetActions";
|
||||
import {MatrixCapabilities} from "matrix-widget-api";
|
||||
|
@ -240,7 +239,8 @@ export default class AppTile extends React.Component {
|
|||
console.info("Granting permission for widget to load: " + this.props.app.eventId);
|
||||
const current = SettingsStore.getValue("allowedWidgets", roomId);
|
||||
current[this.props.app.eventId] = true;
|
||||
SettingsStore.setValue("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, current).then(() => {
|
||||
const level = SettingsStore.firstSupportedLevel("allowedWidgets");
|
||||
SettingsStore.setValue("allowedWidgets", roomId, level, current).then(() => {
|
||||
this.setState({hasPermissionToLoad: true});
|
||||
|
||||
// Fetch a token for the integration manager, now that we're allowed to
|
||||
|
|
|
@ -421,7 +421,8 @@ export const SETTINGS: {[setting: string]: ISetting} = {
|
|||
default: true,
|
||||
},
|
||||
"allowedWidgets": {
|
||||
supportedLevels: [SettingLevel.ROOM_ACCOUNT],
|
||||
supportedLevels: [SettingLevel.ROOM_ACCOUNT, SettingLevel.ROOM_DEVICE],
|
||||
supportedLevelsAreOrdered: true,
|
||||
default: {}, // none allowed
|
||||
},
|
||||
"analyticsOptIn": {
|
||||
|
|
|
@ -467,6 +467,32 @@ export default class SettingsStore {
|
|||
return LEVEL_HANDLERS[level].isSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the first supported level out of all the levels that can be used for a
|
||||
* specific setting.
|
||||
* @param {string} settingName The setting name.
|
||||
* @return {SettingLevel}
|
||||
*/
|
||||
public static firstSupportedLevel(settingName: string): SettingLevel {
|
||||
// Verify that the setting is actually a setting
|
||||
const setting = SETTINGS[settingName];
|
||||
if (!setting) {
|
||||
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
|
||||
}
|
||||
|
||||
const levelOrder = (setting.supportedLevelsAreOrdered ? setting.supportedLevels : LEVEL_ORDER);
|
||||
if (!levelOrder.includes(SettingLevel.DEFAULT)) levelOrder.push(SettingLevel.DEFAULT); // always include default
|
||||
|
||||
const handlers = SettingsStore.getHandlers(settingName);
|
||||
|
||||
for (const level of levelOrder) {
|
||||
const handler = handlers[level];
|
||||
if (!handler) continue;
|
||||
return level;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging function for reading explicit setting values without going through the
|
||||
* complicated/biased functions in the SettingsStore. This will print information to
|
||||
|
|
|
@ -169,7 +169,7 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
|
||||
public isSupported(): boolean {
|
||||
const cli = MatrixClientPeg.get();
|
||||
return cli !== undefined && cli !== null;
|
||||
return cli !== undefined && cli !== null && !cli.isGuest();
|
||||
}
|
||||
|
||||
private getSettings(eventType = "im.vector.web.settings"): any { // TODO: [TS] Types on return
|
||||
|
|
|
@ -129,7 +129,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
|
|||
|
||||
public isSupported(): boolean {
|
||||
const cli = MatrixClientPeg.get();
|
||||
return cli !== undefined && cli !== null;
|
||||
return cli !== undefined && cli !== null && !cli.isGuest();
|
||||
}
|
||||
|
||||
private getSettings(roomId: string, eventType = "im.vector.web.settings"): any { // TODO: [TS] Type return
|
||||
|
|
|
@ -222,6 +222,7 @@ describe("<TextualBody />", () => {
|
|||
getRoom: () => mkStubRoom("room_id"),
|
||||
getAccountData: () => undefined,
|
||||
getUrlPreview: (url) => new Promise(() => {}),
|
||||
isGuest: () => false,
|
||||
};
|
||||
|
||||
const ev = mkEvent({
|
||||
|
|
Loading…
Reference in a new issue