Add .well-known config option to force disable encryption on room creation (#11120)

* force disable encryption on room creation

* test allowChangingEncryption

* move into utils/room directory

* tests

* unit test CreateRoomDialog

* remove debug

* wait for constructor promises to settle

* test case for force_disable

* comment

* set forced value after resolving checkUserIsAllowedToChangeEncryption

* tidy and comments

* use label text in test
This commit is contained in:
Kerry 2023-06-22 09:50:01 +12:00 committed by GitHub
parent 9d9c55d92e
commit a692fe2181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 375 additions and 9 deletions

View file

@ -24,7 +24,7 @@ import SdkConfig from "../../../SdkConfig";
import withValidation, { IFieldState, IValidationResult } from "../elements/Validation";
import { _t } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { IOpts } from "../../../createRoom";
import { checkUserIsAllowedToChangeEncryption, IOpts } from "../../../createRoom";
import Field from "../elements/Field";
import RoomAliasField from "../elements/RoomAliasField";
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
@ -86,11 +86,15 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
detailsOpen: false,
noFederate: SdkConfig.get().default_federate === false,
nameIsValid: false,
canChangeEncryption: true,
canChangeEncryption: false,
};
cli.doesServerForceEncryptionForPreset(Preset.PrivateChat).then((isForced) =>
this.setState({ canChangeEncryption: !isForced }),
checkUserIsAllowedToChangeEncryption(cli, Preset.PrivateChat).then(({ allowChange, forcedValue }) =>
this.setState((state) => ({
canChangeEncryption: allowChange,
// override with forcedValue if it is set
isEncrypted: forcedValue ?? state.isEncrypted,
})),
);
}
@ -107,8 +111,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
const { alias } = this.state;
createOpts.room_alias_name = alias.substring(1, alias.indexOf(":"));
} else {
// If we cannot change encryption we pass `true` for safety, the server should automatically do this for us.
opts.encryption = this.state.canChangeEncryption ? this.state.isEncrypted : true;
opts.encryption = this.state.isEncrypted;
}
if (this.state.topic) {