Right now, this function has both database logic and business logic wrapped into it. As a result, you cannot call this as an external function in the event that you _want_ to impose access rules on site administrators.
See #1359570: Restrict node views for admins fails on taxonomy pages.
Why would you want to do so? To help users configure their access control rules properly while still acting as a "super-user".
The problem is, this portion of the code prevents this usage:
// If $account can bypass node access, or there are no node access modules,
// or the operation is 'view' and the $acount has a global view grant (i.e.,
// a view grant for node ID 0), we don't need to alter the query.
if (user_access('bypass node access', $account)) {
return;
}
if (!count(module_implements('node_grants'))) {
return;
}
if ($op == 'view' && node_access_view_all_nodes($account)) {
return;
}
This check should be performed by the calling operation, not this function, so that we can eliminate code duplication caused by improper abstraction.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 1363062-node_access_check_abstraction.patch | 2.99 KB | agentrickard |
| #1 | 1363062-node_access_check_abstraction.patch | 2.88 KB | agentrickard |
Comments
Comment #1
agentrickardAnd a patch. Not very glamorous, but all tests pass. The cleanup does a few things:
This does cause an API change, as the result adds two new parameters to the current function, which I think is fine, since the cleanup improves readability and isolates functionality.
Comment #2
agentrickardMinor re-roll in light of new doxygen standards at http://drupal.org/node/1354.
Comment #4
agentrickard#2: 1363062-node_access_check_abstraction.patch queued for re-testing.
Comment #5
agentrickardPerhaps we need a minor change to remove the "private" function underscore as well.
Comment #6
albert volkman commentedThis function got moved to here -
http://api.drupal.org/api/drupal/core%21modules%21node%21node.module/fun...