Index: modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.285 diff -u -F^f -r1.285 blog.module --- modules/blog/blog.module 12 Aug 2007 15:55:35 -0000 1.285 +++ modules/blog/blog.module 11 Oct 2007 04:13:12 -0000 @@ -29,15 +29,13 @@ function blog_perm() { /** * Implementation of hook_access(). */ -function blog_access($op, $node) { - global $user; - +function blog_access($op, $node, $account) { if ($op == 'create') { - return user_access('edit own blog') && $user->uid; + return user_access('edit own blog', $account) && $account->uid; } if ($op == 'update' || $op == 'delete') { - if (user_access('edit own blog') && ($user->uid == $node->uid)) { + if (user_access('edit own blog', $account) && ($node->uid == $account->uid)) { return TRUE; } } Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.421 diff -u -F^f -r1.421 forum.module --- modules/forum/forum.module 8 Oct 2007 08:40:26 -0000 1.421 +++ modules/forum/forum.module 11 Oct 2007 04:13:13 -0000 @@ -295,15 +295,13 @@ function forum_node_info() { /** * Implementation of hook_access(). */ -function forum_access($op, $node) { - global $user; - +function forum_access($op, $node, $account) { if ($op == 'create') { - return user_access('create forum topics'); + return user_access('create forum topics', $account); } if ($op == 'update' || $op == 'delete') { - if (user_access('edit own forum topics') && ($user->uid == $node->uid)) { + if (user_access('edit own forum topics', $account) && ($account->uid == $node->uid)) { return TRUE; } } Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.891 diff -u -F^f -r1.891 node.module --- modules/node/node.module 8 Oct 2007 13:04:32 -0000 1.891 +++ modules/node/node.module 11 Oct 2007 04:13:14 -0000 @@ -1770,10 +1770,13 @@ function node_search_validate($form, &$f * @param $node * The node object (or node array) on which the operation is to be performed, * or node type (e.g. 'forum') for "create" operation. + * @param $account + * Optional, a user object representing the user for whom the operation is to + * be performed. Determines access for a user other than the current user. * @return * TRUE if the operation may be performed. */ -function node_access($op, $node) { +function node_access($op, $node, $account = NULL) { global $user; if (!$node) { @@ -1783,16 +1786,20 @@ function node_access($op, $node) { if ($op != 'create') { $node = (object)$node; } + // If no user object is supplied, the access check is for the current user. + if (empty($account)) { + $account = $GLOBALS['user']; + } // If the node is in a restricted format, disallow editing. if ($op == 'update' && !filter_access($node->format)) { return FALSE; } - if (user_access('administer nodes')) { + if (user_access('administer nodes', $account)) { return TRUE; } - if (!user_access('access content')) { + if (!user_access('access content', $account)) { return FALSE; } @@ -1802,7 +1809,7 @@ function node_access($op, $node) { if ($module == 'node') { $module = 'node_content'; // Avoid function name collisions. } - $access = module_invoke($module, 'access', $op, $node); + $access = module_invoke($module, 'access', $op, $node, $account); if (!is_null($access)) { return $access; } @@ -1811,7 +1818,7 @@ function node_access($op, $node) { // node_access table. if ($op != 'create' && $node->nid && $node->status) { $grants = array(); - foreach (node_access_grants($op) as $realm => $gids) { + foreach (node_access_grants($op, $account) as $realm => $gids) { foreach ($gids as $gid) { $grants[] = "(gid = $gid AND realm = '$realm')"; } @@ -1863,16 +1870,19 @@ function _node_access_join_sql($node_ali * @param $node_access_alias * If the node_access table has been given an SQL alias other than the default * "na", that must be passed here. + * @param $account + * The user object for the user performing the operation. If omitted, the + * current user is used. * @return * An SQL where clause. */ -function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid = NULL) { +function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $account = NULL) { if (user_access('administer nodes')) { return; } $grants = array(); - foreach (node_access_grants($op, $uid) as $realm => $gids) { + foreach (node_access_grants($op, $account) as $realm => $gids) { foreach ($gids as $gid) { $grants[] = "($node_access_alias.gid = $gid AND $node_access_alias.realm = '$realm')"; } @@ -1896,23 +1906,20 @@ function _node_access_where_sql($op = 'v * * @param $op * The operation that the user is trying to perform. - * @param $uid - * The user ID performing the operation. If omitted, the current user is used. + * @param $account + * The user object for the user performing the operation. If omitted, the + * current user is used. * @return * An associative array in which the keys are realms, and the values are * arrays of grants for those realms. */ -function node_access_grants($op, $uid = NULL) { - global $user; +function node_access_grants($op, $account = NULL) { - if (isset($uid)) { - $user_object = user_load(array('uid' => $uid)); - } - else { - $user_object = $user; + if (!isset($account)) { + $account = $GLOBALS['user']; } - return array_merge(array('all' => array(0)), module_invoke_all('node_grants', $user_object, $op)); + return array_merge(array('all' => array(0)), module_invoke_all('node_grants', $account, $op)); } /** @@ -2183,17 +2190,19 @@ function _node_access_rebuild_batch_fini /** * Implementation of hook_access(). + * + * Named so as not to conflict with node_access() */ -function node_content_access($op, $node) { +function node_content_access($op, $node, $account) { global $user; $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); if ($op == 'create') { - return user_access('create '. $type .' content'); + return user_access('create '. $type .' content', $account); } if ($op == 'update') { - if (user_access('edit '. $type .' content') || (user_access('edit own '. $type .' content') && ($user->uid == $node->uid))) { + if (user_access('edit '. $type .' content', $account) || (user_access('edit own '. $type .' content', $account) && ($user->uid == $node->uid))) { return TRUE; } } Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.242 diff -u -F^f -r1.242 poll.module --- modules/poll/poll.module 6 Sep 2007 12:18:01 -0000 1.242 +++ modules/poll/poll.module 11 Oct 2007 04:13:15 -0000 @@ -57,9 +57,9 @@ function poll_perm() { /** * Implementation of hook_access(). */ -function poll_access($op, $node) { +function poll_access($op, $node, $account) { if ($op == 'create') { - return user_access('create polls'); + return user_access('create polls', $account); } }