I have created a node and added some user-specific permissions. The result of this is that I see the user's permissions in a row with the "Keep" checkbox selected, and, in the DB, two rows for this node, one in realm 'nodeaccess_rid' and one in realm 'nodeaccess_uid'. So far so good!

Now I uncheck the "Keep" checkbox and hit "Save grants". Nothing happens to both the DB table nodeaccess and the visual result on screen: the row for the user reappears and the checkbox "Keep" is still checked. (I expected the user-specific row to be deleted.)

In the code I see that in function nodeaccess_grants_form_submit(), the first foreach loop iterates over the types 'uid' and 'rid'. Inside this loop, it is checked where $form_values contains a 'uid' or 'rid' field, respectively. If so, the grants are updated by a call to Drupal's node_access_write_grants(). But when the checkbox is unchecked, the if-clause fails and node_access_write_grants() is not called for realms 'nodeaccess_uid' — with the result that the row for this user remains in the DB.

Now, I do not see through the whole code but it seems to me that node_access_write_grants() should be called always, for both realms. The attached patch achieves this. Here it is, for the sake of convenience:

Index: nodeaccess.module
===================================================================
--- nodeaccess.module   (revision 29)
+++ nodeaccess.module   (working copy)
@@ -178,11 +178,11 @@
   $nid = $form_values['nid'];
   $save = array();
   foreach (array('uid', 'rid') as $type) {
+    $realm = 'nodeaccess_' . $type;
+    $node->nid = $nid; 
     if (is_array($form_values[$type])) {
       $grants = array();
-      $realm = 'nodeaccess_' . $type;
       foreach ($form_values[$type] as $gid => $line) {
-        $realm = 'nodeaccess_'. $type;
         // check the settings, no need for an entry if no perms are granted
         if ($line['grant_view'] || $line['grant_update'] || $line['grant_delete']) {
           $grant = array('gid' => $gid, 'realm' => $realm, 'grant_view' => $line['grant_view'], 
@@ -191,9 +191,8 @@
           $save[] = $grant;
         }
       }
-      $node->nid = $nid; 
-      node_access_write_grants($node, $grants, $realm);
     }
+    node_access_write_grants($node, $grants, $realm);
   }
   // save it to our own table, thanks to the new api....
   _nodeaccess_save_new($nid, $save);

Could somebody test this, please?

Kaspar

CommentFileSizeAuthor
patch_106.txt1.1 KBhbfkf

Comments

hbfkf’s picture

Any echo on this? Or was my Drupal install broken when I installed the module and it didn't work?!

Nikkol’s picture

My problem is the opposite. I cannot add user specific access.

hbfkf’s picture

My problem is the opposite. I cannot add user specific access.

What happens? Is it that even if you check the "Keep?" checkbox, the user specific setting does not stay?

Anonymous’s picture

Status: Active » Fixed

Ok fixed in the soon to be available update

hbfkf’s picture

Thanks a lot, debtman7! But have you checked that the patch makes sense? I must admit that I could not reproduce the problem on a different Drupal installation with the unpatched nodeaccess module (although Nikkol had similar problems). Does the patch make sense? A nodeaccess expert is needed here ;-)

Nikkol’s picture

My problem was actually a PICNIC (problem in chair, not in computer) ... since the box for searching for a user was using ajax, I figured it was actually pulling up that user. I didn't realize I had to click the search button to get it to stick. Sorry!

Anonymous’s picture

Status: Fixed » Closed (fixed)