The following is the piece of code from module_grants_node_access() that allows view access to unpublished nodes. The problem is that if node's author is set to uid 0, all anonymous users will be allowed to see the node when unpublished.
if ($node_op == 'view' && !$node->status) {
$may_view = module_invoke('revisioning', 'user_node_access', 'view revisions', $node)
|| user_access('view revisions');
if (!$may_view) {
if ($account->uid != $node->uid) {
// Not the author: no permission to view this unpublished content.
return $access["$uid:$nid:$node_op"] = FALSE;
}
}
}
Easy fix, just return FALSE too if uid = 0:
if (!$may_view) {
if (!$account->uid || $account->uid != $node->uid) {
// Not the author: no permission to view this unpublished content.
return $access["$uid:$nid:$node_op"] = FALSE;
}
How to reproduce:
- Create a node where access is granted through Module Grants (eg. Revisioning-enabled)
- Publish the node: anonymous user can see it
- Unpublish the node: access denied for anonymous users
- Edit the node and remove the author to set it to Anonymous
- Save the changes (and make sure the node is still unpublished)
- Check with anonymous user: access granted while the node is unpublished
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | module_grants-fix_unpublished_access-1372006-1-D6.patch | 789 bytes | mdupont |
Comments
Comment #1
mdupontPatch attached.
Comment #2
rdeboer@mdupont:
While it is a bit of a contrived situation (an administrator changing ownership of an unpublished piece of content to "Anonymous"), I do believe you hit the nail on the head with your solution.
Will apply the patch soon.
Thanks!
Rik
Comment #3
rdeboerChecked in with creditation.
See your personal profile page and http://drupal.org/node/407922/committers
Comment #4
rdeboerChange title to something less dramatic.
Comment #5
mdupontWow, that was fast! Thanks :-)
Comment #6.0
(not verified) commentedAdded how to reproduce procedure