Download & Extend

Respect file type restrictions in media browser library view

Project:Media
Version:7.x-2.x-dev
Component:Media Browser
Category:task
Priority:normal
Assigned:Dave Reid
Status:needs work
Issue tags:Media Initiative, sprint

Issue Summary

Use hook_views_query_alter() to respect file type restrictions from the media browser configuration.

Comments

#1

Adding an issue tag...

#2

Assigned to:becw» Anonymous
Status:active» needs review

Here's a patch.

AttachmentSizeStatusTest resultOperations
1293908-2-media-restrict_library_view_by_browser_params.patch1.76 KBIdlePASSED: [[SimpleTest]]: [MySQL] 0 pass(es).View details | Re-test

#3

Component:Code» Media Browser

#4

Status:needs review» needs work

The code looks good but it doesn't work well with the restriction by "URI Scheme". I suspect it may be caused by a conflict with the file_extensions params. The "file extension" is required in the "file" field settings and the view alter patch check for !empty($params['file_extensions']).

Another problem is that when you change any of the exposed filter the view_query_filter doesn't seem to be applied.

#5

unfortunately, this probably ultimately depends on the monster patch over at the file entity module: http://drupal.org/node/1292382

#6

Another problem is that when you change any of the exposed filter the view_query_filter doesn't seem to be applied.

That's because media_get_browser_params() gets set with the URL query parameters, which are different when submitting the type from views/ajax.

#7

[10:42pm] aaronwinborn: is there a way to store a value to be saved with the view instance, based for example on $_GET from the referring page, for later use with a hook_views_alter_query() when later calling views/ajax?
[10:42pm] merlinofchaos: aaronwinborn: Wow, uh.
[10:42pm] aaronwinborn: this is for #1293908-6: Respect file type restrictions in media browser library view
[10:43pm] merlinofchaos: aaronwinborn: Man. I dunno. Maybe you could add some .js to put extra data in the .ajax call by modifying Drupal.ajax[base]
[10:43pm] merlinofchaos: That's all I can think of.
[10:43pm] aaronwinborn: that would probably work, thanks merlinofchaos
[10:45pm] davereid: aaronwinborn: probably a better solution would be to somehow alter the exposed filter for file type in the view to only allow the options in the field
[10:45pm] • davereid pulls another idea out of his 'crazy bad idea hat'
[10:47pm] aaronwinborn: davereid: yes, that's what my (currently unsubmitted) patch does. only it forgets by the time we change an exposed filter, because we've lost the original context
[10:47pm] davereid: ugh

#8

Status:needs work» needs review

This takes care of those concerns, and also locks the type select to the allowed types. Tested against WYSIWYG and the default image field of story.

AttachmentSizeStatusTest resultOperations
media-restrict_library_view_by_browser_params-1293908-8.patch5.3 KBIdlePASSED: [[SimpleTest]]: [MySQL] 26 pass(es).View details | Re-test

#9

Status:needs review» needs work

Patch at #8 does not work for file field (plain file or remote youtube video) - view library displays no results.

Applied against 7.x-2.0-unstable3+1-dev

#10

Assigned to:Anonymous» Dave Reid

#11

john, did you flush your cache?

#12

Oki done some testing with this and here are my results.

Patch applies cleanly, Hunk 1 has on offset of 46 though...

Cache needs to be cleared after its applied as well.

It does the trick for fields. It both restrict upload of new files to specified extensions and restrict the choices in the Views library the same.

For the WYSIWYG though it gets half there. It does restrict upload, but still lists everything.

However, if you try to upload a file with a not listed extension, it does complain, but then the Views library shows nothing at all. Just cancel the browser and reopen it again and the files are back.

Seems like something is not going absolutely correct with the plugin.

#13