3

I am having a site that hosts a number of content items (nodes) that are available to registered users. We would like to make some of those data available to anonymous users, too, via a view. I have encountered so far two issues:

  1. The nodes have attachments and currently the attachments are saved in Drupal's private storage. When an anonymous user will try to access the attachment directly, they will see an error.

  2. Currently, I deny to anonymous users the permission to View published content. Thus, when a user clicks a link to a node, he will see an Access Denied error. This can be perhaps solved by using Content Access.

The solution I can think of is to clone the nodes I want to make public and make public their cloned counterparts but I dislike data copying as a practise. Any other ideas?

4

Just add a field to your nodes, similar to the "checkbox" as described in the question "How to allow users to post content and easily overrule its default access settings?". That field is used when creating a node, to indicate if the node should be viewable by anonymous users also (the default probably being "no").

With that, you could use the Rules module and the Content Access module to implement what you're looking for, similar to what I described in my answer to that same question mentioned above.

This approach should work for brand new nodes being created, while it should also work if you add such field to existing nodes. Though you'd have to experiment a bit to see which Rules "Event" is the bet fit in your case (I'd assume that node create and/or node update is what you'd need).

If you only want "some of those data" to be available to anonymous users, then you may want to add the Field Permissions module also (so that only the relevant fields can be viewed by anonymous users.

Video tutorials

If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework, organized in 7 chapters.

  • 1
    +1 Very elegant answer but I haven't had the time to check it how it will work. I haven't used Rules so far, so will the same logic apply if I add a "checkbox" to already existing nodes and set its value, manually, programmatically or with Views Bulk Operations? – Yannis P. Feb 17 '16 at 13:31
  • 1
    Ok I finally implented the Rules + Content Access solution and it works like a charm! Note: I used a boolean field and had to create two rules, one for changing the field to True that will Grant Access to anonymous users and one for when the field changes to False that will Revoke view access from anonymous users – Yannis P. Feb 17 '16 at 21:43
  • OK, great, and "merci" for accept. Just slighty expanded my answer a bit, trying to address your first comment. Make sure to some day watch those great videos ... after you'll get used to using Rules, you'll find dozens of use cases for it (and don't forget the "Flag" module, which offers tons of other possibilities). If you want more "Rules" use cases, have a look at my various answers containing "Rules" ... – Pierre.Vriens Feb 17 '16 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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