Disallow download of all file types on RN apps when disallowed in System Console (#2038)

This commit is contained in:
Elias Nahum 2018-08-29 15:04:36 -03:00 committed by Harrison Healey
parent 96e9c6c707
commit ddc4a3057e
5 changed files with 39 additions and 2 deletions

View file

@ -20,6 +20,7 @@ import FileAttachmentImage from './file_attachment_image';
export default class FileAttachment extends PureComponent {
static propTypes = {
canDownloadFiles: PropTypes.bool.isRequired,
deviceWidth: PropTypes.number.isRequired,
file: PropTypes.object.isRequired,
index: PropTypes.number.isRequired,
@ -80,6 +81,7 @@ export default class FileAttachment extends PureComponent {
render() {
const {
canDownloadFiles,
deviceWidth,
file,
onInfoPress,
@ -103,6 +105,7 @@ export default class FileAttachment extends PureComponent {
} else if (isDocument(data)) {
fileAttachmentComponent = (
<FileAttachmentDocument
canDownloadFiles={canDownloadFiles}
file={file}
navigator={navigator}
theme={theme}

View file

@ -39,6 +39,7 @@ const TEXT_PREVIEW_FORMATS = [
export default class FileAttachmentDocument extends PureComponent {
static propTypes = {
canDownloadFiles: PropTypes.bool.isRequired,
iconHeight: PropTypes.number,
iconWidth: PropTypes.number,
file: PropTypes.object.isRequired,
@ -171,9 +172,14 @@ export default class FileAttachmentDocument extends PureComponent {
};
handlePreviewPress = async () => {
const {file} = this.props;
const {canDownloadFiles, file} = this.props;
const {downloading, progress} = this.state;
if (!canDownloadFiles) {
this.showDownloadDisabledAlert();
return;
}
if (downloading && progress < 100) {
this.cancelDownload();
} else if (downloading) {
@ -290,6 +296,27 @@ export default class FileAttachmentDocument extends PureComponent {
);
};
showDownloadDisabledAlert = () => {
const {intl} = this.context;
Alert.alert(
intl.formatMessage({
id: 'mobile.downloader.disabled_title',
defaultMessage: 'Download disabled',
}),
intl.formatMessage({
id: 'mobile.downloader.disabled_description',
defaultMessage: 'File downloads are disabled on this server. Please contact your System Admin for more details.\n',
}),
[{
text: intl.formatMessage({
id: 'mobile.server_upgrade.button',
defaultMessage: 'OK',
}),
}]
);
};
showDownloadFailedAlert = () => {
const {intl} = this.context;

View file

@ -25,6 +25,7 @@ import FileAttachment from './file_attachment';
export default class FileAttachmentList extends Component {
static propTypes = {
actions: PropTypes.object.isRequired,
canDownloadFiles: PropTypes.bool.isRequired,
deviceHeight: PropTypes.number.isRequired,
deviceWidth: PropTypes.number.isRequired,
fileIds: PropTypes.array.isRequired,
@ -144,12 +145,13 @@ export default class FileAttachmentList extends Component {
};
renderItems = () => {
const {deviceWidth, fileIds, files, navigator} = this.props;
const {canDownloadFiles, deviceWidth, fileIds, files, navigator} = this.props;
if (!files.length && fileIds.length > 0) {
return fileIds.map((id, idx) => (
<FileAttachment
key={id}
canDownloadFiles={canDownloadFiles}
deviceWidth={deviceWidth}
file={{loading: true}}
index={idx}
@ -172,6 +174,7 @@ export default class FileAttachmentList extends Component {
onPressOut={this.handlePressOut}
>
<FileAttachment
canDownloadFiles={canDownloadFiles}
deviceWidth={deviceWidth}
file={f}
index={idx}

View file

@ -4,6 +4,7 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {canDownloadFilesOnMobile} from 'mattermost-redux/selectors/entities/general';
import {makeGetFilesForPost} from 'mattermost-redux/selectors/entities/files';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
@ -17,6 +18,7 @@ function makeMapStateToProps() {
return function mapStateToProps(state, ownProps) {
return {
...getDimensions(state),
canDownloadFiles: canDownloadFilesOnMobile(state),
files: getFilesForPost(state, ownProps.postId),
theme: getTheme(state),
filesForPostRequest: state.requests.files.getFilesForPost,

View file

@ -2422,6 +2422,8 @@
"mobile.downloader.android_started": "Download started",
"mobile.downloader.android_success": "download successful",
"mobile.downloader.complete": "Download complete",
"mobile.downloader.disabled_title": "Download disabled",
"mobile.downloader.disabled_description": "File downloads are disabled on this server. Please contact your System Admin for more details.\n",
"mobile.downloader.downloading": "Downloading...",
"mobile.downloader.failed_description": "An error occurred while downloading the file. Please check your internet connection and try again.\n",
"mobile.downloader.failed_title": "Download failed",