mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 02:21:34 +03:00
23162c8625
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 <travpc@gmail.com>
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
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) {
|
|
super(props);
|
|
|
|
const curlBase = this.getCurlBase();
|
|
this.state = { curlBase: curlBase};
|
|
}
|
|
|
|
// Return string representation of content URL without query parameters
|
|
getCurlBase() {
|
|
const wurl = url.parse(this.props.url);
|
|
let curl;
|
|
let curlString;
|
|
|
|
const searchParams = new URLSearchParams(wurl.search);
|
|
|
|
if (this.isScalarWurl(wurl) && searchParams && searchParams.get('url')) {
|
|
curl = url.parse(searchParams.get('url'));
|
|
if (curl) {
|
|
curl.search = curl.query = "";
|
|
curlString = curl.format();
|
|
}
|
|
}
|
|
if (!curl && wurl) {
|
|
wurl.search = wurl.query = "";
|
|
curlString = wurl.format();
|
|
}
|
|
return curlString;
|
|
}
|
|
|
|
isScalarWurl(wurl) {
|
|
// 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;
|
|
}
|
|
|
|
render() {
|
|
let e2eWarningText;
|
|
if (this.props.isRoomEncrypted) {
|
|
e2eWarningText =
|
|
<span className='mx_AppPermissionWarningTextLabel'>{ _t('NOTE: Apps are not end-to-end encrypted') }</span>;
|
|
}
|
|
const cookieWarning =
|
|
<span className='mx_AppPermissionWarningTextLabel'>
|
|
{ _t('Warning: This widget might use cookies.') }
|
|
</span>;
|
|
return (
|
|
<div className='mx_AppPermissionWarning'>
|
|
<div className='mx_AppPermissionWarningImage'>
|
|
<img src='img/warning.svg' alt={_t('Warning!')} />
|
|
</div>
|
|
<div className='mx_AppPermissionWarningText'>
|
|
<span className='mx_AppPermissionWarningTextLabel'>{ _t('Do you want to load widget from URL:') }</span> <span className='mx_AppPermissionWarningTextURL'>{ this.state.curlBase }</span>
|
|
{ e2eWarningText }
|
|
{ cookieWarning }
|
|
</div>
|
|
<input
|
|
className='mx_AppPermissionButton'
|
|
type='button'
|
|
value={_t('Allow')}
|
|
onClick={this.props.onPermissionGranted}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
AppPermission.propTypes = {
|
|
isRoomEncrypted: PropTypes.bool,
|
|
url: PropTypes.string.isRequired,
|
|
onPermissionGranted: PropTypes.func.isRequired,
|
|
};
|
|
AppPermission.defaultProps = {
|
|
isRoomEncrypted: false,
|
|
onPermissionGranted: function() {},
|
|
};
|