Add a prompt when interacting with an identity server without terms

This adds a prompt whenever we are about to perform some action on a default identity
server (from homeserver .well-known or Riot app config) without terms. This
allows the user to abort or trust the server (storing it in account data).

Fixes https://github.com/vector-im/riot-web/issues/10557
This commit is contained in:
J. Ryan Stinnett 2019-10-31 11:58:31 +00:00
parent 54cea6a5e3
commit 0fc5108817
4 changed files with 81 additions and 19 deletions

View file

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { SERVICE_TYPES } from 'matrix-js-sdk';
import SdkConfig from '../SdkConfig';
import MatrixClientPeg from '../MatrixClientPeg';
@ -28,3 +29,24 @@ export function useDefaultIdentityServer() {
base_url: url,
});
}
export async function doesIdentityServerHaveTerms(fullUrl) {
let terms;
try {
terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
} catch (e) {
console.error(e);
if (e.cors === "rejected" || e.httpStatus === 404) {
terms = null;
} else {
throw e;
}
}
return terms && terms["policies"] && (Object.keys(terms["policies"]).length > 0);
}
export function doesAccountDataHaveIdentityServer() {
const event = MatrixClientPeg.get().getAccountData("m.identity_server");
return event && event.getContent() && event.getContent()['base_url'];
}