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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SomebodySysop’s picture

Status: Active » Needs review
FileSize
1.53 KB
6.28 KB

I'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.

shittii’s picture

Excellent 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. :)

SomebodySysop’s picture

OK, here is the patched module and install file.

dezolt384’s picture

thanks, 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.

SomebodySysop’s picture

The code is only designed to select ONE role. Sorry!

bmeier’s picture

I'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.

bmeier’s picture

FileSize
37.81 KB

I 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.

bmeier’s picture

Version: 5.x-1.0-beta6 » 6.x-1.0-rc2
FileSize
36.56 KB

I'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.

higgins’s picture

Category: feature » bug
Status: Needs review » Needs work

This 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!

pjsz’s picture

These 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.

Jody Lynn’s picture

Category: bug » feature
tomsm’s picture

subscribing

Shiny’s picture

subscribing