[MM-29216] Don't allow sharing of files if file uploads are disabled (#4857)

* Don't allow sharing of files if file uploads are disabled

* Remove snapshot

* Fix iOS message
This commit is contained in:
Miguel Alatzar 2020-10-02 10:03:31 -07:00 committed by GitHub
parent a5cb92876c
commit b8ce726b0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 2 deletions

View file

@ -276,6 +276,7 @@
"mobile.file_upload.browse": "Browse Files",
"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.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.",

View file

@ -29,6 +29,7 @@ class ShareViewController: SLComposeServiceViewController {
private var teamsVC: TeamsViewController = TeamsViewController()
private var maxMessageSize: Int = 0
private var canUploadFiles: Bool = true
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@ -37,6 +38,7 @@ class ShareViewController: SLComposeServiceViewController {
sessionToken = store.getToken()
serverURL = store.getServerUrl()
maxMessageSize = Int(store.getMaxPostSize())
canUploadFiles = store.getCanUploadFiles()
}
// MARK: - Lifecycle methods
@ -94,6 +96,8 @@ class ShareViewController: SLComposeServiceViewController {
showErrorMessage(title: "", message: "Authentication required: Please first login using the app.", VC: self)
} else if store.getCurrentTeamId() == "" || store.getMyTeams().count == 0 {
showErrorMessage(title: "", message: "You must belong to a team before you can share files.", VC: self)
} else if !canUploadFiles {
showErrorMessage(title: "", message: "File uploads from mobile are disabled. Please contact your System Admin for more details.", VC: self)
} else {
extractDataFromContext()
}

View file

@ -22,5 +22,6 @@
-(NSArray *)getMyTeams;
-(NSString *)getServerUrl;
-(NSString *)getToken;
-(BOOL)getCanUploadFiles;
-(void)updateEntities:(NSString *)content;
@end

View file

@ -207,6 +207,21 @@
return DEFAULT_SERVER_MAX_POST_SIZE;
}
-(BOOL)getCanUploadFiles {
NSDictionary *config = [self getConfig];
NSDictionary *license = [self getLicense];
if (config != nil && license != nil) {
NSString *enableFileAttachments = [config objectForKey:@"EnableFileAttachments"];
NSString *isLicensed = [license objectForKey:@"IsLicensed"];
NSString *compliance = [license objectForKey:@"Compliance"];
NSString *enableMobileFileUpload = [config objectForKey:@"EnableMobileFileUpload"];
return ![enableFileAttachments isEqual:@"false"] &&
([isLicensed isEqual:@"false"] || [compliance isEqual:@"false"] || ![enableMobileFileUpload isEqual:@"false"]);
}
return YES;
}
-(void)updateEntities:(NSString *)content {
[self.bucket writeToFile:@"entities" content:content];
}
@ -272,6 +287,10 @@
return [[self.entities objectForKey:@"general"] objectForKey:@"config"];
}
-(NSDictionary *)getLicense {
return [[self.entities objectForKey:@"general"] objectForKey:@"license"];
}
-(NSDictionary *)getMyPreferences {
return [[self.entities objectForKey:@"preferences"] objectForKey:@"myPreferences"];
}

View file

@ -66,6 +66,7 @@ export default class ExtensionPost extends PureComponent {
channels: PropTypes.object.isRequired,
currentUserId: PropTypes.string.isRequired,
getTeamChannels: PropTypes.func.isRequired,
canUploadFiles: PropTypes.bool.isRequired,
maxFileSize: PropTypes.number.isRequired,
navigation: PropTypes.object.isRequired,
teamId: PropTypes.string.isRequired,
@ -377,7 +378,7 @@ export default class ExtensionPost extends PureComponent {
};
onClose = (data) => {
ShareExtension.close(data.nativeEvent ? null : data);
ShareExtension.close(data?.nativeEvent ? null : data);
};
onPost = () => {
@ -555,6 +556,7 @@ export default class ExtensionPost extends PureComponent {
delayPressIn={0}
pressColorAndroid='rgba(0, 0, 0, .32)'
onPress={this.onPost}
disabled={!this.props.canUploadFiles}
>
<View style={styles.left}>
<PaperPlane
@ -625,6 +627,14 @@ export default class ExtensionPost extends PureComponent {
return this.renderErrorMessage(teamRequired);
}
if (!this.props.canUploadFiles) {
const uploadsDisabled = formatMessage({
id: 'mobile.file_upload.disabled',
defaultMessage: 'File uploads from mobile are disabled. Please contact your System Admin for more details.',
});
return this.renderErrorMessage(uploadsDisabled);
}
if (this.token && this.url) {
if (hasPermission === false) {
const storage = formatMessage({

View file

@ -24,6 +24,7 @@ describe('ExtensionPost', () => {
channels: {},
currentUserId: 'current-user-id',
getTeamChannels: jest.fn(),
canUploadFiles: true,
maxFileSize: 1024,
navigation: {
setOptions: jest.fn(),
@ -39,6 +40,7 @@ describe('ExtensionPost', () => {
);
const instance = wrapper.instance();
instance.renderErrorMessage = jest.fn();
const postMessage = (message) => {
wrapper.setState({value: message});
@ -65,4 +67,10 @@ describe('ExtensionPost', () => {
expect(Alert.alert).not.toHaveBeenCalled();
});
test('should render file uploads disabled message when canUploadFiles is false', () => {
wrapper.setState({loaded: true});
wrapper.setProps({canUploadFiles: false});
expect(instance.renderErrorMessage).toHaveBeenCalledWith('File uploads from mobile are disabled. Please contact your System Admin for more details.');
});
});

View file

@ -6,7 +6,7 @@ import {connect} from 'react-redux';
import {getAllChannels, getCurrentChannel, getDefaultChannel} from '@mm-redux/selectors/entities/channels';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
import {getConfig} from '@mm-redux/selectors/entities/general';
import {getConfig, canUploadFilesOnMobile} from '@mm-redux/selectors/entities/general';
import {getTeamChannels} from 'share_extension/android/actions';
import {getAllowedServerMaxFileSize} from 'app/utils/file';
@ -25,6 +25,7 @@ function mapStateToProps(state) {
channelId: channel?.id,
channels: getAllChannels(state),
currentUserId: getCurrentUserId(state),
canUploadFiles: canUploadFilesOnMobile(state),
maxFileSize: getAllowedServerMaxFileSize(config),
teamId: getCurrentTeamId(state),
};