1

I know there is https://www.drupal.org/project/field_permissions module, which allows to set field permissions per role, however what I need is to provide each individual field access permissions. As put on https://www.drupal.org/node/1376182

It looks that there is no module allowing to restrict access to certain files / images per role. What I think about is having checkboxes beside each file/image where to select the roles to have view access to the according entry.

I can't believe this was not implemented before, so hopefully someone can point out a viable solution.

Edit: I've got couple responses confused about what I wanted, so I believe I have to elaborate little more.

Field Permissions set role permissions for the field across all the nodes. What I am looking for is role permissions for individual field PER NODE. For example, an admin for Drupal 7 site could edit node 1 and make the file attached to it viewable to role "subscriber", but that wouldn't change any permission for another file attached to node 2. I hope it is now clear.

5
  • "If node 1 has a filefield pointing to file 1 (or image field pointing to image1), then I want be able to indicate that (eg) role1 (only) has access to it. Similar for node 2, with file 2 (or image 2) and role 2". This seems to be a possible interpretation of what you're asking for. Am I close? If not can you provide a similar "sample" with what you are asking for? Commented Mar 19, 2016 at 8:19
  • 1
    Please read my edit.
    – Nick
    Commented Mar 19, 2016 at 10:07
  • Aha, now we have a clear question (and I think my "guess" was close, right? If not can you tell me what I was missiing? Commented Mar 19, 2016 at 10:14
  • 1
    Right. Do you have any solution?
    – Nick
    Commented Mar 19, 2016 at 10:17
  • I think so ... read my answer and let me know what you think of it (or if I need to further refine/detail it). and guess what, I even have a plan b (if plan a fails ...). Commented Mar 19, 2016 at 10:31

3 Answers 3

1

Not sure if it is going to be the best/most elegant solution, but here is "an" approach that might work:

  • Use the Entity reference module to replace your file field in your existing content type with a reference to some other content type (say Resource).
  • Attach your files to nodes of content type Resource (so not in your already existing content type nodes).
  • Use the Content Access module to implement the refined access that you are looking for, but applied to that Resource content type.
  • Create some testcase(s) to verify how that refenced Resource node is going to be shown in your original nodes.

Get the idea? Pretty basic Drupal techniques (to KeepItSuperSimple, aka KISS).

I haven't tested it (yet) while writing this answer, but I bet functionally it will behave exactly as what you'd want. And guess what: no need for the field permissions module to make this work.

FYI: the above is a D7-equivalent of how I used to create such kinds of related content in D6 already (also using the Content Access module, and I believe in D6 it was "node reference" or something like that).

2
  • Sorry, Pierre, but instead of using one module you are suggesting to use two more and additional content type making the whole task too complicating, so I can not accept your answer.
    – Nick
    Commented Mar 19, 2016 at 11:32
  • No problem, thanks for the feedback anyway (I have another opinion but its fine to disagree, no?). Expect an updated answers then that will include an alternative approach. Which may only be tomorrow or so, since I need to first do some preparation and QA-testing to verify what I have in mind (to avoid it gets perceived as guessing only). Commented Mar 19, 2016 at 11:37
0

I not exactly understand your request. With field_permission you can set access permissions for each individual field. For example you can decide that a role can view and edit a field, instead another role can only view the same field.

1
  • Please read my edit.
    – Nick
    Commented Mar 19, 2016 at 10:08
0

I solved this problem using some code in the theme templates. Still I believe there should be a Drupal module for this specific purpose. There are per individual node permissions (not per content type, but individual nodes), so I don't get why there shouldn't be per individual field permission modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.