From fb2022fb1cb3c8023efd22316d570d9b26facbd1 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 4 Aug 2017 14:05:33 -0400 Subject: PLT-6924 Added ability to disable file uploads/downloads on old mobile apps (#7117) --- .../components/admin_console/storage_settings.jsx | 84 ++++++++++++---------- webapp/components/create_post.jsx | 3 +- webapp/components/file_attachment.jsx | 47 +++++++----- webapp/components/file_info_preview.jsx | 26 +++++-- webapp/components/file_upload.jsx | 11 +-- webapp/components/view_image.jsx | 29 ++++---- webapp/components/view_image_popover_bar.jsx | 45 +++++++----- webapp/utils/file_utils.jsx | 24 +++++++ 8 files changed, 174 insertions(+), 95 deletions(-) create mode 100644 webapp/utils/file_utils.jsx diff --git a/webapp/components/admin_console/storage_settings.jsx b/webapp/components/admin_console/storage_settings.jsx index 934a82f8f..4e0d9d19b 100644 --- a/webapp/components/admin_console/storage_settings.jsx +++ b/webapp/components/admin_console/storage_settings.jsx @@ -66,6 +66,53 @@ export default class StorageSettings extends AdminSettings { } renderSettings() { + const mobileUploadDownloadSettings = []; + if (window.mm_license.IsLicensed === 'true' && window.mm_license.Compliance === 'true') { + mobileUploadDownloadSettings.push( + + } + helpText={ + + } + value={this.state.enableMobileUpload} + onChange={this.handleChange} + disabled={!this.state.enableFileAttachments} + /> + ); + + mobileUploadDownloadSettings.push( + + } + helpText={ + + } + value={this.state.enableMobileDownload} + onChange={this.handleChange} + disabled={!this.state.enableFileAttachments} + /> + ); + } + return ( - - } - helpText={ - - } - value={this.state.enableMobileUpload} - onChange={this.handleChange} - disabled={!this.state.enableFileAttachments} - /> - - } - helpText={ - - } - value={this.state.enableMobileDownload} - onChange={this.handleChange} - disabled={!this.state.enableFileAttachments} - /> + {mobileUploadDownloadSettings} ); - } else { + } else if (canDownloadFiles) { filenameOverlay = ( ); + } else { + filenameOverlay = ( + + {trimmedFilename} + + ); + } + + let downloadButton = null; + if (canDownloadFiles) { + downloadButton = ( + + + + ); } return ( @@ -157,15 +180,7 @@ export default class FileAttachment extends React.Component {
{filenameOverlay}
- - - + {downloadButton} {fileInfo.extension.toUpperCase()} {Utils.fileSizeToString(fileInfo.size)}
diff --git a/webapp/components/file_info_preview.jsx b/webapp/components/file_info_preview.jsx index 4a90c4728..6032defb6 100644 --- a/webapp/components/file_info_preview.jsx +++ b/webapp/components/file_info_preview.jsx @@ -1,10 +1,10 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. +import PropTypes from 'prop-types'; import React from 'react'; +import * as FileUtils from 'utils/file_utils'; import * as Utils from 'utils/utils.jsx'; export default class FileInfoPreview extends React.Component { @@ -35,17 +35,31 @@ export default class FileInfoPreview extends React.Component { const infoString = infoParts.join(', '); - return ( -
+ let preview = null; + if (FileUtils.canDownloadFiles()) { + preview = ( + ); + } else { + preview = ( + + + + + ); + } + + return ( +
+ {preview}
{fileInfo.name}
{infoString}
diff --git a/webapp/components/file_upload.jsx b/webapp/components/file_upload.jsx index 0eb12a097..3e28f11df 100644 --- a/webapp/components/file_upload.jsx +++ b/webapp/components/file_upload.jsx @@ -8,6 +8,7 @@ import Constants from 'utils/constants.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import DelayedAction from 'utils/delayed_action.jsx'; import * as UserAgent from 'utils/user_agent.jsx'; +import * as FileUtils from 'utils/file_utils'; import * as Utils from 'utils/utils.jsx'; import {intlShape, injectIntl, defineMessages} from 'react-intl'; @@ -135,7 +136,7 @@ class FileUpload extends React.Component { } handleDrop(e) { - if (global.window.mm_config.EnableFileAttachments === 'false') { + if (!FileUtils.canUploadFiles()) { this.props.onUploadError(Utils.localizeMessage('file_upload.disabled', 'File attachments are disabled.')); return; } @@ -172,7 +173,7 @@ class FileUpload extends React.Component { }); let dragsterActions = {}; - if (global.window.mm_config.EnableFileAttachments === 'true') { + if (FileUtils.canUploadFiles()) { dragsterActions = { enter(dragsterEvent, e) { var files = e.originalEvent.dataTransfer; @@ -263,7 +264,7 @@ class FileUpload extends React.Component { // This looks redundant, but must be done this way due to // setState being an asynchronous call if (items && items.length > 0) { - if (global.window.mm_config.EnableFileAttachments === 'false') { + if (!FileUtils.canUploadFiles()) { this.props.onUploadError(Utils.localizeMessage('file_upload.disabled', 'File attachments are disabled.')); return; } @@ -326,7 +327,7 @@ class FileUpload extends React.Component { if (Utils.cmdOrCtrlPressed(e) && e.keyCode === Constants.KeyCodes.U) { e.preventDefault(); - if (global.window.mm_config.EnableFileAttachments === 'false') { + if (!FileUtils.canUploadFiles()) { this.props.onUploadError(Utils.localizeMessage('file_upload.disabled', 'File attachments are disabled.')); return; } @@ -377,7 +378,7 @@ class FileUpload extends React.Component { const uploadsRemaining = Constants.MAX_UPLOAD_FILES - this.props.getFileCount(channelId); let fileDiv; - if (global.window.mm_config.EnableFileAttachments === 'true') { + if (FileUtils.canUploadFiles()) { fileDiv = (
; + } + return ( - - - + let downloadLinks = null; + if (FileUtils.canDownloadFiles()) { + downloadLinks = ( + ); + } + + return ( +
+ + + + {downloadLinks}
); } diff --git a/webapp/utils/file_utils.jsx b/webapp/utils/file_utils.jsx new file mode 100644 index 000000000..42feb11be --- /dev/null +++ b/webapp/utils/file_utils.jsx @@ -0,0 +1,24 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import * as UserAgent from 'utils/user_agent'; + +export function canUploadFiles() { + if (window.mm_config.EnableFileAttachments === 'false') { + return false; + } + + if (UserAgent.isMobileApp() && window.mm_license.IsLicensed === 'true' && window.mm_license.Compliance === 'true') { + return window.mm_config.EnableMobileFileUpload !== 'false'; + } + + return true; +} + +export function canDownloadFiles() { + if (UserAgent.isMobileApp() && window.mm_license.IsLicensed === 'true' && window.mm_license.Compliance === 'true') { + return window.mm_config.EnableMobileFileDownload !== 'false'; + } + + return true; +} -- cgit v1.2.3-1-g7c22