1

I would like to control access to specific articles or categories of articles depending on a boolean variable in a user's profile.

For example, this would be on a site where a user gets access to all kinds of data about their product after they purchase it. I would like to manually enable or "tick" a boolean field on their profile which then allows them to see the corresponding information when they browse the website.

I hope you understand what I'm trying to say.

I have already set up a few fields on the user profiles and I'm trying to make it work using the Rules and Content Access modules but I'm not sure if I'm heading in the right direction. I have thought about just setting this up with a "View" but I think the content would still be accessible to everyone by default if they have a link or through Google?

If someone could point me in the right direction, that would be great. Thanks in advance!

1

I got it working, for the sake of anyone ever needing this functionality and stumbling upon this thread:

You'll need the Access Control and ACL modules. The combination of these allows you to set "per user" access for each individual node. For the checkboxes on a profile or page, you'll need to use the Entity Reference module and create a field on the profiles for that type of content. You can then set that field up as checkboxes.

For the final part, you'll need the Rules module and set up two rules: one to "Grant Access per user" and grant view access when a specific value of the checkboxes is true and one to "Revoke Access per user" when values have changed. You'll need to play around with the rule's conditions to make it suit your needs.

0

Content Access is a roles-based access control module. So, you must have created a role for your "controlled access" content. And setup the Content Access settings on your content types. From here, you could use standard, Drupal user admin to add remove users to/from this role. Done.

But if you want to assign this role dynamically, Rules is a place you can do it.

Create a rule that triggers on the "Before saving a user account" event. Add a "Data comparison" condition to test your boolean field's value. Select "account" then "" in the Data Selector field. For the Value field, select the value you want to trigger from (most likely the 'on' value for your boolean). Now, add the "Add user role" action, and select your "controlled access" role. Save. And test.

You'll also want create an inverse rule to remove the role.

Good luck!

  • Hello, thanks for your response! If I understand correctly, you mean I should make a role that allows access to the content and then automatically give a user that role when the boolean is true using Rules? I understand the approach (I think) but wouldn't that require me to create a role for each product? And if a user would get access to several products, I have to stack user roles? I've looked into the Node Access module which (with a user reference plugin) allows me to select specific users who can view this content but perhaps I can point that to the boolean field in some way? Thanks – Bram May 2 '14 at 20:03

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.