Enforce the file type of the featured image, background media, and video block#2737
Enforce the file type of the featured image, background media, and video block#2737swissspidy merged 19 commits intodevelopfrom
Conversation
This doesn't disable the 'Select' button now, though it shows a notice both in the AMP Story editor and the normal post or page block editor.
Before, this simply displayed a notice. Now, it actually disables the button.
…tion I didn't write this originally, but I used this same logic for the file type notice. So instead of simply copy and pasting it, this extracts it into a separate function.
|
Does this also apply to the video block? Users should be disallowed from selecting or uploading anything but MP4 videos. |
Hi @westonruter, no, it doesn't apply to the video block or to the 'Background Media' control. I still need to work on that. |
Refactor much of the existing logic, which was for featured images. Rename a file and many functions.
There was duplicated logic, so use that function in place of the copy-pasted code.
It looks like that wasn't preventing .mov files from appearing. Also, the new logic uses ALLOWED_MEDIA_TYPES as passed in allowedTypes. It checks that the attachment.get( 'type' ) matches that, and the attachment.get( 'type' ) is never 'video/mp4'. That is only the attachment.get( 'mime' ).
There was a file that should have been moved, but I forgot to delete it.
There an error: fatal: Path 'amp.php' exists on disk, but not in 'eb9bb06b77d811ba80ca70ec60fbe551aea4ca73'. Pascal had suggested an empty commit for this.
It looks like this needed a 'select' handler. So add one here.
|
Mainly Working This is mainly working for the 'Background Media,' Core Video block, and the featured image. If any of them have the wrong mime type, like The same applies for uploading other incorrect types, like I still need to test this more, and I'm working on a unit test for |
Add a mockClasses.js file to store some mocks. And use this for the tests in isFileTypeAllowed.js.
|
The first 3 scenarios are new in this PR, the last 2 are to test regressions.
|
This comment has been minimized.
This comment has been minimized.
That seems to have caused .mov files to appear in the Background Media. So revert the change to that, and instead change isFileTypeAllowed() to return true whene a mime type matches a value in the allowedTypes array.
This PR already blocked selecting uploading them. But if they were uploaded before, they would still display in the 'Media Library' tab of the Media Library. So this blocks displaying them in that tab if they were uploaded before.
This caused a failed Travis build, as it was imported but not used.
Before, some of these were joined using a comma. Instead, keep to the convention in the rest of this PR.
|
Request For Review Hi @swissspidy and @westonruter, In the first 3 scenarios above, this displays a notice in the Media Library and disables the 'Select' button: Thanks, and have a great weekend! |
There shouldn't have been a period in the middle of the sentence.
westonruter
left a comment
There was a problem hiding this comment.
Attempting to select a MOV video to upload for page background successfully results in the Select button being disabled and a warning message displayed:
Same thing happened successfully when attempting to upload a video via the Media Library button in the video block:
Nevertheless, it does not successfully restrict the video type when selecting the Upload button from the video block:
|
Is applying the restriction to the Video block's Upload button too difficult to include here? |
|
Video Block Upload Button Hi @westonruter,
Good question. I'll look at that tomorrow if that's alright. It looks like if the accept prop were Maybe there's a way to change that with the |
…mp4' files There was already logic to prevent uploading in the Media Library. But this applies to the 'Upload' button in the block's Edit component, not the Media Library.
|
Video Upload Button Hi @westonruter,
Sure, a72b3e5 restricts the upload type of the Video block to `video/mp4': Sorry for the delay. |
westonruter
left a comment
There was a problem hiding this comment.
It works! I'll let @swissspidy do a final review of the JS prior to merging.
|
Thanks, @westonruter! |
|
Request For Review Hi @swissspidy, Here's the expected behavior. Thanks, and hope you have a great weekend. |






.movfile, is the wrong type, it displays a notice and disables the 'Select' button.allowedTypesproperty of theMediaUploadcomponent.Here's the notice:
Fixes #2727