Migrate blacklistUnverifiedDevicesPerRoom

This currently causes a split-brain scenario for the application due to the priority of each level. Granular settings assumes a simple override, however the crypto setting wants per room to be overriden with the global setting, regardless of the room setting. Some additional comments are needed on the intended behaviour.

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-11-04 19:15:55 -07:00
parent c7eee36990
commit cb17c0a379
5 changed files with 52 additions and 45 deletions

View file

@ -55,7 +55,12 @@ module.exports = React.createClass({
}, },
save: function(val = null) { save: function(val = null) {
SettingsStore.setValue(this.props.name, this.props.roomId, this.props.level, val ? val : this.state.value); return SettingsStore.setValue(
this.props.name,
this.props.roomId,
this.props.level,
val ? val : this.state.value
);
}, },
render: function() { render: function() {

View file

@ -363,28 +363,11 @@ module.exports = React.createClass({
}, },
saveBlacklistUnverifiedDevicesPerRoom: function() { saveBlacklistUnverifiedDevicesPerRoom: function() {
if (!this.refs.blacklistUnverified) return; if (!this.refs.blacklistUnverifiedDevices) return;
if (this._isRoomBlacklistUnverified() !== this.refs.blacklistUnverified.checked) { this.refs.blacklistUnverifiedDevices.save().then(() => {
this._setRoomBlacklistUnverified(this.refs.blacklistUnverified.checked); const value = SettingsStore.getValue("blacklistUnverifiedDevices", this.props.room.roomId);
} this.props.room.setBlacklistUnverifiedDevices(value);
}, });
_isRoomBlacklistUnverified: function() {
// TODO: {Travis} Use generic blacklistUnverifiedDevices
const blacklistUnverifiedDevicesPerRoom = SettingsStore.getValue("blacklistUnverifiedDevicesPerRoom");
if (blacklistUnverifiedDevicesPerRoom) {
return blacklistUnverifiedDevicesPerRoom[this.props.room.roomId];
}
return false;
},
_setRoomBlacklistUnverified: function(value) {
// TODO: {Travis} Use generic blacklistUnverifiedDevices
const blacklistUnverifiedDevicesPerRoom = SettingsStore.getValue("blacklistUnverifiedDevicesPerRoom");
blacklistUnverifiedDevicesPerRoom[this.props.room.roomId] = value;
SettingsStore.setValue("blacklistUnverifiedDevicesPerRoom", null, SettingLevel.DEVICE, blacklistUnverifiedDevicesPerRoom);
this.props.room.setBlacklistUnverifiedDevices(value);
}, },
_hasDiff: function(strA, strB) { _hasDiff: function(strA, strB) {
@ -590,20 +573,20 @@ module.exports = React.createClass({
}, },
_renderEncryptionSection: function() { _renderEncryptionSection: function() {
const SettingsFlag = sdk.getComponent("elements.SettingsFlag");
const cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
const roomState = this.props.room.currentState; const roomState = this.props.room.currentState;
const isEncrypted = cli.isRoomEncrypted(this.props.room.roomId); const isEncrypted = cli.isRoomEncrypted(this.props.room.roomId);
const isGlobalBlacklistUnverified = SettingsStore.getValue("blacklistUnverifiedDevices");
const isRoomBlacklistUnverified = this._isRoomBlacklistUnverified();
// TODO: {Travis} Convert to blacklistUnverifiedDevices with SettingsFlag const settings = (
const settings = <SettingsFlag name="blacklistUnverifiedDevices"
<label> level={SettingLevel.ROOM_DEVICE}
<input type="checkbox" ref="blacklistUnverified" roomId={this.props.room.roomId}
defaultChecked={isGlobalBlacklistUnverified || isRoomBlacklistUnverified} manualSave={true}
disabled={isGlobalBlacklistUnverified || (this.refs.encrypt && !this.refs.encrypt.checked)} /> ref="blacklistUnverifiedDevices"
{ _t('Never send encrypted messages to unverified devices in this room from this device') }. />
</label>; );
if (!isEncrypted && roomState.mayClientSendStateEvent("m.room.encryption", cli)) { if (!isEncrypted && roomState.mayClientSendStateEvent("m.room.encryption", cli)) {
return ( return (

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import Promise from 'bluebird';
import SettingsHandler from "./SettingsHandler"; import SettingsHandler from "./SettingsHandler";
/** /**

View file

@ -23,12 +23,30 @@ import SettingsHandler from "./SettingsHandler";
*/ */
export default class RoomDeviceSettingsHandler extends SettingsHandler { export default class RoomDeviceSettingsHandler extends SettingsHandler {
getValue(settingName, roomId) { getValue(settingName, roomId) {
const value = localStorage.getItem(this._getKey(settingName, roomId)); // Special case blacklist setting to use legacy values
if (!value) return null; if (settingName === "blacklistUnverifiedDevices") {
return JSON.parse(value).value; const value = this._read("mx_local_settings");
if (value && value['blacklistUnverifiedDevicesPerRoom']) {
return value['blacklistUnverifiedDevicesPerRoom'][roomId];
}
}
const value = this._read(this._getKey(settingName, roomId));
if (value) return value.value;
return null;
} }
setValue(settingName, roomId, newValue) { setValue(settingName, roomId, newValue) {
// Special case blacklist setting for legacy structure
if (settingName === "blacklistUnverifiedDevices") {
let value = this._read("mx_local_settings");
if (!value) value = {};
if (!value["blacklistUnverifiedDevicesPerRoom"]) value["blacklistUnverifiedDevicesPerRoom"] = {};
value["blacklistUnverifiedDevicesPerRoom"][roomId] = newValue;
localStorage.setItem("mx_local_settings", JSON.stringify(value));
return Promise.resolve();
}
if (newValue === null) { if (newValue === null) {
localStorage.removeItem(this._getKey(settingName, roomId)); localStorage.removeItem(this._getKey(settingName, roomId));
} else { } else {
@ -47,6 +65,12 @@ export default class RoomDeviceSettingsHandler extends SettingsHandler {
return localStorage !== undefined && localStorage !== null; return localStorage !== undefined && localStorage !== null;
} }
_read(key) {
const rawValue = localStorage.getItem(key);
if (!rawValue) return null;
return JSON.parse(rawValue);
}
_getKey(settingName, roomId) { _getKey(settingName, roomId) {
return "mx_setting_" + settingName + "_" + roomId; return "mx_setting_" + settingName + "_" + roomId;
} }

View file

@ -188,16 +188,12 @@ export const SETTINGS = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: 200, default: 200,
}, },
"blacklistUnverifiedDevicesPerRoom": {
// TODO: {Travis} Write a migration path to support blacklistUnverifiedDevices
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
displayName: _td('Never send encrypted messages to unverified devices from this device'),
default: {},
},
"blacklistUnverifiedDevices": { "blacklistUnverifiedDevices": {
// TODO: {Travis} Write a migration path to support blacklistUnverifiedDevices
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
displayName: _td('Never send encrypted messages to unverified devices from this device'), displayName: {
"default": _td('Never send encrypted messages to unverified devices from this device'),
"room-device": _td('Never send encrypted messages to unverified devices in this room from this device'),
},
default: false, default: false,
}, },
"urlPreviewsEnabled": { "urlPreviewsEnabled": {