diff --git a/modules/node/node.module b/modules/node/node.module index 8f247cd..e352662 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -3185,17 +3185,29 @@ function node_permissions_get_configured_types() { * arrays of grants for those realms. */ function node_access_grants($op, $account = NULL) { + $grants = &drupal_static(__FUNCTION__); + + if (!isset($grants)) { + $grants = array(); + } if (!isset($account)) { $account = $GLOBALS['user']; } - // Fetch node access grants from other modules. - $grants = module_invoke_all('node_grants', $account, $op); - // Allow modules to alter the assigned grants. - drupal_alter('node_grants', $grants, $account, $op); + // Grants are unique only per account and per operation on any single request. + $cid = $account->uid . ':' . $op; + + if (!isset($grants[$cid])) { + // Fetch node access grants from other modules. + $grants[$cid] = module_invoke_all('node_grants', $account, $op); + // Allow modules to alter the assigned grants. + drupal_alter('node_grants', $grants[$cid], $account, $op); + + $grants[$cid] = array_merge(array('all' => array(0)), $grants[$cid]); + } - return array_merge(array('all' => array(0)), $grants); + return $grants[$cid]; } /** diff --git a/modules/node/node.test b/modules/node/node.test index bfe3717..0479249 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -2259,6 +2259,7 @@ class NodeQueryAlter extends DrupalWebTestCase { // Test that the noAccessUser still doesn't have the 'view' // privilege after adding the node_access record. drupal_static_reset('node_access_view_all_nodes'); + drupal_static_reset('node_access_grants'); try { $query = db_select('node', 'mytab') ->fields('mytab'); @@ -2281,6 +2282,7 @@ class NodeQueryAlter extends DrupalWebTestCase { $this->drupalLogin($this->noAccessUser2); variable_set('node_test_node_access_all_uid', $this->noAccessUser->uid); drupal_static_reset('node_access_view_all_nodes'); + drupal_static_reset('node_access_grants'); try { $query = db_select('node', 'mytab') ->fields('mytab');