From 23162c86253cc5aca18f2a9a954ab56736055991 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 9 Oct 2017 18:50:08 -0600 Subject: [PATCH] Support third party integration managers in AppPermission Alternative integration managers may wish to also wrap widgets to supply a better user experience. With the previous code, it was not possible to use the integrations_widgets_urls configuration option (described in AppTile). AppPermission should use the same logic to determine if a widget is being wrapped, so it can display a helpful URL for the user (instead of the wrapper URL). Signed-off-by: Travis Ralston --- .../views/elements/AppPermission.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/views/elements/AppPermission.js b/src/components/views/elements/AppPermission.js index c45006be3a..0ce7c2a45e 100644 --- a/src/components/views/elements/AppPermission.js +++ b/src/components/views/elements/AppPermission.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import url from 'url'; import { _t } from '../../../languageHandler'; +import SdkConfig from '../../../SdkConfig'; export default class AppPermission extends React.Component { constructor(props) { @@ -34,14 +35,21 @@ export default class AppPermission extends React.Component { } isScalarWurl(wurl) { - if (wurl && wurl.hostname && ( - wurl.hostname === 'scalar.vector.im' || - wurl.hostname === 'scalar-staging.riot.im' || - wurl.hostname === 'scalar-develop.riot.im' || - wurl.hostname === 'demo.riot.im' || - wurl.hostname === 'localhost' - )) { - return true; + // Exit early if we've been given bad data + if (!wurl) { + return false; + } + + let scalarUrls = SdkConfig.get().integrations_widgets_urls; + if (!scalarUrls || scalarUrls.length == 0) { + scalarUrls = [SdkConfig.get().integrations_rest_url]; + } + + const url = wurl.format(); + for (const scalarUrl of scalarUrls) { + if (url.startsWith(scalarUrl)) { + return true; + } } return false; }