I have a node (A), with a node reference to node (B) and I have the nodereference field set to display the full node (B) when displaying node A. This works great when both nodes are published. The problem I am running into is when node B is unpublished. A user (editor) has access to view and edit this node as defined in Drupal's node_access table and can do so when viewing node B. However, when viewing node A, node B is not displayed as I would otherwise expect it to. We get the nid back but not the rendered node as we have previously specified. I believe this is an issue with how nodereference populates the field by checking for the 'administer_nodes' permission instead of paying any mind as to whether the user has rights to view node B as seen here:
from nodereference.module:
259: if (!user_access('administer nodes')) {
260: $where[] = 'n.status = 1';
261: }
262: $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids);
263: while ($row = db_fetch_array($result)) {
264: $sanitized_nodes[$row['nid']] = $row;
265: }
Does anyone have any insight as to why this is done this way? Is there a work-around? If editor has the ability to view node B, I believe they should have the ability to be able to see it when it is referenced from node A.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | cck-946554-7.patch | 1.21 KB | q0rban |
| #4 | cck-946554-4.patch | 1.21 KB | q0rban |
Comments
Comment #1
apotek commentedBeen wondering about this too, and I think the analysis is correct. The expected behavior should be as described at the bottom of the issue. The 'administer nodes' perm is not flexible (or modular, for that matter, if a node were to wish to override the default response). Ideally, the logic would be left in place, but extensible with an alternate permission check that a module that needed more flexible authorization schemes could extend.
Comment #2
q0rban commentedJust to be clear, this is not an issue with a typical setup, this only occurs when you have a system that allows a user without 'administer nodes' permission to be able to view an unpublished node. As such, I'm retitling and changing to a feature request.
Benchmarking would need to be done to see the performance implications of switching to node_access instead of the simple method currently in place.
Comment #3
karens commentedSome of this code was added as a response to a security issue to ensure that no one could see nodes they don't have access to if they find a way to get to the url used to return autocomplete results. So any attempt to alter this would have to be carefully scrutinized to be sure no new security hole is introduced. That being said, the current setup is certainly hard-wired to the normal Drupal behavior of hiding unpublished nodes from pretty much everyone and might be made more flexible.
Comment #4
q0rban commentedAttached patch fixes it for us, but needs testing with regards to performance.
Comment #5
q0rban commentedActually, a fundamental flaw I just noticed with that patch is that the node's uid is not being passed to node_access. I'll re-roll it tomorrow.
Comment #6
q0rban commentedHere's some benchmarking. It seems that there isn't much performance hit due to this change on a clean Drupal site (actually Pressflow 6.19.94) with just CCK 3.x, Devel, and Admin modules enabled:
STOCK = stock CCK 3.x
PATCH = with the patch on this comment
Test 1
≈ 1000 nodereferences on a single node, with the noderef display settings set to link
Average Page Execution time:
STOCK: ≈ 625ms
PATCH: ≈ 650ms
Longest Page Execution time:
STOCK: 886ms
PATCH: 744ms
Page Execution time after a drush cc all:
STOCK: 846ms
PATCH: 865ms
Test 2
≈ 20 nodereferences on a single node, with display settings to full node
Average Page Execution time:
STOCK: ≈ 300ms
PATCH: ≈ 300ms
Longest Page Execution time:
STOCK: 325ms
PATCH: 340ms
Page Execution time after a drush cc all
STOCK: 593ms
PATCH: 450ms
Comment #7
q0rban commentedWhoops, forgot to set --no-prefix and --relative on that last patch. Here's a re-roll.
Comment #8
markdorisonTested the patch from #7 and seems to be working as expected.
Comment #9
iratau commentedIt is worth noting that this patch affects installations that have any modules that implement their own access functions, such as workflow_access or module_grants. There is a comment about this under the module_grants issue queue here:
http://drupal.org/node/948306
Comment #10
q0rban commentedThis may need to be re-tested as far as performance, benchmarking with an anonymous as well as authenticated (non-admin) user to see the performance differences between the two.