0

I have a lot of user-generated content that I want to restrict to only be viewed by 'in-network' peers. I was originally trying to use Organic Groups but it's way more functionality than I need and I couldn't use it across all the entities I wanted to. Also, I could never get the og_subgroups module to work right, and there's a hierarchical element to the rules, too.

If I just want to implement my own permissions logic, I'd use hook_node_grants, right? Is there an equivalent for entities or other objects?

1
  • Nodes have a solid access restriction system built in but for other core, contrib or custom entities, the access systems can vary.
    – AKS
    Commented May 28, 2014 at 8:30

2 Answers 2

0

You can use following code snippet that allow users(particular role/roles) to access nodes based on content type.

  function HOOK_node_access($node, $op, $account){
    if (is_string($node))
        return NODE_ACCESS_IGNORE;

    if ($node->type == 'my_type' && $op == 'view'){
        $allowed_roles = array(
            'authenticated user'
        );
        $access_allow = array_intersect($allowed_roles, array_values($account->roles));
        if ($access_allow)
            return NODE_ACCESS_ALLOW;
        else
            return NODE_ACCESS_DENY;
    }
    return NODE_ACCESS_IGNORE;
}
0

Ok this is a somewhat shameful self promotion. I too had a similar requirement but I was not willing to implement any expensive hooks just to hide some nodes.

Try this sandbox module: https://drupal.org/sandbox/ayesh/2274655

It allows you to select one or more node types and one or more roles to allow access to them. It doesn't support any fancy UIs or per-operation permissions but this would be a good starting point I think.

Works in individual node pages, search pages (non-admins won't see results from private node types), term pages, views, etc.

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.