Views to display nodes based on ACL permission

mr.andrey - August 14, 2009 - 17:04
Project:ACL
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hello,

We have a setup where someone can buy a video, and on purchase completion (ACL + Content Access + Ubercart) they get an ACL view access. The video shows up only if they have this specific permission, but they can still access the node itself (with a video placeholder) without that permission.

I would like to create a view for purchased videos. One way to do that would be to pull all the nodes that have specific ACL view permission (as opposed to node access in general).

Is there a way to do this?

Any other ideas on how I can accomplish this?

Thanks,
Andrey.

#1

mr.andrey - September 26, 2009 - 15:51

I ended up using a default argument with PHP code. It checks for all the ACL view permissions for the current user and returns the list of nodes.

Here's how to do it:

Under Arguments, create a new argument: "Node: Nid"

Under "Action to take if argument is not present", select "Provide default argument"

Set the "Default argument type" to "PHP Code", and enter the following:

global $user;
return db_result(db_query("SELECT GROUP_CONCAT(CAST(an.nid AS CHAR) SEPARATOR ',') FROM {acl_user} au INNER JOIN {acl_node} an ON au.acl_id = an.acl_id WHERE an.grant_view = 1 AND au.uid = %d", $user->uid));

Then check "Allow multiple terms per argument", and click "Update".

Best,
Andrey.

#2

salvis - September 28, 2009 - 14:20

Thanks for sharing this. I wish we had a good place for keeping such snippets — the issues queue is not really the right place...

#3

mr.andrey - September 28, 2009 - 15:25

I use Vim for note keeping. It has folds, so you can keep things very organized for yourself.

Cheers,
Andrey.

#4

mr.andrey - September 28, 2009 - 17:52

And just for reference, if you're using Taxonomy Access module, and want to provide and argument for explicit node view permission based on a term and a role that has permission to view it, here's the mysql query for that:

SELECT GROUP_CONCAT(CAST(tn.nid AS CHAR) SEPARATOR ',') FROM term_node tn INNER JOIN term_access ta ON tn.tid = ta.tid WHERE ta.rid IN (SELECT ur.rid FROM users_roles ur WHERE ur.uid = <your user id goes here>)
AND ta.grant_view = 1

Best,
Andrey.

#5

salvis - September 28, 2009 - 17:52

I mean here on d.o...

 
 

Drupal is a registered trademark of Dries Buytaert.