Merge pull request #3549 from matrix-org/jryans/disconnect-dead-is

Show warning dialog when changing unreachable IS
This commit is contained in:
J. Ryan Stinnett 2019-10-18 16:53:25 +01:00 committed by GitHub
commit 7ac14e48dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 26 deletions

View file

@ -28,6 +28,9 @@ import {SERVICE_TYPES} from "matrix-js-sdk";
import {abbreviateUrl, unabbreviateUrl} from "../../../utils/UrlUtils"; import {abbreviateUrl, unabbreviateUrl} from "../../../utils/UrlUtils";
import { getDefaultIdentityServerUrl } from '../../../utils/IdentityServerUtils'; import { getDefaultIdentityServerUrl } from '../../../utils/IdentityServerUtils';
// We'll wait up to this long when checking for 3PID bindings on the IS.
const REACHABILITY_TIMEOUT = 10000; // ms
/** /**
* Check an IS URL is valid, including liveness check * Check an IS URL is valid, including liveness check
* *
@ -249,20 +252,61 @@ export default class SetIdServer extends React.Component {
}; };
async _showServerChangeWarning({ title, unboundMessage, button }) { async _showServerChangeWarning({ title, unboundMessage, button }) {
const threepids = await getThreepidsWithBindStatus(MatrixClientPeg.get()); const { currentClientIdServer } = this.state;
let threepids = [];
let currentServerReachable = true;
try {
threepids = await Promise.race([
getThreepidsWithBindStatus(MatrixClientPeg.get()),
new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error("Timeout attempting to reach identity server"));
}, REACHABILITY_TIMEOUT);
}),
]);
} catch (e) {
currentServerReachable = false;
console.warn(
`Unable to reach identity server at ${currentClientIdServer} to check ` +
`for 3PIDs during IS change flow`,
);
console.warn(e);
}
const boundThreepids = threepids.filter(tp => tp.bound); const boundThreepids = threepids.filter(tp => tp.bound);
let message; let message;
let danger = false; let danger = false;
if (boundThreepids.length) { const messageElements = {
idserver: sub => <b>{abbreviateUrl(currentClientIdServer)}</b>,
b: sub => <b>{sub}</b>,
};
if (!currentServerReachable) {
message = <div>
<p>{_t(
"You should <b>remove your personal data</b> from identity server " +
"<idserver /> before disconnecting. Unfortunately, identity server " +
"<idserver /> is currently offline or cannot be reached.",
{}, messageElements,
)}</p>
<p>{_t("You should:")}</p>
<ul>
<li>{_t(
"check your browser plugins for anything that might block " +
"the identity server (such as Privacy Badger)",
)}</li>
<li>{_t("contact the administrators of identity server <idserver />", {}, {
idserver: messageElements.idserver,
})}</li>
<li>{_t("wait and try again later")}</li>
</ul>
</div>;
danger = true;
button = _t("Disconnect anyway");
} else if (boundThreepids.length) {
message = <div> message = <div>
<p>{_t( <p>{_t(
"You are still <b>sharing your personal data</b> on the identity " + "You are still <b>sharing your personal data</b> on the identity " +
"server <idserver />.", {}, "server <idserver />.", {}, messageElements,
{
idserver: sub => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b>,
b: sub => <b>{sub}</b>,
},
)}</p> )}</p>
<p>{_t( <p>{_t(
"We recommend that you remove your email addresses and phone numbers " + "We recommend that you remove your email addresses and phone numbers " +

View file

@ -102,7 +102,17 @@ export default class GeneralUserSettingsTab extends React.Component {
// Need to get 3PIDs generally for Account section and possibly also for // Need to get 3PIDs generally for Account section and possibly also for
// Discovery (assuming we have an IS and terms are agreed). // Discovery (assuming we have an IS and terms are agreed).
const threepids = await getThreepidsWithBindStatus(cli); let threepids = [];
try {
threepids = await getThreepidsWithBindStatus(cli);
} catch (e) {
const idServerUrl = MatrixClientPeg.get().getIdentityServerUrl();
console.warn(
`Unable to reach identity server at ${idServerUrl} to check ` +
`for 3PIDs bindings in Settings`,
);
console.warn(e);
}
this.setState({ emails: threepids.filter((a) => a.medium === 'email') }); this.setState({ emails: threepids.filter((a) => a.medium === 'email') });
this.setState({ msisdns: threepids.filter((a) => a.medium === 'msisdn') }); this.setState({ msisdns: threepids.filter((a) => a.medium === 'msisdn') });
} }
@ -115,16 +125,18 @@ export default class GeneralUserSettingsTab extends React.Component {
// By starting the terms flow we get the logic for checking which terms the user has signed // By starting the terms flow we get the logic for checking which terms the user has signed
// for free. So we might as well use that for our own purposes. // for free. So we might as well use that for our own purposes.
const idServerUrl = MatrixClientPeg.get().getIdentityServerUrl();
const authClient = new IdentityAuthClient(); const authClient = new IdentityAuthClient();
const idAccessToken = await authClient.getAccessToken({ check: false }); const idAccessToken = await authClient.getAccessToken({ check: false });
startTermsFlow([new Service( try {
await startTermsFlow([new Service(
SERVICE_TYPES.IS, SERVICE_TYPES.IS,
MatrixClientPeg.get().getIdentityServerUrl(), idServerUrl,
idAccessToken, idAccessToken,
)], (policiesAndServices, agreedUrls, extraClassNames) => { )], (policiesAndServices, agreedUrls, extraClassNames) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.setState({ this.setState({
idServerName: abbreviateUrl(MatrixClientPeg.get().getIdentityServerUrl()), idServerName: abbreviateUrl(idServerUrl),
requiredPolicyInfo: { requiredPolicyInfo: {
hasTerms: true, hasTerms: true,
policiesAndServices, policiesAndServices,
@ -133,14 +145,20 @@ export default class GeneralUserSettingsTab extends React.Component {
}, },
}); });
}); });
}).then(() => { });
// User accepted all terms // User accepted all terms
this.setState({ this.setState({
requiredPolicyInfo: { requiredPolicyInfo: {
hasTerms: false, hasTerms: false,
}, },
}); });
}); } catch (e) {
console.warn(
`Unable to reach identity server at ${idServerUrl} to check ` +
`for terms in Settings`,
);
console.warn(e);
}
} }
_onLanguageChange = (newLanguage) => { _onLanguageChange = (newLanguage) => {

View file

@ -568,9 +568,14 @@
"Disconnect identity server": "Disconnect identity server", "Disconnect identity server": "Disconnect identity server",
"Disconnect from the identity server <idserver />?": "Disconnect from the identity server <idserver />?", "Disconnect from the identity server <idserver />?": "Disconnect from the identity server <idserver />?",
"Disconnect": "Disconnect", "Disconnect": "Disconnect",
"You should <b>remove your personal data</b> from identity server <idserver /> before disconnecting. Unfortunately, identity server <idserver /> is currently offline or cannot be reached.": "You should <b>remove your personal data</b> from identity server <idserver /> before disconnecting. Unfortunately, identity server <idserver /> is currently offline or cannot be reached.",
"You should:": "You should:",
"check your browser plugins for anything that might block the identity server (such as Privacy Badger)": "check your browser plugins for anything that might block the identity server (such as Privacy Badger)",
"contact the administrators of identity server <idserver />": "contact the administrators of identity server <idserver />",
"wait and try again later": "wait and try again later",
"Disconnect anyway": "Disconnect anyway",
"You are still <b>sharing your personal data</b> on the identity server <idserver />.": "You are still <b>sharing your personal data</b> on the identity server <idserver />.", "You are still <b>sharing your personal data</b> on the identity server <idserver />.": "You are still <b>sharing your personal data</b> on the identity server <idserver />.",
"We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.": "We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.", "We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.": "We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.",
"Disconnect anyway": "Disconnect anyway",
"Go back": "Go back", "Go back": "Go back",
"Identity Server (%(server)s)": "Identity Server (%(server)s)", "Identity Server (%(server)s)": "Identity Server (%(server)s)",
"You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.", "You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.",