diff -Naur view_unpublished/README.txt view_unpublished_6/README.txt --- view_unpublished/README.txt 2008-08-11 16:47:25.000000000 +0100 +++ view_unpublished_6/README.txt 2008-09-19 19:17:00.000000000 +0100 @@ -4,13 +4,12 @@ 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 -Naur view_unpublished/view_unpublished.info view_unpublished_6/view_unpublished.info --- view_unpublished/view_unpublished.info 2008-08-12 01:11:21.000000000 +0100 +++ view_unpublished_6/view_unpublished.info 2008-09-20 17:58:58.000000000 +0100 @@ -1,10 +1,5 @@ -; $Id: view_unpublished.info,v 1.1 2008/08/11 15:47:25 dsantangelo Exp $ +; $Id$ name = View Unpublished Content -description = "Select which roles should be able to see unpublished content" +description = "Select which roles should be able to see unpublished nodes by content type, or all unpubished nodes." package = "Permissions" - -; Information added by drupal.org packaging script on 2008-08-12 -version = "5.x-1.x-dev" -project = "view_unpublished" -datestamp = "1218499881" - +core = 6.x \ No newline at end of file diff -Naur view_unpublished/view_unpublished.install view_unpublished_6/view_unpublished.install --- view_unpublished/view_unpublished.install 2008-08-11 16:47:25.000000000 +0100 +++ view_unpublished_6/view_unpublished.install 1970-01-01 01:00:00.000000000 +0100 @@ -1,5 +0,0 @@ - $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); +}