diff -urpN /Volumes/Talaria/Downloads/view_unpublished.d5/README.txt /Volumes/Talaria/Downloads/view_unpublished/README.txt --- /Volumes/Talaria/Downloads/view_unpublished.d5/README.txt 2008-08-11 11:47:25.000000000 -0400 +++ /Volumes/Talaria/Downloads/view_unpublished/README.txt 2009-08-29 19:06:49.000000000 -0400 @@ -4,13 +4,12 @@ This module allows you to grant access f Usage: ------ -view_unpublished looks for two user access permissions: -*Use view_unpublished module -*View unpublished (node type) +view_unpublished looks for the "view all unpublished content" permission and then the "view unpublished (node type) content" permission when a user tries to view a node that is unpublished. -After installing the module, navigate to your user access page and assign the appropriate permissions to the roles you wish to be able to view unpublished nodes. For each role that (now) has permissions to view unpublished nodes, assign the "use view_unpublished" permission to them as well. +After installing the module, navigate to your user access page and assign the appropriate permissions to the roles you wish to be able to view unpublished nodes. Code Contributions: ------------------- Brad Bowman/beeradb - Aten Design Group +Caleb Delnay/calebd Domenic Santangelo/dsantangelo - WorkHabit diff -urpN /Volumes/Talaria/Downloads/view_unpublished.d5/view_unpublished.module /Volumes/Talaria/Downloads/view_unpublished/view_unpublished.module --- /Volumes/Talaria/Downloads/view_unpublished.d5/view_unpublished.module 2008-08-11 11:47:25.000000000 -0400 +++ /Volumes/Talaria/Downloads/view_unpublished/view_unpublished.module 2009-08-29 19:07:22.000000000 -0400 @@ -1,45 +1,54 @@ $name) { $perms[] = 'view unpublished '. $type .' content'; } - + return $perms; } -/* -* Selectively overrides the node/nid path to set access => true when a user has permission -* to view unpublished content -*/ -function view_unpublished_menu($may_cache) { - $items = array(); - if (!$may_cache) { - if (is_numeric(arg(1)) && arg(0) == 'node' && user_access('use view_unpublished module') && !user_access('administer nodes')) { - $node = node_load(arg(1)); - if ($node->status == 0 && (user_access('view unpublished '. $node->type .' content') || user_access('view all unpublished content'))) { - //print_r($node); - //die(); - $items[] = array( - 'path' => 'node/'. arg(1), - 'title' => t('View'), - 'callback' => 'node_page_view', - 'callback arguments' => array($node), - 'type' => MENU_CALLBACK, - 'access' => true, - ); - } - } - } - - return $items; +/** + * Implementation of hook_menu_alter(). + * + * Modifies the path node/nid to use our access callback. + */ +function view_unpublished_menu_alter(&$items) { + $items['node/%node']['access callback'] = '_view_unpublished_node_access'; + $items['node/%node']['access arguments'] = array(1); } +/** + * Returns true if the user has 'view all unpublished content' or if + * they have the permission corresponding to the node's content type. + */ +function _view_unpublished_node_access($node) { + // Only check permissions on nodes that are unpublished. + if ($node->status == 0) { + if (user_access('view all unpublished content')) { + return TRUE; + } + + if (user_access('view unpublished '. $node->type .' content')) { + return TRUE; + } + } + + // If none of the above conditions were satisfied, then use node_access like normal. + return node_access('view', $node); +}