? 306541.patch
Index: nodeaccess.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeaccess/Attic/nodeaccess.install,v
retrieving revision 1.1.2.5.2.2
diff -u -p -r1.1.2.5.2.2 nodeaccess.install
--- nodeaccess.install	8 Mar 2009 00:00:45 -0000	1.1.2.5.2.2
+++ nodeaccess.install	1 Nov 2010 21:56:10 -0000
@@ -16,11 +16,15 @@ function nodeaccess_install() {
   $grants[] = array('gid' => 2, 'realm' => 'nodeaccess_rid',
                     'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
   $author_prefs = array();
+  $anon_author_prefs = array();
   foreach (node_get_types() as $type => $name) {
     variable_set('nodeaccess_' . $type, $grants);
     $author_prefs[$type] = array('grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1);
+    $anon_author_prefs[$type] = array('grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
   }
   variable_set('nodeaccess_authors', $author_prefs);
+  variable_set('nodeaccess_anon_authors', $anon_author_prefs);
+
   // Set up all permissions to be editable by default.
   $grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1);
   variable_set('nodeaccess-grants', $grant_prefs);
@@ -132,6 +136,17 @@ function nodeaccess_update_3() {
   return $ret;
 }
 
+function nodeaccess_update_4() {
+  $anon_author_prefs = array();
+  foreach (node_get_types() as $type => $name) {
+    $anon_author_prefs[$type] = array('grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
+  }
+  variable_set('nodeaccess_anon_authors', $anon_author_prefs);
+  
+  node_access_needs_rebuild(TRUE);
+  return array();
+}
+
 /**
  * Implementation of hook_uninstall().
  */
@@ -143,6 +158,7 @@ function nodeaccess_uninstall() {
   variable_del('nodeaccess-roles');
   variable_del('nodeaccess-types');
   variable_del('nodeaccess_authors');
+  variable_del('nodeaccess_anon_authors');
   foreach (node_get_types() as $type => $name) {
     variable_del('nodeaccess_' . $type);
     variable_del('nodeaccess_' . $type . '_userreference');
Index: nodeaccess.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeaccess/nodeaccess.module,v
retrieving revision 1.4.2.7.2.9.2.2
diff -u -p -r1.4.2.7.2.9.2.2 nodeaccess.module
--- nodeaccess.module	8 Mar 2009 00:00:45 -0000	1.4.2.7.2.9.2.2
+++ nodeaccess.module	1 Nov 2010 21:56:10 -0000
@@ -158,6 +158,11 @@ function nodeaccess_admin_form(&$form_st
     $form['nodeaccess'][$type]['author']['grant_update'] = array('#type' => 'checkbox', '#default_value' => $author_prefs[$type]['grant_update']);
     $form['nodeaccess'][$type]['author']['grant_delete'] = array('#type' => 'checkbox', '#default_value' => $author_prefs[$type]['grant_delete']);
 
+    $anon_author_prefs = variable_get('nodeaccess_anon_authors', array());
+    $form['nodeaccess'][$type]['anon_author']['grant_view'] = array('#type' => 'checkbox', '#default_value' => $anon_author_prefs[$type]['grant_view']);
+    $form['nodeaccess'][$type]['anon_author']['grant_update'] = array('#type' => 'checkbox', '#default_value' => $anon_author_prefs[$type]['grant_update']);
+    $form['nodeaccess'][$type]['anon_author']['grant_delete'] = array('#type' => 'checkbox', '#default_value' => $anon_author_prefs[$type]['grant_delete']);
+
     $perms = variable_get('nodeaccess_' . $type, array());
     foreach ($perms as $perm) {
       $opts[$perm['gid']] = $perm;
@@ -224,6 +229,7 @@ function nodeaccess_admin_form_submit($f
   nodeaccess_save_role_aliases($alias_prefs);
   // Save author and role permissions for each node type.
   $author_prefs = array();
+  $anon_author_prefs = array();
   foreach (node_get_types() as $type => $name) {
     $grants = array();
     foreach ($form_values[$type]['roles'] as $role => $val) {
@@ -237,6 +243,7 @@ function nodeaccess_admin_form_submit($f
       $allowed_types[$type] = 0;
     }
     $author_prefs[$type] = $form_values[$type]['author'];
+    $anon_author_prefs[$type] = $form_values[$type]['anon_author'];
     // Also save userreference default permissions if enabled.
     if (module_exists('userreference') && isset($form_values[$type]['userreference'])) {
       $userreference_grants = array();
@@ -247,6 +254,7 @@ function nodeaccess_admin_form_submit($f
     }
   }
   variable_set('nodeaccess_authors', $author_prefs);
+  variable_set('nodeaccess_anon_authors', $anon_author_prefs);
   // Save allowed node types.
   variable_set('nodeaccess-types', $allowed_types);
   node_access_needs_rebuild(TRUE);
@@ -286,13 +294,22 @@ function theme_nodeaccess_admin_form_typ
 
   $header = array(t('Author Settings'), t('View'), t('Edit'), t('Delete'));
   $row = array();
+  $rows = array();
   $row[] = t('Node author');
   $row[] = drupal_render($form['author']['grant_view']);
   $row[] = drupal_render($form['author']['grant_update']);
   $row[] = drupal_render($form['author']['grant_delete']);
+  $rows[] = $row;
+
+  $row = array();
+  $row[] = t('Anonymous node author');
+  $row[] = drupal_render($form['anon_author']['grant_view']);
+  $row[] = drupal_render($form['anon_author']['grant_update']);
+  $row[] = drupal_render($form['anon_author']['grant_delete']);
+  $rows[] = $row;
 
-  $output .= theme('table', $header, array($row));
-  $output .= '<small>' . t('The settings selected for the node author will define what permissions the node author has. This cannot be changed on individual node grants.') . '</small>';
+  $output .= theme('table', $header, $rows);
+  $output .= '<small>' . t('The settings selected for the node author will define what permissions the node author has. This cannot be changed on individual node grants. The anonymous node author refers to nodes that have the user id set to 0. This can be used to prevent anonymous users from having unexpected permissions.') . '</small>';
 
   if (module_exists('userreference') && isset($form['userreference'])) {
     $userreference_fields = element_children($form['userreference']);
@@ -606,7 +623,6 @@ function theme_nodeaccess_grants_form($f
 function nodeaccess_node_grants($account, $op) {
 	$roles = is_array($account->roles) ? array_keys($account->roles) : array(-1);
 	return array('nodeaccess_rid' => $roles, 'nodeaccess_uid' => array($account->uid), 'nodeaccess_author' => array($account->uid));
-
 }
 
 /**
@@ -633,6 +649,10 @@ function nodeaccess_nodeapi(&$node, $op)
       // Done, default permissions are not written into nodeaccess.
     break;
     case 'update':
+      /* Not neccessary? Grants will be written at the end of a node save with
+       * the node_access_acquire_grants function, which will run the nodeaccess
+       * hook_node_access_records.
+       */
       // Node author may have changed, overwrite old record.
       $author_prefs = variable_get('nodeaccess_authors', array());
       // Array is prepopulated with grant values.
@@ -641,6 +661,7 @@ function nodeaccess_nodeapi(&$node, $op)
       $grant['realm'] = 'nodeaccess_author';
       $grants = array();
       $grants[] = $grant;
+
       node_access_write_grants($node, $grants, 'nodeaccess_author');
       if (module_exists('userreference')) {
         $fields = variable_get('nodeaccess_' . $node->type . '_userreference', array());
@@ -704,9 +725,13 @@ function nodeaccess_node_access_records(
     }
   }
   // Apply author grants.
-  $author_prefs = variable_get('nodeaccess_authors', array());
-  // Array is prepopulated with grant values.
-  $grant = $author_prefs[$node->type];
+  if ($node->uid == 0) {
+    $anon_author_prefs = variable_get('nodeaccess_anon_authors', array());
+    $grant = $anon_author_prefs[$node->type];
+  } else {
+    $author_prefs = variable_get('nodeaccess_authors', array());
+    $grant = $author_prefs[$node->type];
+  }
   $grant['gid'] = $node->uid;
   $grant['realm'] = 'nodeaccess_author';
   $grant['priority'] = $priority;
@@ -747,7 +772,11 @@ function nodeaccess_node_type($op, $info
       variable_del('nodeaccess_' . $info->type);
       $author_prefs = variable_get('nodeaccess_authors', array());
       unset($author_prefs[$info->type]);
+
       variable_set('nodeaccess_authors', $author_prefs);
+      $anon_author_prefs = variable_get('nodeaccess_anon_authors', array());
+      unset($anon_author_prefs[$info->type]);
+      variable_set('nodeaccess_anon_authors', $author_prefs);
     break;
     case 'update':
       // Node type has changed, move preferences to new type.
@@ -755,6 +784,7 @@ function nodeaccess_node_type($op, $info
         $setting = variable_get('nodeaccess_'. $info->old_type, array());
         variable_del('nodeaccess_'. $info->old_type);
         variable_set('nodeaccess_'. $info->type, $setting);
+
         $author_prefs = variable_get('nodeaccess_authors', array());
         $author_prefs[$info->type] = array(
           'grant_view' => $author_prefs[$info->old_type]['grant_view'],
@@ -763,6 +793,15 @@ function nodeaccess_node_type($op, $info
         );
         unset($author_prefs[$info->old_type]);
         variable_set('nodeaccess_authors', $author_prefs);
+
+        $anon_author_prefs = variable_get('nodeaccess_anon_authors', array());
+        $anon_author_prefs[$info->type] = array(
+          'grant_view' => $anon_author_prefs[$info->old_type]['grant_view'],
+          'grant_update' => $anon_author_prefs[$info->old_type]['grant_update'],
+          'grant_delete' => $anon_author_prefs[$info->old_type]['grant_delete']
+        );
+        unset($author_prefs[$info->old_type]);
+        variable_set('nodeaccess_anon_authors', $anon_author_prefs);
       }
     break;
     case 'insert':
@@ -771,9 +810,15 @@ function nodeaccess_node_type($op, $info
       $grants[] = array('gid' => 1, 'realm' => 'nodeaccess_rid', 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
       $grants[] = array('gid' => 2, 'realm' => 'nodeaccess_rid', 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
       variable_set('nodeaccess_' . $info->type, $grants);
+
       $author_prefs = variable_get('nodeaccess_authors', array());
       $author_prefs[$info->type] = array('grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1);
       variable_set('nodeaccess_authors', $author_prefs);
+
+      $anon_author_prefs = variable_get('nodeaccess_anon_authors', array());
+      $anon_author_prefs[$info->type] = array('grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
+      variable_set('nodeaccess_anon_authors', $anon_author_prefs);
+      
       node_access_needs_rebuild(TRUE);
     break;
   }
