From f014c8557fefd770686ad3aa2e610b8751e574b7 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 28 Oct 2020 17:23:40 +0100 Subject: [PATCH] MM-29948 Display error msg when pasting files and uploads are disabled (#4927) (#4930) * MM-29948 Display error msg when pasting files and uploads are disabled * Remove unnecessary ref and Animated.View Co-authored-by: Miguel Alatzar (cherry picked from commit f73db6e51c092d960e60bc4c4b6c47c453726133) Co-authored-by: Elias Nahum --- .../__snapshots__/post_draft.test.js.snap | 2 - app/components/post_draft/uploads/index.js | 3 +- app/components/post_draft/uploads/uploads.js | 41 ++++++++++++++----- .../post_draft/uploads/uploads.test.js | 22 ++++++++++ assets/base/i18n/en.json | 1 + 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/app/components/post_draft/__snapshots__/post_draft.test.js.snap b/app/components/post_draft/__snapshots__/post_draft.test.js.snap index 297ad7234..58beb9613 100644 --- a/app/components/post_draft/__snapshots__/post_draft.test.js.snap +++ b/app/components/post_draft/__snapshots__/post_draft.test.js.snap @@ -368,8 +368,6 @@ exports[`PostDraft Should render the DraftInput 1`] = ` } > { this.setState({showFileMaxWarning: true}); - if (this.errorRef.current) { + if (this.errorContainerRef.current) { this.makeErrorVisible(true, 20); setTimeout(() => { this.makeErrorVisible(false, 20); @@ -132,7 +132,7 @@ export default class Uploads extends PureComponent { }; handleFileSizeWarning = () => { - if (this.errorRef.current) { + if (this.errorContainerRef.current) { const {formatMessage} = this.context.intl; const message = formatMessage({ id: 'file_upload.fileAbove', @@ -159,8 +159,14 @@ export default class Uploads extends PureComponent { return; } - const {maxFileSize} = this.props; + const {canUploadFiles, maxFileSize} = this.props; const availableCount = MAX_FILE_COUNT - this.props.files.length; + + if (!canUploadFiles) { + this.handleUploadDisabled(); + return; + } + if (files.length > availableCount) { this.handleFileMaxWarning(); return; @@ -175,6 +181,24 @@ export default class Uploads extends PureComponent { this.handleUploadFiles(files); }; + handleUploadDisabled = () => { + if (this.errorContainerRef.current) { + const {formatMessage} = this.context.intl; + const message = formatMessage({ + id: 'mobile.file_upload.disabled2', + defaultMessage: 'File uploads from mobile are disabled.', + }, { + max: getFormattedFileSize({size: this.props.maxFileSize}), + }); + + this.setState({fileSizeWarning: message}); + this.makeErrorVisible(true, 20); + setTimeout(() => { + this.makeErrorVisible(false, 20); + }, 5000); + } + }; + handleUploadFiles = async (files) => { if (this.props.screenId !== EphemeralStore.getNavigationTopComponentId()) { return; @@ -286,12 +310,7 @@ export default class Uploads extends PureComponent { style={style.errorContainer} isInteraction={true} > - + {showFileMaxWarning && ( } - + ); diff --git a/app/components/post_draft/uploads/uploads.test.js b/app/components/post_draft/uploads/uploads.test.js index 8f0ee503f..ec4db78f4 100644 --- a/app/components/post_draft/uploads/uploads.test.js +++ b/app/components/post_draft/uploads/uploads.test.js @@ -10,6 +10,7 @@ import Uploads from './uploads'; describe('Uploads', () => { const baseProps = { + canUploadFiles: true, channelId: 'channel-id', files: [], filesUploadingForCurrentChannel: true, @@ -37,4 +38,25 @@ describe('Uploads', () => { expect(instance.handleFileSizeWarning).not.toHaveBeenCalled(); expect(props.initUploadFiles).not.toHaveBeenCalled(); }); + + test('handlePasteFiles should display an error if uploads are disabled', () => { + const topScreenId = 'top-screen'; + EphemeralStore.getNavigationTopComponentId = jest.fn(() => (topScreenId)); + + const props = { + ...baseProps, + canUploadFiles: false, + screenId: topScreenId, + }; + const wrapper = shallow( + , + ); + const instance = wrapper.instance(); + instance.showPasteFilesErrorDialog = jest.fn(); + instance.handleUploadDisabled = jest.fn(); + + instance.handlePasteFiles(undefined, []); + expect(instance.showPasteFilesErrorDialog).not.toHaveBeenCalled(); + expect(instance.handleUploadDisabled).toHaveBeenCalled(); + }); }); diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index 7d1aa9fa9..691c18be6 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -277,6 +277,7 @@ "mobile.file_upload.camera_photo": "Take Photo", "mobile.file_upload.camera_video": "Take Video", "mobile.file_upload.disabled": "File uploads from mobile are disabled. Please contact your System Admin for more details.", + "mobile.file_upload.disabled2": "File uploads from mobile are disabled.", "mobile.file_upload.library": "Photo Library", "mobile.file_upload.max_warning": "Uploads limited to 5 files maximum.", "mobile.file_upload.unsupportedMimeType": "Only BMP, JPG or PNG images may be used for profile pictures.",