Saturday, June 11, 2011

Access control of Views

It is possible that view will show the data that is not allowed to see by setting of permission.

Using PHP validation to the argument is very normal.

The php is look like the following:


global $user;
return arg(1) == $user->uid || user_access('access user profiles');

?>

Note:
users/2/edit
arg() is system-level item (not just views), and with the following values
arg(0) = 'users'
arg(1) = '2'
arg(2) = 'edit'





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));


?>


** Also refer to Views to display nodes based on ACL permission.

No comments: