From 5f3df579133e3e3e54eb4e428f306f57f71b21f1 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 2 Feb 2023 18:17:08 +0000 Subject: [PATCH 1/2] Enable Sign in with QR section in Settings where the Homeserver supports it --- .../views/settings/devices/LoginWithQRSection.tsx | 7 ++----- .../settings/tabs/user/SecurityUserSettingsTab.tsx | 7 ++----- .../views/settings/tabs/user/SessionManagerTab.tsx | 7 ++----- src/settings/Settings.tsx | 10 ---------- .../settings/devices/LoginWithQRSection-test.tsx | 14 ++------------ .../__snapshots__/LoginWithQRSection-test.tsx.snap | 6 ++---- .../tabs/user/SecurityUserSettingsTab-test.tsx | 13 +------------ .../settings/tabs/user/SessionManagerTab-test.tsx | 13 +------------ 8 files changed, 12 insertions(+), 65 deletions(-) diff --git a/src/components/views/settings/devices/LoginWithQRSection.tsx b/src/components/views/settings/devices/LoginWithQRSection.tsx index a07a7a9722c..0faa3913c80 100644 --- a/src/components/views/settings/devices/LoginWithQRSection.tsx +++ b/src/components/views/settings/devices/LoginWithQRSection.tsx @@ -20,7 +20,6 @@ import type { IServerVersions } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../../languageHandler"; import AccessibleButton from "../../elements/AccessibleButton"; import SettingsSubsection from "../shared/SettingsSubsection"; -import SettingsStore from "../../../../settings/SettingsStore"; interface IProps { onShowQr: () => void; @@ -33,12 +32,10 @@ export default class LoginWithQRSection extends React.Component { } public render(): JSX.Element | null { + // Needs server support for MSC3882 and MSC3886: const msc3882Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3882"]; const msc3886Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3886"]; - - // Needs to be enabled as a feature + server support MSC3886 or have a default rendezvous server configured: - const offerShowQr = - SettingsStore.getValue("feature_qr_signin_reciprocate_show") && msc3882Supported && msc3886Supported; // We don't support configuration of a fallback at the moment so we just check the MSCs + const offerShowQr = msc3882Supported && msc3886Supported; // don't show anything if no method is available if (!offerShowQr) { diff --git a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx index 07e05ef10ce..2d2a086c615 100644 --- a/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/SecurityUserSettingsTab.tsx @@ -381,7 +381,6 @@ export default class SecurityUserSettingsTab extends React.Component
{_t("Where you're signed in")}
@@ -394,15 +393,13 @@ export default class SecurityUserSettingsTab extends React.Component - {showQrCodeEnabled ? ( - - ) : null} + ); const client = MatrixClientPeg.get(); - if (showQrCodeEnabled && this.state.showLoginWithQR) { + if (this.state.showLoginWithQR) { return (
{ const [signInWithQrMode, setSignInWithQrMode] = useState(); - const showQrCodeEnabled = SettingsStore.getValue("feature_qr_signin_reciprocate_show"); - const onQrFinish = useCallback(() => { setSignInWithQrMode(null); }, [setSignInWithQrMode]); @@ -222,7 +219,7 @@ const SessionManagerTab: React.FC = () => { setSignInWithQrMode(Mode.Show); }, [setSignInWithQrMode]); - if (showQrCodeEnabled && signInWithQrMode) { + if (signInWithQrMode) { return ; } @@ -282,7 +279,7 @@ const SessionManagerTab: React.FC = () => { /> )} - {showQrCodeEnabled ? : null} + ); }; diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 8fd10429f45..960bc695ffa 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -496,16 +496,6 @@ export const SETTINGS: { [setting: string]: ISetting } = { ), }, }, - "feature_qr_signin_reciprocate_show": { - isFeature: true, - labsGroup: LabGroup.Experimental, - supportedLevels: LEVELS_FEATURE, - displayName: _td( - "Allow a QR code to be shown in session manager to sign in another device " + - "(requires compatible homeserver)", - ), - default: false, - }, "feature_rust_crypto": { // use the rust matrix-sdk-crypto-js for crypto. isFeature: true, diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index df71544b321..2f272acdec5 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -21,8 +21,6 @@ import React from "react"; import LoginWithQRSection from "../../../../../src/components/views/settings/devices/LoginWithQRSection"; import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg"; -import { SettingLevel } from "../../../../../src/settings/SettingLevel"; -import SettingsStore from "../../../../../src/settings/SettingsStore"; function makeClient() { return mocked({ @@ -67,22 +65,14 @@ describe("", () => { expect(container).toMatchSnapshot(); }); - it("feature enabled", async () => { - await SettingsStore.setValue("feature_qr_signin_reciprocate_show", null, SettingLevel.DEVICE, true); - const { container } = render(getComponent()); - expect(container).toMatchSnapshot(); - }); - - it("only feature + MSC3882 enabled", async () => { - await SettingsStore.setValue("feature_qr_signin_reciprocate_show", null, SettingLevel.DEVICE, true); + it("only MSC3882 enabled", async () => { const { container } = render(getComponent({ versions: makeVersions({ "org.matrix.msc3882": true }) })); expect(container).toMatchSnapshot(); }); }); describe("should render panel", () => { - it("enabled by feature + MSC3882 + MSC3886", async () => { - await SettingsStore.setValue("feature_qr_signin_reciprocate_show", null, SettingLevel.DEVICE, true); + it("MSC3882 + MSC3886", async () => { const { container } = render( getComponent({ versions: makeVersions({ diff --git a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap index 2cf0d24cc6c..ccf2e4ccb51 100644 --- a/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap +++ b/test/components/views/settings/devices/__snapshots__/LoginWithQRSection-test.tsx.snap @@ -1,12 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` should not render feature enabled 1`] = `
`; - exports[` should not render no support at all 1`] = `
`; -exports[` should not render only feature + MSC3882 enabled 1`] = `
`; +exports[` should not render only MSC3882 enabled 1`] = `
`; -exports[` should render panel enabled by feature + MSC3882 + MSC3886 1`] = ` +exports[` should render panel MSC3882 + MSC3886 1`] = `
", () => { expect(queryByTestId("devices-section")).toBeFalsy(); }); - it("does not render qr code login section when disabled", () => { - settingsValueSpy.mockReturnValue(false); - const { queryByText } = render(getComponent()); - - expect(settingsValueSpy).toHaveBeenCalledWith("feature_qr_signin_reciprocate_show"); - - expect(queryByText("Sign in with QR code")).toBeFalsy(); - }); - - it("renders qr code login section when enabled", async () => { - settingsValueSpy.mockImplementation((settingName) => settingName === "feature_qr_signin_reciprocate_show"); + it("renders qr code login section", async () => { const { getByText } = render(getComponent()); // wait for versions call to settle @@ -99,7 +89,6 @@ describe("", () => { }); it("enters qr code login section when show QR code button clicked", async () => { - settingsValueSpy.mockImplementation((settingName) => settingName === "feature_qr_signin_reciprocate_show"); const { getByText, getByTestId } = render(getComponent()); // wait for versions call to settle await flushPromises(); diff --git a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx index 2baadc1a6cb..6356f652b34 100644 --- a/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx +++ b/test/components/views/settings/tabs/user/SessionManagerTab-test.tsx @@ -1351,17 +1351,7 @@ describe("", () => { }); }); - it("does not render qr code login section when disabled", () => { - settingsValueSpy.mockReturnValue(false); - const { queryByText } = render(getComponent()); - - expect(settingsValueSpy).toHaveBeenCalledWith("feature_qr_signin_reciprocate_show"); - - expect(queryByText("Sign in with QR code")).toBeFalsy(); - }); - - it("renders qr code login section when enabled", async () => { - settingsValueSpy.mockImplementation((settingName) => settingName === "feature_qr_signin_reciprocate_show"); + it("renders qr code login section", async () => { const { getByText } = render(getComponent()); // wait for versions call to settle @@ -1371,7 +1361,6 @@ describe("", () => { }); it("enters qr code login section when show QR code button clicked", async () => { - settingsValueSpy.mockImplementation((settingName) => settingName === "feature_qr_signin_reciprocate_show"); const { getByText, getByTestId } = render(getComponent()); // wait for versions call to settle await flushPromises(); From dd97109586c75457b4fe9bd6b015a1253070aff1 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 3 Feb 2023 09:31:08 +0000 Subject: [PATCH 2/2] i18n fix --- src/i18n/strings/en_EN.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8cdb69d5852..3411316ebdf 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -977,7 +977,6 @@ "New session manager": "New session manager", "Have greater visibility and control over all your sessions.": "Have greater visibility and control over all your sessions.", "Our new sessions manager provides better visibility of all your sessions, and greater control over them including the ability to remotely toggle push notifications.": "Our new sessions manager provides better visibility of all your sessions, and greater control over them including the ability to remotely toggle push notifications.", - "Allow a QR code to be shown in session manager to sign in another device (requires compatible homeserver)": "Allow a QR code to be shown in session manager to sign in another device (requires compatible homeserver)", "Rust cryptography implementation": "Rust cryptography implementation", "Under active development. Can currently only be enabled via config.json": "Under active development. Can currently only be enabled via config.json", "Font size": "Font size",