diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-01-04 19:56:51 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-01-04 19:56:51 +0000 |
commit | 634379299f7ab35bf64504718a77d00767fa2dfa (patch) | |
tree | 4ed784c5e43ea9de8818dd7ac38f0648a76b2b4d /modules/node/node.module | |
parent | 7e60d94f69d896e1f063cc52a4ba1778f91a77fc (diff) | |
download | brdo-634379299f7ab35bf64504718a77d00767fa2dfa.tar.gz brdo-634379299f7ab35bf64504718a77d00767fa2dfa.tar.bz2 |
- Patch #320591 by Moshe, Crell et al: tag specific alter hook for database queries.
Diffstat (limited to 'modules/node/node.module')
-rw-r--r-- | modules/node/node.module | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index f2e616f6a..deca20ea3 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -2324,17 +2324,23 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) { } /** - * Implementation of hook_query_alter(). + * Implementation of hook_query_TAG_alter(). */ -function node_query_alter(QueryAlterableInterface $query) { - if ($query->hasTag('node_access') && !node_access_view_all_nodes()) { +function node_query_node_access_alter(QueryAlterableInterface $query) { + // Skip the extra expensive alterations if site has no node access control modules. + if (!node_access_view_all_nodes()) { + // Prevent duplicate records. $query->distinct(); + // The recognized operations are 'view', 'update', 'delete'. if (!$op = $query->getMetaData('op')) { $op = 'view'; } + // Skip the extra joins and conditions for node admins. if (!user_access('bypass node access')) { + // The node_access table has the access grants for any given node. $access_alias = $query->join('node_access', 'na', 'na.nid = n.nid'); $or = db_or(); + // If any grant exists for the specified user, then user has access to the node for the specified operation. foreach (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) { foreach ($gids as $gid) { $or->condition(db_and() |