0
votes

I have a permissions problem in Drupal. I want users to be able to create a certain node type, but there are two different paths I need to give them permissions for to let them do this. The type is content created by a module called isbn2node, and there are two ways to make content through it, each with different paths:

?=node/add/isbn2node-book

?=node/add/isbn2node_book/isbn2node

One has an underscore and the other one has a hyphen. The first path leads to a form that lets users enter information on a book manually; the second path lets them enter an ISBN, searches for it, and populates the form for them based on the results.

I've changed permissions in the People menu so they can add isbn2node-book content manually using the first path, but there isn't an option to let them use the second method. Aliasing the url so it didn't have node/add in the path didn't work either.

Creating a duplicate content type seems like an ugly solution to this; is there a more elegant way to let users access that second path?

2

2 Answers

1
votes

A little code in a custom module using hook_node_access should do it.

$node is either a node object or the machine name of the content type on which to perform the access check (if the node is being created then the $node object is not available so it will be a string instead).

So this should do it:

function MY_MODULE_node_access($node, $op, $account) {
    if ($op == 'create') {
        $type = $node;
        if($type == 'book' && $account->uid) return NODE_ACCESS_ALLOW;
    }
}
0
votes

I figured this out, and the issues I was having were specific to this content type. The ISBN2Node module requires users to have the Administer Nodes permission to use its lookup and bulk import features.

There is some extra code for the module's hook_permission and hook_menu sections submitted as a fix in the module's issues thread.