diff --git a/res/css/views/dialogs/_TermsDialog.scss b/res/css/views/dialogs/_TermsDialog.scss index 60dec57b66..df2a72010f 100644 --- a/res/css/views/dialogs/_TermsDialog.scss +++ b/res/css/views/dialogs/_TermsDialog.scss @@ -14,6 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ +/* + * To avoid visual glitching of two modals stacking briefly, we customise the + * terms dialog sizing when it will appear for the integrations manager so that + * it gets the same basic size as the IM's own modal. + */ +.mx_TermsDialog_forIntegrationsManager .mx_Dialog { + width: 60%; + height: 70%; + box-sizing: border-box; +} + .mx_TermsDialog_termsTableHeader { font-weight: bold; text-align: left; @@ -21,6 +32,7 @@ limitations under the License. .mx_TermsDialog_termsTable { font-size: 12px; + width: 100%; } .mx_TermsDialog_service, .mx_TermsDialog_summary { diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index 1168be4c8e..c268fbe3fb 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -18,7 +18,7 @@ limitations under the License. import url from 'url'; import Promise from 'bluebird'; import SettingsStore from "./settings/SettingsStore"; -import { Service, presentTermsForServices, TermsNotSignedError } from './Terms'; +import { Service, startTermsFlow, TermsNotSignedError } from './Terms'; const request = require('browser-request'); const SdkConfig = require('./SdkConfig'); @@ -32,6 +32,9 @@ const imApiVersion = "1.1"; class ScalarAuthClient { constructor() { this.scalarToken = null; + // `undefined` to allow `startTermsFlow` to fallback to a default + // callback if this is unset. + this.termsInteractionCallback = undefined; } /** @@ -42,6 +45,10 @@ class ScalarAuthClient { return SdkConfig.get()['integrations_rest_url'] && SdkConfig.get()['integrations_ui_url']; } + setTermsInteractionCallback(callback) { + this.termsInteractionCallback = callback; + } + connect() { return this.getScalarToken().then((tok) => { this.scalarToken = tok; @@ -122,11 +129,11 @@ class ScalarAuthClient { const parsedImRestUrl = url.parse(SdkConfig.get().integrations_rest_url); parsedImRestUrl.path = ''; parsedImRestUrl.pathname = ''; - return presentTermsForServices([new Service( + return startTermsFlow([new Service( Matrix.SERVICE_TYPES.IM, parsedImRestUrl.format(), token, - )]).then(() => { + )], this.termsInteractionCallback).then(() => { return token; }); } else { diff --git a/src/Terms.js b/src/Terms.js index 401123f712..02e34cbb3f 100644 --- a/src/Terms.js +++ b/src/Terms.js @@ -15,6 +15,7 @@ limitations under the License. */ import Promise from 'bluebird'; +import classNames from 'classnames'; import MatrixClientPeg from './MatrixClientPeg'; import sdk from './'; @@ -39,17 +40,6 @@ export class Service { } } -/** - * Present a popup to the user prompting them to agree to terms and conditions - * - * @param {Service[]} services Object with keys 'serviceType', 'baseUrl', 'accessToken' - * @returns {Promise} resolves when the user agreed to all necessary terms or rejects - * if they cancel. - */ -export function presentTermsForServices(services) { - return startTermsFlow(services, dialogTermsInteractionCallback); -} - /** * Start a flow where the user is presented with terms & conditions for some services * @@ -61,7 +51,10 @@ export function presentTermsForServices(services) { * @returns {Promise} resolves when the user agreed to all necessary terms or rejects * if they cancel. */ -export async function startTermsFlow(services, interactionCallback) { +export async function startTermsFlow( + services, + interactionCallback = dialogTermsInteractionCallback, +) { const termsPromises = services.map( (s) => MatrixClientPeg.get().getTerms(s.serviceType, s.baseUrl), ); @@ -160,7 +153,11 @@ export async function startTermsFlow(services, interactionCallback) { return Promise.all(agreePromises); } -function dialogTermsInteractionCallback(policiesAndServicePairs, agreedUrls) { +export function dialogTermsInteractionCallback( + policiesAndServicePairs, + agreedUrls, + extraClassNames, +) { return new Promise((resolve, reject) => { console.log("Terms that need agreement", policiesAndServicePairs); const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog"); @@ -175,6 +172,6 @@ function dialogTermsInteractionCallback(policiesAndServicePairs, agreedUrls) { } resolve(agreedUrls); }, - }); + }, classNames("mx_TermsDialog", extraClassNames)); }); } diff --git a/src/components/views/dialogs/TermsDialog.js b/src/components/views/dialogs/TermsDialog.js index 7a8e565555..dee183bc6c 100644 --- a/src/components/views/dialogs/TermsDialog.js +++ b/src/components/views/dialogs/TermsDialog.js @@ -176,7 +176,7 @@ export default class TermsDialog extends React.PureComponent { } return ( -