I needed Node Hierarchy Access on a 6.x site, so I took some time to update the module for 6.x-2.x-dev. The functionality is based off of the original 5.x structure, so the organization may be a little wonky. I've also added two new options on the Grant form: copy permissions from a parent, and copy all permissions to children. I've been using this (with Node Access 6.x-1.3) on two production sites and haven't had any problems. You should be able to drop this into the nodehierarchy module directory as a replacement for the current (nonworking) nodehierarchyaccess folder.

A quick warning: I'm not sure how this will work with the new "multiple parent" code. I wrote everything assuming that nodes would only have one parent, so some further tweaking may be required to work with the new functionality.

CommentFileSizeAuthor
nodehierarchyaccess.zip2.96 KBjbylsma

Comments

hansroberto’s picture

nodehierarchy_get_node_ancestor_nids()

and

_nodehierarchy_get_descendant_list()

breaks the module. Why?

The first triggers when saving parent and child grants. The second when creating a new node.

/Hans

markhalliwell’s picture

FINALLY! :D jbylsma you're my savior! I haven't had the time to go over this module myself, but now you have I will let you know how it works and help if I can. I'm in the middle of rolling out some secondary sites this next couple of weeks, so it might take me a bit to get going. I suppose this is my way of saying: "subscribing" hehe

markhalliwell’s picture

_nodehierarchy_get_descendant_list($nid); on line 178 needs to be changed to:

_nodehierarchy_get_children_menu_links($nid);

markhalliwell’s picture

Added recursive algorithm for children deeper than 1 level (line 174):

/**
 *  Set the given grants for the children nodes
 */
function _nodehierarchyaccess_set_descendant_grants($nid, $grants = NULL) {
  if ($grants == NULL) {
    $grants = _nodehierarchyaccess_get_node_grants($nid);
  }
  $descendants = _nodehierarchy_get_children_menu_links($nid);
  
  // copy grants to the descendants of the node
  foreach ($descendants as $descendant) {    
    $node = new stdClass();
    $node->nid = $descendant['nid'];
    _nodehierarchyaccess_update_node_access($node, $grants, TRUE);
    if ($descendant['has_children']) {
      _nodehierarchyaccess_set_descendant_grants($node->nid, $grants);
    }
  }
}
markhalliwell’s picture

Status: Needs review » Fixed

Committed this code to 6.x-2.x-dev. Finally a fix for nodehierarchyaccess in D6!

jbylsma’s picture

Fantastic! I really appreciate the effort you are putting into NH, thanks!

markhalliwell’s picture

No problem :) Thank you for doing must of the grunt work! Please let me know if there are any other issues you encounter!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gintass’s picture

"I've also added two new options on the Grant form: copy permissions from a parent, and copy all permissions to children."

Hmm, interesting, I tried installing and tested nodehierarchy 6.x-2.0 and nodehierarchy 6.x-2.x-dev and neither gives these options you are talking about. I also see this statement in "Noteworthy features" of nodehierarchy 6.x-2.x-dev:
"Node Hierarchy and Node Access integration (Now fully implemented for D6!) "

I still don't see these options mentioned above, nor it happens automatically, i.e. parent permissions aren't being inherited when I create new child node.

jbylsma’s picture

The added functionality is only present on the "Grants" tab for whatever node you are using. You'll need to turn on the Grant tab for whatever content type you are working on, which should be under User management, Nodeaccess. After you've done that, the Grant tab should have a new fieldset titled "Node Hierarchy/Node Access integration," where you have the two options mentioned.

If my code comments are correct (and I'm pretty sure they are), any new node will automatically inherit its parent's permission. Any update to a node will only inherit its parent's permission if a new parent has been assigned (ie: a moved node).

Semi-unrelated: the nodeapi hooks shouldn't run if the content type isn't using Node Hierarchy. I should probably check that out.

gintass’s picture

Thank you very much for your prompt reply.
I did have grant tabs enabled, but as I suspected I missed something simple and obvious - I didn't notice that there is a separate sub-module in this new version of Node Hierarchy called "Node Hierarchy Access". Once I enabled it everything is perfect. Thank you very much for an excellent module.

r0bm1lls’s picture

Component: Code » Drupal/PHP Code

Hi, this is just what I am looking for in D7. Can't seem to find anything in the D7 port and the standard node access module does not integrate. I want to be able to have children automatically inherit the access per mission of their parent. Is this still in the pipeline for the D7 port?