Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I understand that a file is uploaded as Private depending upon users access to node the file is being attached to and 'view uploaded files' permission.
I'm wondering how difficult it would be to go a step further, and only allow a user to download the file if he has a particular role?
Like, if we added a select box in the node called "Role(s) Required for Private File Download", and only allowed a user to download the Private files in that node if they had those permission(s), if present.
What do you think?
Comment | File | Size | Author |
---|---|---|---|
#8 | private_upload.module.txt | 36.56 KB | bmeier |
#7 | private_upload.module.txt | 37.81 KB | bmeier |
#3 | private_upload.module.txt | 34.95 KB | SomebodySysop |
#3 | private_upload.install.txt | 1.53 KB | SomebodySysop |
#1 | private_upload.ogr_.patch | 6.28 KB | SomebodySysop |
Comments
Comment #1
SomebodySysop CreditAttribution: SomebodySysop commentedI've modified private_upload.module to support assigning a role to private uploads. That is, if you upload a file as "private", you can additionally say: "Only users who have Role A can download this file.".
Attached is patch to private_upload.module and new private_upload.install file.
Please let me know what you think.
Comment #2
shittii CreditAttribution: shittii commentedExcellent addition! Unfortunately I don't have the know-how to patch the module or review your code. Maybe the module author starbow can do it. Thanks anyway. :)
Comment #3
SomebodySysop CreditAttribution: SomebodySysop commentedOK, here is the patched module and install file.
Comment #4
dezolt384 CreditAttribution: dezolt384 commentedthanks, it works perfectly!! but i've another issue: i can't select multiple roles.
how can i fix that?
Other solution could be selecting a single role leaving unaffected other permission.
Comment #5
SomebodySysop CreditAttribution: SomebodySysop commentedThe code is only designed to select ONE role. Sorry!
Comment #6
bmeier CreditAttribution: bmeier commentedI'm in the process of updating this code into 6.x-1.0-RC2. I can set and save a role but no functionality is added (the only requirement for viewing a private file is to be an authenticated user). I think this may be because authenticated users will have the permission to view the node and therefore the file attached to it regardless of specific role.
I'm not very experienced with Drupal but I'll post my finished code when I figure this out. I'll also see about being able to select multiple roles.
EDIT: I have it working for a single role but I'm going to add multiple role support. It checks to see if the node has any specific permissions and if so checks if the user has access, otherwise it grants access based on authenticated or anonymous.
Comment #7
bmeier CreditAttribution: bmeier commentedI spent some time on multiple roles and got check boxes to display for each role (and have the correct default value) but I don't know how to access their values in private_upload_form_alter. Any help would be great.
I've attached the working code for single roles I put "//MOD" tags wherever I changed things. I apologize if my coding style is awkward this is the first module I've worked on.
Comment #8
bmeier CreditAttribution: bmeier commentedI've finished the multiple role system (a good learning experience for me) if anyone else would like to use it. You can use the install file supplied by SomebodySysop above.
Edit: The javascript for this is really broken I don't know how to deal with it, if a file is uploaded the initial permissions you select are discarded. Afterwards if you edit the form again it will work as intended. Again any help would be great.
Comment #9
higgins CreditAttribution: higgins commentedThis module's exactly what I was looking for - file upload, downloadable for a specific user role!!! Great!
I'm quite familiar with PHP programming but I'm a drupal newb so I need to ask u for help on SomebodySysop's code (post #3).
But after I changed the code to yr code (module and install file), installed the module, I get this error:
warning: Missing argument 1 for private_upload_menu() in /home/user/public_html/drupal/modules/private_upload/private_upload.module on line 45
Seems to me that the function private_upload_menu is missing its required argument. But where can I fix that?
Also, if I create a node and attach a file, I miss the checkbox for role (which was the old 'private' field). I assume, that this is caused by the missing argument which should be passed on the the function (see above). I'm using drupal 6.12!
Anyone has an idea how I can fix that issue? Would desperately need this module to work.
Any help appreciated, THANX!
Comment #10
pjsz CreditAttribution: pjsz commentedThese patches did not work for me. I downloaded the patched module and diffed it with patch my patched version and got many diffs.
Still trying. Thanks.
Comment #11
Jody LynnComment #12
tomsm CreditAttribution: tomsm commentedsubscribing
Comment #13
Shiny CreditAttribution: Shiny commentedsubscribing