Drupal - "View unpublished content" permission for non-author
If you're ok writing a very small custom module you could use a combination of hook_permission()
and hook_node_access()
to do this:
function MYMODULE_permission() {
return array(
'unconditionally view unpublished content' => array(
'title' => t('Unconditionally View Unpublished Content'),
'restrict access' => TRUE
)
);
}
function MYMODULE_node_access($node, $op, $account) {
// We're only bothered about the 'view' operation at the moment
if ($op == 'view') {
// If the user has access to our new permission, let 'em at it
if (user_access('unconditionally view unpublished content', $account)) {
return NODE_ACCESS_ALLOW;
}
}
// For everything else let the system decide.
return NODE_ACCESS_IGNORE;
}
Any role you assign the new permission to should now be able to view any node, regardless of whether it's published or not.
I first tried the code above, which is great. But after giving rights onto unpublished content to a role, that role still couldn't see unpublished content in views, and this can be very useful for some editors roles...
I solved it using the module view_unpublished.
I use the Revisioning module for this. Upon installation, it creates the following permissions for each content type:
Content type: View revisions of own content
Content type: View revisions of anyone's content
Content type: Publish revisions of own content
Content type: Publish revisions of anyone's content
By giving my editors permission to view revisions of anyone's content, they are able to access and publish all nodes that have been created or revised by other users.