From a0e7249c31ac84d8d7b14b6ae137d992f3118cc5 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 17 Nov 2021 19:32:04 -0300 Subject: [PATCH 01/15] [NEW] Block upload file without permission --- app/containers/MessageBox/index.tsx | 91 ++++++++++++++++++----------- app/lib/methods/getPermissions.js | 3 +- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 047c128bdaf..93ee4f144b1 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -47,6 +47,7 @@ import Navigation from '../../lib/Navigation'; import { withActionSheet } from '../ActionSheet'; import { sanitizeLikeString } from '../../lib/database/utils'; import { CustomIcon } from '../../lib/Icons'; +import { compareServerVersion, methods } from '../../lib/utils'; if (isAndroid) { require('./EmojiKeyboard'); @@ -109,6 +110,8 @@ interface IMessageBoxProps { sharing: boolean; isActionsEnabled: boolean; usedCannedResponse: string; + uploadFilePermission: string[]; + serverVersion: string; } interface IMessageBoxState { @@ -185,35 +188,6 @@ class MessageBox extends Component { this.selection = { start: 0, end: 0 }; this.focused = false; - // MessageBox Actions - this.options = [ - { - title: I18n.t('Take_a_photo'), - icon: 'camera-photo', - onPress: this.takePhoto - }, - { - title: I18n.t('Take_a_video'), - icon: 'camera', - onPress: this.takeVideo - }, - { - title: I18n.t('Choose_from_library'), - icon: 'image', - onPress: this.chooseFromLibrary - }, - { - title: I18n.t('Choose_file'), - icon: 'attach', - onPress: this.chooseFile - }, - { - title: I18n.t('Create_Discussion'), - icon: 'discussions', - onPress: this.createDiscussion - } - ]; - const libPickerLabels = { cropperChooseText: I18n.t('Choose'), cropperCancelText: I18n.t('Cancel'), @@ -277,6 +251,8 @@ class MessageBox extends Component { this.onChangeText(usedCannedResponse); } + this.setOptions(); + this.unsubscribeFocus = navigation.addListener('focus', () => { // didFocus // We should wait pushed views be dismissed @@ -293,7 +269,7 @@ class MessageBox extends Component { } UNSAFE_componentWillReceiveProps(nextProps: any) { - const { isFocused, editing, replying, sharing, usedCannedResponse } = this.props; + const { isFocused, editing, replying, sharing, usedCannedResponse, uploadFilePermission } = this.props; if (!isFocused?.()) { return; } @@ -319,12 +295,15 @@ class MessageBox extends Component { clearTimeout(this.trackingTimeout); this.trackingTimeout = false; } + if (!dequal(nextProps.uploadFilePermission, uploadFilePermission)) { + this.setOptions(); + } } - shouldComponentUpdate(nextProps: any, nextState: any) { + shouldComponentUpdate(nextProps: IMessageBoxProps, nextState: IMessageBoxState) { const { showEmojiKeyboard, showSend, recording, mentions, commandPreview, tshow, mentionLoading, trackingType } = this.state; - const { roomType, replying, editing, isFocused, message, theme, usedCannedResponse } = this.props; + const { roomType, replying, editing, isFocused, message, theme, usedCannedResponse, uploadFilePermission } = this.props; if (nextProps.theme !== theme) { return true; } @@ -367,6 +346,9 @@ class MessageBox extends Component { if (!dequal(nextProps.message?.id, message?.id)) { return true; } + if (!dequal(nextProps.uploadFilePermission, uploadFilePermission)) { + return true; + } if (nextProps.usedCannedResponse !== usedCannedResponse) { return true; } @@ -404,6 +386,47 @@ class MessageBox extends Component { } } + setOptions = async () => { + const { uploadFilePermission, serverVersion } = this.props; + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); + + const uploadActionsArray = []; + if (permissionToUpload[0] || compareServerVersion(serverVersion, '4.1.0', methods.lowerThan)) { + uploadActionsArray.push( + { + title: I18n.t('Take_a_photo'), + icon: 'camera-photo', + onPress: this.takePhoto + }, + { + title: I18n.t('Take_a_video'), + icon: 'camera', + onPress: this.takeVideo + }, + { + title: I18n.t('Choose_from_library'), + icon: 'image', + onPress: this.chooseFromLibrary + }, + { + title: I18n.t('Choose_file'), + icon: 'attach', + onPress: this.chooseFile + } + ); + } + + // MessageBox Actions + this.options = [ + ...uploadActionsArray, + { + title: I18n.t('Create_Discussion'), + icon: 'discussions', + onPress: this.createDiscussion + } + ]; + }; + onChangeText: any = (text: string): void => { const isTextEmpty = text.length === 0; this.setShowSend(!isTextEmpty); @@ -1117,7 +1140,9 @@ const mapStateToProps = (state: any) => ({ user: getUserSelector(state), FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize, - Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled + Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled, + uploadFilePermission: state.permissions['mobile-upload-file'], + serverVersion: state.server.version }); const dispatchToProps = { diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index 589aa6bd1c9..b680a919632 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -55,7 +55,8 @@ const PERMISSIONS = [ 'convert-team', 'edit-omnichannel-contact', 'edit-livechat-room-customfields', - 'view-canned-responses' + 'view-canned-responses', + 'mobile-upload-file' ]; export async function setPermissions() { From 36bbc3c311c3995fb28cf55b16748217676e815e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 17 Nov 2021 19:44:50 -0300 Subject: [PATCH 02/15] minor tweak server version --- app/containers/MessageBox/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 93ee4f144b1..74a6b80f898 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -391,7 +391,7 @@ class MessageBox extends Component { const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); const uploadActionsArray = []; - if (permissionToUpload[0] || compareServerVersion(serverVersion, '4.1.0', methods.lowerThan)) { + if (permissionToUpload[0] || compareServerVersion(serverVersion, '4.2.0', methods.lowerThan)) { uploadActionsArray.push( { title: I18n.t('Take_a_photo'), From e95596d614097b4e4642252b15bd3462be09b489 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 23 Nov 2021 00:08:43 -0300 Subject: [PATCH 03/15] fix conditional to upload and db on shareListView --- app/containers/MessageBox/index.tsx | 9 ++++----- app/views/ShareListView/index.js | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 74a6b80f898..b8082f64b56 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -47,7 +47,6 @@ import Navigation from '../../lib/Navigation'; import { withActionSheet } from '../ActionSheet'; import { sanitizeLikeString } from '../../lib/database/utils'; import { CustomIcon } from '../../lib/Icons'; -import { compareServerVersion, methods } from '../../lib/utils'; if (isAndroid) { require('./EmojiKeyboard'); @@ -387,11 +386,12 @@ class MessageBox extends Component { } setOptions = async () => { - const { uploadFilePermission, serverVersion } = this.props; + const { uploadFilePermission } = this.props; const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); const uploadActionsArray = []; - if (permissionToUpload[0] || compareServerVersion(serverVersion, '4.2.0', methods.lowerThan)) { + // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. + if (permissionToUpload[0] || !uploadFilePermission) { uploadActionsArray.push( { title: I18n.t('Take_a_photo'), @@ -1141,8 +1141,7 @@ const mapStateToProps = (state: any) => ({ FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize, Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled, - uploadFilePermission: state.permissions['mobile-upload-file'], - serverVersion: state.server.version + uploadFilePermission: state.permissions['mobile-upload-file'] }); const dispatchToProps = { diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index e0a82a50def..bc62e522167 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View } from 'react-native'; +import { Alert, BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View } from 'react-native'; import ShareExtension from 'rn-extensions-share'; import * as FileSystem from 'expo-file-system'; import { connect } from 'react-redux'; @@ -54,7 +54,8 @@ class ShareListView extends React.Component { text: '', loading: true, serverInfo: null, - needsPermission: isAndroid || false + needsPermission: isAndroid || false, + permissionToUploadFile: false }; this.setHeader(); if (isAndroid) { @@ -96,6 +97,7 @@ class ShareListView extends React.Component { } this.getSubscriptions(server); + this.getPermissionMobileUpload(); } UNSAFE_componentWillReceiveProps(nextProps) { @@ -106,13 +108,16 @@ class ShareListView extends React.Component { } shouldComponentUpdate(nextProps, nextState) { - const { searching, needsPermission } = this.state; + const { searching, needsPermission, permissionToUploadFile } = this.state; if (nextState.searching !== searching) { return true; } if (nextState.needsPermission !== needsPermission) { return true; } + if (nextState.permissionToUploadFile !== permissionToUploadFile) { + return true; + } const { server, userId } = this.props; if (server !== nextProps.server) { @@ -263,10 +268,25 @@ class ShareListView extends React.Component { return ((item.prid || useRealName) && item.fname) || item.name; }; + getPermissionMobileUpload = async () => { + const db = database.active; + const permissionsCollection = db.get('permissions'); + const uploadFilePermissionFetch = await permissionsCollection.query(Q.where('id', Q.like('mobile-upload-file'))).fetch(); + const uploadFilePermission = uploadFilePermissionFetch[0]?.roles; + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); + // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. + this.setState({ permissionToUploadFile: !uploadFilePermission || permissionToUpload[0] }); + }; + shareMessage = room => { - const { attachments, text, serverInfo } = this.state; + const { attachments, text, serverInfo, permissionToUploadFile } = this.state; const { navigation } = this.props; + if (attachments.length > 0 && !permissionToUploadFile) { + // TODO: Check what is to do here + return; + } + navigation.navigate('ShareView', { room, text, From 7c445ba2ac1ab6f79b166496598832fd1f989034 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 23 Nov 2021 14:23:29 -0300 Subject: [PATCH 04/15] block file upload inside shareview --- app/i18n/locales/en.json | 1 + app/utils/media.js | 5 ++++- app/views/ShareListView/index.js | 28 ++++------------------------ app/views/ShareView/index.tsx | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 18dd52bc5b6..1d3571bfc7c 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -21,6 +21,7 @@ "error-save-video": "Error while saving video", "error-field-unavailable": "{{field}} is already in use :(", "error-file-too-large": "File is too large", + "error-not-permission-to-upload-file": "You don't have permission to upload files", "error-importer-not-defined": "The importer was not defined correctly, it is missing the Import class.", "error-input-is-not-a-valid-field": "{{input}} is not a valid {{field}}", "error-invalid-actionlink": "Invalid action link", diff --git a/app/utils/media.js b/app/utils/media.js index b05f95a9410..07f6f58d740 100644 --- a/app/utils/media.js +++ b/app/utils/media.js @@ -1,10 +1,13 @@ -export const canUploadFile = (file, allowList, maxFileSize) => { +export const canUploadFile = (file, allowList, maxFileSize, permissionToUploadFile) => { if (!(file && file.path)) { return { success: true }; } if (maxFileSize > -1 && file.size > maxFileSize) { return { success: false, error: 'error-file-too-large' }; } + if (!permissionToUploadFile) { + return { success: false, error: 'error-not-permission-to-upload-file' }; + } // if white list is empty, all media types are enabled if (!allowList || allowList === '*') { return { success: true }; diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index bc62e522167..e0a82a50def 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Alert, BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View } from 'react-native'; +import { BackHandler, FlatList, Keyboard, PermissionsAndroid, ScrollView, Text, View } from 'react-native'; import ShareExtension from 'rn-extensions-share'; import * as FileSystem from 'expo-file-system'; import { connect } from 'react-redux'; @@ -54,8 +54,7 @@ class ShareListView extends React.Component { text: '', loading: true, serverInfo: null, - needsPermission: isAndroid || false, - permissionToUploadFile: false + needsPermission: isAndroid || false }; this.setHeader(); if (isAndroid) { @@ -97,7 +96,6 @@ class ShareListView extends React.Component { } this.getSubscriptions(server); - this.getPermissionMobileUpload(); } UNSAFE_componentWillReceiveProps(nextProps) { @@ -108,16 +106,13 @@ class ShareListView extends React.Component { } shouldComponentUpdate(nextProps, nextState) { - const { searching, needsPermission, permissionToUploadFile } = this.state; + const { searching, needsPermission } = this.state; if (nextState.searching !== searching) { return true; } if (nextState.needsPermission !== needsPermission) { return true; } - if (nextState.permissionToUploadFile !== permissionToUploadFile) { - return true; - } const { server, userId } = this.props; if (server !== nextProps.server) { @@ -268,25 +263,10 @@ class ShareListView extends React.Component { return ((item.prid || useRealName) && item.fname) || item.name; }; - getPermissionMobileUpload = async () => { - const db = database.active; - const permissionsCollection = db.get('permissions'); - const uploadFilePermissionFetch = await permissionsCollection.query(Q.where('id', Q.like('mobile-upload-file'))).fetch(); - const uploadFilePermission = uploadFilePermissionFetch[0]?.roles; - const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); - // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. - this.setState({ permissionToUploadFile: !uploadFilePermission || permissionToUpload[0] }); - }; - shareMessage = room => { - const { attachments, text, serverInfo, permissionToUploadFile } = this.state; + const { attachments, text, serverInfo } = this.state; const { navigation } = this.props; - if (attachments.length > 0 && !permissionToUploadFile) { - // TODO: Check what is to do here - return; - } - navigation.navigate('ShareView', { room, text, diff --git a/app/views/ShareView/index.tsx b/app/views/ShareView/index.tsx index e10b21483b2..4e685f35dc3 100644 --- a/app/views/ShareView/index.tsx +++ b/app/views/ShareView/index.tsx @@ -4,6 +4,7 @@ import { RouteProp } from '@react-navigation/native'; import { NativeModules, Text, View } from 'react-native'; import { connect } from 'react-redux'; import ShareExtension from 'rn-extensions-share'; +import { Q } from '@nozbe/watermelondb'; import { themes } from '../../constants/colors'; import I18n from '../../i18n'; @@ -154,6 +155,16 @@ class ShareView extends Component { } }; + getPermissionMobileUpload = async () => { + const db = database.active; + const permissionsCollection = db.get('permissions'); + const uploadFilePermissionFetch = await permissionsCollection.query(Q.where('id', Q.like('mobile-upload-file'))).fetch(); + const uploadFilePermission = uploadFilePermissionFetch[0]?.roles; + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); + // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. + return !uploadFilePermission || permissionToUpload[0]; + }; + getReadOnly = async () => { const { room } = this.state; const { user } = this.props; @@ -163,10 +174,12 @@ class ShareView extends Component { getAttachments = async () => { const { mediaAllowList, maxFileSize } = this.state; + const permissionToUploadFile = await this.getPermissionMobileUpload(); + const items = await Promise.all( this.files.map(async item => { // Check server settings - const { success: canUpload, error } = canUploadFile(item, mediaAllowList, maxFileSize); + const { success: canUpload, error } = canUploadFile(item, mediaAllowList, maxFileSize, permissionToUploadFile); item.canUpload = canUpload; item.error = error; From 1e31a6f1a8fb5c4a4a09cc8a44560077b9ea3c04 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:04:22 -0300 Subject: [PATCH 05/15] Move setOptions logic to did update, so it gets triggered after the new props get to the component --- app/containers/MessageBox/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 91c263ad11d..002708422e0 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -268,7 +268,7 @@ class MessageBox extends Component { } UNSAFE_componentWillReceiveProps(nextProps: any) { - const { isFocused, editing, replying, sharing, usedCannedResponse, uploadFilePermission } = this.props; + const { isFocused, editing, replying, sharing, usedCannedResponse } = this.props; if (!isFocused?.()) { return; } @@ -294,9 +294,6 @@ class MessageBox extends Component { clearTimeout(this.trackingTimeout); this.trackingTimeout = false; } - if (!dequal(nextProps.uploadFilePermission, uploadFilePermission)) { - this.setOptions(); - } } shouldComponentUpdate(nextProps: IMessageBoxProps, nextState: IMessageBoxState) { @@ -354,6 +351,13 @@ class MessageBox extends Component { return false; } + componentDidUpdate(prevProps: IMessageBoxProps) { + const { uploadFilePermission } = this.props; + if (!dequal(prevProps.uploadFilePermission, uploadFilePermission)) { + this.setOptions(); + } + } + componentWillUnmount() { console.countReset(`${this.constructor.name}.render calls`); if (this.onChangeText && this.onChangeText.stop) { @@ -386,8 +390,8 @@ class MessageBox extends Component { } setOptions = async () => { - const { uploadFilePermission } = this.props; - const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); + const { uploadFilePermission, rid } = this.props; + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission], rid); const uploadActionsArray = []; // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. From 850324b45c31ebd06a552318db54a93a59377a00 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:07:37 -0300 Subject: [PATCH 06/15] Hide audio recording if there's not enough permission --- app/containers/MessageBox/RecordAudio.tsx | 6 ++-- app/containers/MessageBox/index.tsx | 43 +++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/containers/MessageBox/RecordAudio.tsx b/app/containers/MessageBox/RecordAudio.tsx index fa6c509ef48..56d4fb13f8a 100644 --- a/app/containers/MessageBox/RecordAudio.tsx +++ b/app/containers/MessageBox/RecordAudio.tsx @@ -192,9 +192,11 @@ export default class RecordAudio extends React.PureComponent { showCommandPreview: false, command: {}, tshow: false, - mentionLoading: false + mentionLoading: false, + permissionToUpload: true }; this.text = ''; this.selection = { start: 0, end: 0 }; @@ -268,7 +269,7 @@ class MessageBox extends Component { } UNSAFE_componentWillReceiveProps(nextProps: any) { - const { isFocused, editing, replying, sharing, usedCannedResponse } = this.props; + const { isFocused, editing, replying, sharing, usedCannedResponse, uploadFilePermission } = this.props; if (!isFocused?.()) { return; } @@ -297,7 +298,17 @@ class MessageBox extends Component { } shouldComponentUpdate(nextProps: IMessageBoxProps, nextState: IMessageBoxState) { - const { showEmojiKeyboard, showSend, recording, mentions, commandPreview, tshow, mentionLoading, trackingType } = this.state; + const { + showEmojiKeyboard, + showSend, + recording, + mentions, + commandPreview, + tshow, + mentionLoading, + trackingType, + permissionToUpload + } = this.state; const { roomType, replying, editing, isFocused, message, theme, usedCannedResponse, uploadFilePermission } = this.props; if (nextProps.theme !== theme) { @@ -333,6 +344,9 @@ class MessageBox extends Component { if (nextState.tshow !== tshow) { return true; } + if (nextState.permissionToUpload !== permissionToUpload) { + return true; + } if (!dequal(nextState.mentions, mentions)) { return true; } @@ -418,6 +432,9 @@ class MessageBox extends Component { onPress: this.chooseFile } ); + this.setState({ permissionToUpload: true }); + } else { + this.setState({ permissionToUpload: false }); } // MessageBox Actions @@ -995,8 +1012,17 @@ class MessageBox extends Component { }; renderContent = () => { - const { recording, showEmojiKeyboard, showSend, mentions, trackingType, commandPreview, showCommandPreview, mentionLoading } = - this.state; + const { + recording, + showEmojiKeyboard, + showSend, + mentions, + trackingType, + commandPreview, + showCommandPreview, + mentionLoading, + permissionToUpload + } = this.state; const { editing, message, @@ -1022,7 +1048,12 @@ class MessageBox extends Component { const recordAudio = showSend || !Message_AudioRecorderEnabled ? null : ( - + ); const commandsPreviewAndMentions = !recording ? ( From ade3fb2971bc7112bae7f432f05405ff88f9fe7e Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:13:24 -0300 Subject: [PATCH 07/15] Small refactor moving options logic to showMessageBoxActions so we can reuse state --- app/containers/MessageBox/index.tsx | 74 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index a20a248b78c..fa183ad10a3 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -407,45 +407,8 @@ class MessageBox extends Component { const { uploadFilePermission, rid } = this.props; const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission], rid); - const uploadActionsArray = []; // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. - if (permissionToUpload[0] || !uploadFilePermission) { - uploadActionsArray.push( - { - title: I18n.t('Take_a_photo'), - icon: 'camera-photo', - onPress: this.takePhoto - }, - { - title: I18n.t('Take_a_video'), - icon: 'camera', - onPress: this.takeVideo - }, - { - title: I18n.t('Choose_from_library'), - icon: 'image', - onPress: this.chooseFromLibrary - }, - { - title: I18n.t('Choose_file'), - icon: 'attach', - onPress: this.chooseFile - } - ); - this.setState({ permissionToUpload: true }); - } else { - this.setState({ permissionToUpload: false }); - } - - // MessageBox Actions - this.options = [ - ...uploadActionsArray, - { - title: I18n.t('Create_Discussion'), - icon: 'discussions', - onPress: this.createDiscussion - } - ]; + this.setState({ permissionToUpload: permissionToUpload[0] || !uploadFilePermission }); }; onChangeText: any = (text: string): void => { @@ -810,8 +773,41 @@ class MessageBox extends Component { showMessageBoxActions = () => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); + const { permissionToUpload } = this.state; const { showActionSheet } = this.props; - showActionSheet({ options: this.options }); + + const options = []; + if (permissionToUpload) { + options.push( + { + title: I18n.t('Take_a_photo'), + icon: 'camera-photo', + onPress: this.takePhoto + }, + { + title: I18n.t('Take_a_video'), + icon: 'camera', + onPress: this.takeVideo + }, + { + title: I18n.t('Choose_from_library'), + icon: 'image', + onPress: this.chooseFromLibrary + }, + { + title: I18n.t('Choose_file'), + icon: 'attach', + onPress: this.chooseFile + } + ); + } + + options.push({ + title: I18n.t('Create_Discussion'), + icon: 'discussions', + onPress: this.createDiscussion + }); + showActionSheet({ options }); }; editCancel = () => { From 79e6e2d32835ba545f4eeb8d5672244b72899f79 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:18:45 -0300 Subject: [PATCH 08/15] Small refactor to making the logic more clear and avoiding an extra call to hasPermission method --- app/containers/MessageBox/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index fa183ad10a3..1fc46faaffd 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -405,10 +405,15 @@ class MessageBox extends Component { setOptions = async () => { const { uploadFilePermission, rid } = this.props; - const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission], rid); - // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. - this.setState({ permissionToUpload: permissionToUpload[0] || !uploadFilePermission }); + // Servers older than 4.2 + if (!uploadFilePermission) { + this.setState({ permissionToUpload: true }); + return; + } + + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission], rid); + this.setState({ permissionToUpload: permissionToUpload[0] }); }; onChangeText: any = (text: string): void => { From fa1c95cf698c75cc2f098d5a6b50572c38cd655a Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:23:04 -0300 Subject: [PATCH 09/15] Make ts happy :) --- app/containers/MessageBox/RecordAudio.tsx | 1 + app/containers/MessageBox/index.tsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/containers/MessageBox/RecordAudio.tsx b/app/containers/MessageBox/RecordAudio.tsx index 56d4fb13f8a..e219e64232f 100644 --- a/app/containers/MessageBox/RecordAudio.tsx +++ b/app/containers/MessageBox/RecordAudio.tsx @@ -13,6 +13,7 @@ import { events, logEvent } from '../../utils/log'; interface IMessageBoxRecordAudioProps { theme: string; + permissionToUpload: boolean; recordingCallback: Function; onFinish: Function; } diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 1fc46faaffd..12b4d86cf5d 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -126,6 +126,7 @@ interface IMessageBoxState { }; tshow: boolean; mentionLoading: boolean; + permissionToUpload: boolean; } class MessageBox extends Component { @@ -269,7 +270,7 @@ class MessageBox extends Component { } UNSAFE_componentWillReceiveProps(nextProps: any) { - const { isFocused, editing, replying, sharing, usedCannedResponse, uploadFilePermission } = this.props; + const { isFocused, editing, replying, sharing, usedCannedResponse } = this.props; if (!isFocused?.()) { return; } From 01afbc04757650576530064a46d169ae90f1d3c8 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 6 Dec 2021 17:51:39 -0300 Subject: [PATCH 10/15] Start block download logic --- app/lib/methods/getPermissions.js | 3 ++- app/views/AttachmentView.tsx | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index b680a919632..a0c63130ad1 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -56,7 +56,8 @@ const PERMISSIONS = [ 'edit-omnichannel-contact', 'edit-livechat-room-customfields', 'view-canned-responses', - 'mobile-upload-file' + 'mobile-upload-file', + 'mobile-download-file' ]; export async function setPermissions() { diff --git a/app/views/AttachmentView.tsx b/app/views/AttachmentView.tsx index 09e2d5d6184..a3087665a18 100644 --- a/app/views/AttachmentView.tsx +++ b/app/views/AttachmentView.tsx @@ -26,6 +26,7 @@ import { getHeaderHeight } from '../containers/Header'; import StatusBar from '../containers/StatusBar'; import { InsideStackParamList } from '../stacks/types'; import { IAttachment } from '../definitions/IAttachment'; +import RocketChat from '../lib/rocketchat'; const styles = StyleSheet.create({ container: { @@ -51,6 +52,7 @@ interface IAttachmentViewProps { token: string; }; Allow_Save_Media_to_Gallery: boolean; + downloadFilePermission: string[]; } class AttachmentView extends React.Component { @@ -79,9 +81,25 @@ class AttachmentView extends React.Component { - const { route, navigation, theme, Allow_Save_Media_to_Gallery } = this.props; + canSaveToGallery = async () => { + const { Allow_Save_Media_to_Gallery, downloadFilePermission, rid } = this.props; + if (!Allow_Save_Media_to_Gallery) { + return false; + } + + // Servers older than 4.2 + if (!downloadFilePermission) { + return true; + } + + const permissionToDownload = await RocketChat.hasPermission([downloadFilePermission]); + return permissionToDownload[0]; + }; + + setHeader = async () => { + const { route, navigation, theme } = this.props; const attachment = route.params?.attachment; + const canSaveToGallery = await this.canSaveToGallery(); let { title } = attachment; try { title = decodeURI(title); @@ -91,8 +109,7 @@ class AttachmentView extends React.Component , - headerRight: () => - Allow_Save_Media_to_Gallery ? : null, + headerRight: () => (canSaveToGallery ? : null), headerBackground: () => , headerTintColor: themes[theme].previewTintColor, headerTitleStyle: { color: themes[theme].previewTintColor, marginHorizontal: 10 } @@ -193,7 +210,8 @@ class AttachmentView extends React.Component ({ baseUrl: state.server.server, user: getUserSelector(state), - Allow_Save_Media_to_Gallery: state.settings.Allow_Save_Media_to_Gallery ?? true + Allow_Save_Media_to_Gallery: state.settings.Allow_Save_Media_to_Gallery ?? true, + downloadFilePermission: state.permissions['mobile-download-file'] }); export default connect(mapStateToProps)(withTheme(withDimensions(withSafeAreaInsets(AttachmentView)))); From 37bddbf63919d75a5d4ebedcd27c01f05cde76d6 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 7 Dec 2021 10:08:16 -0300 Subject: [PATCH 11/15] Send rid to AttachmentView --- app/containers/UIKit/Image.tsx | 6 ++++-- app/stacks/types.ts | 1 + app/views/AttachmentView.tsx | 9 ++++++--- app/views/MessagesView/index.tsx | 6 ++++-- app/views/RoomView/index.js | 2 +- app/views/SearchMessagesView/index.tsx | 2 +- storybook/stories/UiKitMessage.js | 13 ++++++++++++- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/containers/UIKit/Image.tsx b/app/containers/UIKit/Image.tsx index 7b8dbf0ff56..040c232f842 100644 --- a/app/containers/UIKit/Image.tsx +++ b/app/containers/UIKit/Image.tsx @@ -1,10 +1,11 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { StyleSheet, View } from 'react-native'; import FastImage from '@rocket.chat/react-native-fast-image'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import ImageContainer from '../message/Image'; import Navigation from '../../lib/Navigation'; +import { KitContext } from './utils'; const styles = StyleSheet.create({ image: { @@ -46,7 +47,8 @@ export const Thumb = ({ element, size = 88 }: IThumb) => ( ); export const Media = ({ element, theme }: IMedia) => { - const showAttachment = (attachment: any) => Navigation.navigate('AttachmentView', { attachment }); + const { rid } = useContext(KitContext); + const showAttachment = (attachment: any) => Navigation.navigate('AttachmentView', { attachment, rid }); const { imageUrl } = element; // @ts-ignore return ; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index c9386d939c8..db227cdd0ae 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -225,6 +225,7 @@ export type InsideStackParamList = { E2EEnterYourPasswordStackNavigator: NavigatorScreenParams; AttachmentView: { attachment: IAttachment; + rid: string; }; StatusView: undefined; ShareView: { diff --git a/app/views/AttachmentView.tsx b/app/views/AttachmentView.tsx index a3087665a18..6b0460ed653 100644 --- a/app/views/AttachmentView.tsx +++ b/app/views/AttachmentView.tsx @@ -36,6 +36,7 @@ const styles = StyleSheet.create({ interface IAttachmentViewState { attachment: IAttachment; + rid: string; loading: boolean; } @@ -62,7 +63,8 @@ class AttachmentView extends React.Component { - const { Allow_Save_Media_to_Gallery, downloadFilePermission, rid } = this.props; + const { rid } = this.state; + const { Allow_Save_Media_to_Gallery, downloadFilePermission } = this.props; if (!Allow_Save_Media_to_Gallery) { return false; } @@ -92,7 +95,7 @@ class AttachmentView extends React.Component { return null; }; - showAttachment = (attachment: any) => { + showAttachment = (attachment: IAttachment) => { const { navigation } = this.props; - navigation.navigate('AttachmentView', { attachment }); + // @ts-ignore + navigation.navigate('AttachmentView', { attachment, rid: this.rid }); }; onLongPress = (message: IMessageItem) => { diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 241cd190241..c985075cb4d 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -639,7 +639,7 @@ class RoomView extends React.Component { showAttachment = attachment => { const { navigation } = this.props; - navigation.navigate('AttachmentView', { attachment }); + navigation.navigate('AttachmentView', { attachment, rid: this.rid }); }; onReactionPress = async (shortname, messageId) => { diff --git a/app/views/SearchMessagesView/index.tsx b/app/views/SearchMessagesView/index.tsx index a85df674590..532e51ea869 100644 --- a/app/views/SearchMessagesView/index.tsx +++ b/app/views/SearchMessagesView/index.tsx @@ -191,7 +191,7 @@ class SearchMessagesView extends React.Component { const { navigation } = this.props; - navigation.navigate('AttachmentView', { attachment }); + navigation.navigate('AttachmentView', { attachment, rid: this.rid }); }; navToRoomInfo = (navParam: IRoomInfoParam) => { diff --git a/storybook/stories/UiKitMessage.js b/storybook/stories/UiKitMessage.js index a9a9aba942b..6a4cd5b0d90 100644 --- a/storybook/stories/UiKitMessage.js +++ b/storybook/stories/UiKitMessage.js @@ -4,6 +4,7 @@ import { SafeAreaView, ScrollView, StyleSheet } from 'react-native'; import { storiesOf } from '@storybook/react-native'; import MessageContext from '../../app/containers/message/Context'; +import { KitContext } from '../../app/containers/UIKit/utils'; import { UiKitMessage } from '../../app/containers/UIKit'; import { themes } from '../../app/constants/colors'; @@ -44,6 +45,15 @@ const messageDecorator = story => ( ); +const kitDecorator = story => ( + + {story()} + +); + const stories = storiesOf('UiKitMessage', module) .addDecorator(story => {story()}) .addDecorator(story => ( @@ -51,7 +61,8 @@ const stories = storiesOf('UiKitMessage', module) {story()} )) - .addDecorator(messageDecorator); + .addDecorator(messageDecorator) + .addDecorator(kitDecorator); const Section = () => UiKitMessage([ From c1bf25f8004fb8b2dfb5eae9444fc65f73ec6bb8 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 8 Dec 2021 10:16:04 -0300 Subject: [PATCH 12/15] rid to ShareView --- app/views/ShareView/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/ShareView/index.tsx b/app/views/ShareView/index.tsx index 8527ae3db75..a3ad287aa2f 100644 --- a/app/views/ShareView/index.tsx +++ b/app/views/ShareView/index.tsx @@ -143,11 +143,12 @@ class ShareView extends Component { }; getPermissionMobileUpload = async () => { + const { room } = this.state; const db = database.active; const permissionsCollection = db.get('permissions'); const uploadFilePermissionFetch = await permissionsCollection.query(Q.where('id', Q.like('mobile-upload-file'))).fetch(); const uploadFilePermission = uploadFilePermissionFetch[0]?.roles; - const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission]); + const permissionToUpload = await RocketChat.hasPermission([uploadFilePermission], room.rid); // uploadFilePermission as undefined is considered that there isn't this permission, so all can upload file. return !uploadFilePermission || permissionToUpload[0]; }; From e6f3fa1076bd2254f6508f4287a87b87fac13256 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 8 Dec 2021 14:55:21 -0300 Subject: [PATCH 13/15] Revert "Send rid to AttachmentView" This reverts commit 37bddbf63919d75a5d4ebedcd27c01f05cde76d6. --- app/containers/UIKit/Image.tsx | 6 ++---- app/stacks/types.ts | 1 - app/views/AttachmentView.tsx | 9 +++------ app/views/MessagesView/index.tsx | 6 ++---- app/views/RoomView/index.js | 2 +- app/views/SearchMessagesView/index.tsx | 2 +- storybook/stories/UiKitMessage.js | 13 +------------ 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/app/containers/UIKit/Image.tsx b/app/containers/UIKit/Image.tsx index 040c232f842..7b8dbf0ff56 100644 --- a/app/containers/UIKit/Image.tsx +++ b/app/containers/UIKit/Image.tsx @@ -1,11 +1,10 @@ -import React, { useContext } from 'react'; +import React from 'react'; import { StyleSheet, View } from 'react-native'; import FastImage from '@rocket.chat/react-native-fast-image'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import ImageContainer from '../message/Image'; import Navigation from '../../lib/Navigation'; -import { KitContext } from './utils'; const styles = StyleSheet.create({ image: { @@ -47,8 +46,7 @@ export const Thumb = ({ element, size = 88 }: IThumb) => ( ); export const Media = ({ element, theme }: IMedia) => { - const { rid } = useContext(KitContext); - const showAttachment = (attachment: any) => Navigation.navigate('AttachmentView', { attachment, rid }); + const showAttachment = (attachment: any) => Navigation.navigate('AttachmentView', { attachment }); const { imageUrl } = element; // @ts-ignore return ; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index db227cdd0ae..c9386d939c8 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -225,7 +225,6 @@ export type InsideStackParamList = { E2EEnterYourPasswordStackNavigator: NavigatorScreenParams; AttachmentView: { attachment: IAttachment; - rid: string; }; StatusView: undefined; ShareView: { diff --git a/app/views/AttachmentView.tsx b/app/views/AttachmentView.tsx index 6b0460ed653..a3087665a18 100644 --- a/app/views/AttachmentView.tsx +++ b/app/views/AttachmentView.tsx @@ -36,7 +36,6 @@ const styles = StyleSheet.create({ interface IAttachmentViewState { attachment: IAttachment; - rid: string; loading: boolean; } @@ -63,8 +62,7 @@ class AttachmentView extends React.Component { - const { rid } = this.state; - const { Allow_Save_Media_to_Gallery, downloadFilePermission } = this.props; + const { Allow_Save_Media_to_Gallery, downloadFilePermission, rid } = this.props; if (!Allow_Save_Media_to_Gallery) { return false; } @@ -95,7 +92,7 @@ class AttachmentView extends React.Component { return null; }; - showAttachment = (attachment: IAttachment) => { + showAttachment = (attachment: any) => { const { navigation } = this.props; - // @ts-ignore - navigation.navigate('AttachmentView', { attachment, rid: this.rid }); + navigation.navigate('AttachmentView', { attachment }); }; onLongPress = (message: IMessageItem) => { diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index c985075cb4d..241cd190241 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -639,7 +639,7 @@ class RoomView extends React.Component { showAttachment = attachment => { const { navigation } = this.props; - navigation.navigate('AttachmentView', { attachment, rid: this.rid }); + navigation.navigate('AttachmentView', { attachment }); }; onReactionPress = async (shortname, messageId) => { diff --git a/app/views/SearchMessagesView/index.tsx b/app/views/SearchMessagesView/index.tsx index 532e51ea869..a85df674590 100644 --- a/app/views/SearchMessagesView/index.tsx +++ b/app/views/SearchMessagesView/index.tsx @@ -191,7 +191,7 @@ class SearchMessagesView extends React.Component { const { navigation } = this.props; - navigation.navigate('AttachmentView', { attachment, rid: this.rid }); + navigation.navigate('AttachmentView', { attachment }); }; navToRoomInfo = (navParam: IRoomInfoParam) => { diff --git a/storybook/stories/UiKitMessage.js b/storybook/stories/UiKitMessage.js index 6a4cd5b0d90..a9a9aba942b 100644 --- a/storybook/stories/UiKitMessage.js +++ b/storybook/stories/UiKitMessage.js @@ -4,7 +4,6 @@ import { SafeAreaView, ScrollView, StyleSheet } from 'react-native'; import { storiesOf } from '@storybook/react-native'; import MessageContext from '../../app/containers/message/Context'; -import { KitContext } from '../../app/containers/UIKit/utils'; import { UiKitMessage } from '../../app/containers/UIKit'; import { themes } from '../../app/constants/colors'; @@ -45,15 +44,6 @@ const messageDecorator = story => ( ); -const kitDecorator = story => ( - - {story()} - -); - const stories = storiesOf('UiKitMessage', module) .addDecorator(story => {story()}) .addDecorator(story => ( @@ -61,8 +51,7 @@ const stories = storiesOf('UiKitMessage', module) {story()} )) - .addDecorator(messageDecorator) - .addDecorator(kitDecorator); + .addDecorator(messageDecorator); const Section = () => UiKitMessage([ From 69ccae70cc77d229848b6f635e7e3ea4473b6514 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 8 Dec 2021 14:55:40 -0300 Subject: [PATCH 14/15] Revert "Start block download logic" This reverts commit 01afbc04757650576530064a46d169ae90f1d3c8. --- app/lib/methods/getPermissions.js | 3 +-- app/views/AttachmentView.tsx | 28 +++++----------------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index a0c63130ad1..b680a919632 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -56,8 +56,7 @@ const PERMISSIONS = [ 'edit-omnichannel-contact', 'edit-livechat-room-customfields', 'view-canned-responses', - 'mobile-upload-file', - 'mobile-download-file' + 'mobile-upload-file' ]; export async function setPermissions() { diff --git a/app/views/AttachmentView.tsx b/app/views/AttachmentView.tsx index a3087665a18..09e2d5d6184 100644 --- a/app/views/AttachmentView.tsx +++ b/app/views/AttachmentView.tsx @@ -26,7 +26,6 @@ import { getHeaderHeight } from '../containers/Header'; import StatusBar from '../containers/StatusBar'; import { InsideStackParamList } from '../stacks/types'; import { IAttachment } from '../definitions/IAttachment'; -import RocketChat from '../lib/rocketchat'; const styles = StyleSheet.create({ container: { @@ -52,7 +51,6 @@ interface IAttachmentViewProps { token: string; }; Allow_Save_Media_to_Gallery: boolean; - downloadFilePermission: string[]; } class AttachmentView extends React.Component { @@ -81,25 +79,9 @@ class AttachmentView extends React.Component { - const { Allow_Save_Media_to_Gallery, downloadFilePermission, rid } = this.props; - if (!Allow_Save_Media_to_Gallery) { - return false; - } - - // Servers older than 4.2 - if (!downloadFilePermission) { - return true; - } - - const permissionToDownload = await RocketChat.hasPermission([downloadFilePermission]); - return permissionToDownload[0]; - }; - - setHeader = async () => { - const { route, navigation, theme } = this.props; + setHeader = () => { + const { route, navigation, theme, Allow_Save_Media_to_Gallery } = this.props; const attachment = route.params?.attachment; - const canSaveToGallery = await this.canSaveToGallery(); let { title } = attachment; try { title = decodeURI(title); @@ -109,7 +91,8 @@ class AttachmentView extends React.Component , - headerRight: () => (canSaveToGallery ? : null), + headerRight: () => + Allow_Save_Media_to_Gallery ? : null, headerBackground: () => , headerTintColor: themes[theme].previewTintColor, headerTitleStyle: { color: themes[theme].previewTintColor, marginHorizontal: 10 } @@ -210,8 +193,7 @@ class AttachmentView extends React.Component ({ baseUrl: state.server.server, user: getUserSelector(state), - Allow_Save_Media_to_Gallery: state.settings.Allow_Save_Media_to_Gallery ?? true, - downloadFilePermission: state.permissions['mobile-download-file'] + Allow_Save_Media_to_Gallery: state.settings.Allow_Save_Media_to_Gallery ?? true }); export default connect(mapStateToProps)(withTheme(withDimensions(withSafeAreaInsets(AttachmentView)))); From f56fde13fa2a1c92b86b375da418641d732d1d90 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Thu, 9 Dec 2021 15:38:14 -0300 Subject: [PATCH 15/15] minor tweak on canUpload --- app/containers/MessageBox/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 12b4d86cf5d..9fe3d11a16b 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -679,8 +679,9 @@ class MessageBox extends Component { }; canUploadFile = (file: any) => { + const { permissionToUpload } = this.state; const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = this.props; - const result = canUploadFile(file, FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize); + const result = canUploadFile(file, FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize, permissionToUpload); if (result.success) { return true; }