Skip to content

Commit 8ca5db0

Browse files
authored
IBX-8111: Validated file mime type for multi file upload without specified location mapping (#1620)
1 parent cc6f2e7 commit 8ca5db0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/bundle/ui-dev/src/modules/multi-file-upload/services/multi.file.upload.service.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ const readFile = function (file, resolve, reject) {
3232
this.readAsDataURL(file);
3333
};
3434
const findFileTypeMapping = (mappings, file) => mappings.find((item) => item.mimeTypes.find((type) => type === file.type));
35+
const checkIsFileWithinMimeTypes = (mimeTypes, file) => !!mimeTypes.find((type) => type === file.type);
3536
const isMimeTypeAllowed = (mappings, file) => !!findFileTypeMapping(mappings, file);
3637

37-
const checkFileTypeAllowed = (file, locationMapping) => (!locationMapping ? true : isMimeTypeAllowed(locationMapping.mappings, file));
38+
const checkFileTypeAllowed = (file, locationMapping, config) => {
39+
return !locationMapping
40+
? config.defaultMappings.some((mapping) => checkIsFileWithinMimeTypes(mapping.mimeTypes, file))
41+
: isMimeTypeAllowed(locationMapping.mappings, file);
42+
};
3843

3944
const detectContentTypeMapping = (file, parentInfo, config) => {
4045
const locationMapping = config.locationMappings.find((item) => item.contentTypeIdentifier === parentInfo.contentTypeIdentifier);
@@ -262,7 +267,7 @@ export const checkCanUpload = (file, parentInfo, config, errorCallback) => {
262267
);
263268
}
264269

265-
if (!checkFileTypeAllowed(file, locationMapping)) {
270+
if (!checkFileTypeAllowed(file, locationMapping, config)) {
266271
errorMsgs.push(Translator.trans(/*@Desc("File type is not allowed")*/ 'disallowed_type.message', {}, 'ibexa_multi_file_upload'));
267272
}
268273

0 commit comments

Comments
 (0)