From 49481caf6db89b0853626ac52ab5f786a6887179 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 4 May 2017 15:45:19 -0400 Subject: PLT-6262 Add config setting to disable file attachments (#6301) * Add config setting to disable file attachments * Add unit tests * Updating UI for no attachments (#6312) * Update UI text on file upload System Console setting (#6313) * Update storage_settings.jsx * Update en.json --- .../components/admin_console/storage_settings.jsx | 20 +++++ webapp/components/create_post.jsx | 7 +- webapp/components/file_upload.jsx | 100 ++++++++++++++------- 3 files changed, 93 insertions(+), 34 deletions(-) (limited to 'webapp/components') diff --git a/webapp/components/admin_console/storage_settings.jsx b/webapp/components/admin_console/storage_settings.jsx index 3b634dc53..1400b673c 100644 --- a/webapp/components/admin_console/storage_settings.jsx +++ b/webapp/components/admin_console/storage_settings.jsx @@ -25,6 +25,7 @@ export default class StorageSettings extends AdminSettings { } getConfigFromState(config) { + config.FileSettings.EnableFileAttachments = this.state.enableFileAttachments; config.FileSettings.MaxFileSize = this.parseInt(this.state.maxFileSize) * 1024 * 1024; config.FileSettings.DriverName = this.state.driverName; config.FileSettings.Directory = this.state.directory; @@ -39,6 +40,7 @@ export default class StorageSettings extends AdminSettings { getStateFromConfig(config) { return { + enableFileAttachments: config.FileSettings.EnableFileAttachments, maxFileSize: config.FileSettings.MaxFileSize / 1024 / 1024, driverName: config.FileSettings.DriverName, directory: config.FileSettings.Directory, @@ -199,6 +201,23 @@ export default class StorageSettings extends AdminSettings { onChange={this.handleChange} disabled={this.state.driverName !== DRIVER_S3} /> + + } + helpText={ + + } + value={this.state.enableFileAttachments} + onChange={this.handleChange} + /> ); diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx index 390940914..6e59b88b1 100644 --- a/webapp/components/create_post.jsx +++ b/webapp/components/create_post.jsx @@ -630,6 +630,11 @@ export default class CreatePost extends React.Component { ); } + let attachmentsDisabled = ''; + if (global.window.mm_config.EnableFileAttachments === 'false') { + attachmentsDisabled = ' post-create--attachment-disabled'; + } + return (
-
+
0) { + if (global.window.mm_config.EnableFileAttachments === 'false') { + this.props.onUploadError(Utils.localizeMessage('file_upload.disabled', 'File attachments are disabled.')); + return; + } + var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - this.props.getFileCount(ChannelStore.getCurrentId()), items.length); if (items.length > numToUpload) { @@ -305,6 +326,12 @@ class FileUpload extends React.Component { keyUpload(e) { if (Utils.cmdOrCtrlPressed(e) && e.keyCode === Constants.KeyCodes.U) { e.preventDefault(); + + if (global.window.mm_config.EnableFileAttachments === 'false') { + this.props.onUploadError(Utils.localizeMessage('file_upload.disabled', 'File attachments are disabled.')); + return; + } + if ((this.props.postType === 'post' && document.activeElement.id === 'post_textbox') || (this.props.postType === 'comment' && document.activeElement.id === 'reply_textbox')) { $(this.refs.fileInput).focus().trigger('click'); @@ -361,11 +388,9 @@ class FileUpload extends React.Component { ); } - return ( - + let fileDiv; + if (global.window.mm_config.EnableFileAttachments === 'true') { + fileDiv = (
+ ); + } + + return ( + + {fileDiv} {emojiSpan} ); -- cgit v1.2.3-1-g7c22