My client wants to require their users to fill a form before downloading any file from Plone. For some other content-types we have created a default view where we require to fill the form and after that we let the users download the file. I have done the same for the default File content-type and so far so good.
But Files have another feature: when visiting their URL the file is downloaded automatically without showing any other view (without redirecting to /view or the relevant default_view).
Do you know if one can override such a feature for File content-type objects? We are using Plone 5.2 in this project.
Thank you in advance,
I AM NOT sure about this, but I think:
Any file (etc) that doesn't not have permissions set can be downloaded (if the user knows what he/she is doing)
If you enable a workflow (you can do this in the content type control panel), and set the state to 'private', it can not be downloaded by going to the url (instead, you will be asked to log in)
You could make a new view (instead of the default file_view) that could 'download it to you' and have this part of the 'questions stuff'
There is a setting for file you might have to change, I can't remember its name, but think it is something like 'use view action'
The workflow trick works for private files but not for public ones. I'll keep investigating this.
The 4th trick works only in Plone generated tempaltes or in those templates where the setting is check and it appends the /view to the URL, but the file is downloadable anyway.
It must me related to the
marshal:primary="true" key present in the plone.app.contenttypes File model definition file file.xml. If I create a new content-type with the same model but without the said key, the file is not directly downloadable.
The point is, where is this download triggered and how can I hook into it, otherwise I will have to create a new content-type and migrate all 15000+ files into the new content-type
Taken from memory:
There is a '@@download' view, and a '@@display-file'
(so http://path/to/file/@@download (or maybe http://path/to/file/field_name/@@download (or something similar).
So, maybe if you don't set marshall primary to true, those views do not know 'which field to download' (since a content type could have several file-fields.
we created a package just for this purpose.
You make the content restricted but link to it and then this plugin lets you customise what happens if someone is required to login to get access, such as redirect them to an easyform. Making them private is probably the best way ensure all views are redirected.
It hasn't been updated lately so no idea if it will work on plone5.2.
There is one other option. For some changes to collective.googleanalytics I had to intercept all downloads of files. You can look at the code I wrote for that using zope events. that might let you intercept a download without having to override the content type.
Thank you for your answers.
I ended creating a content-type that is basically the same as the standard File type but without the marshal:primary stuff, and now I can create a custom view for it with my form-filling-requirements.
I have migrated all File content objects to the new content-type using ftw.upgrade's inplace migrator