'. t('This module helps in site development. Specifically, when an access control module is used to limit access to some or all nodes, this module provides some feedback showing the node_access table in the database.') ."

\n"; $output .= '

'. t('The node_access table is one method Drupal provides to hide content from some users while displaying it to others. By default, Drupal shows all nodes to all users. There are a number of optional modules which may be installed to hide content from some users.') ."

\n"; $output .= '

'. t('If you have not installed any of these modules, you really have no need for the devel_node_access module. This module is intended for use during development, so that developers and admins can confirm that the node_access table is working as expected. You probably do not want this module enabled on a production site.') ."

\n"; $output .= '

'. t('This module provides two blocks. One called Devel Node Access by User is visible when a single node is shown on a page. This block shows which users can view, update or delete the node shown. Note that this block uses an inefficient algorithm to produce its output. You should only enable this block on sites with very few user accounts.') ."

\n"; $output .= '

'. t('The second block provided by this module shows the entries in the node_access table for any nodes shown on the current page. You can enable the debug mode on the !settings_page to display much more information, but this can cause considerable overhead. Because the tables shown are wide, it is recommended to enable the blocks in the page footer rather than a sidebar.', array('!settings_page' => l(t('settings page'), 'admin/settings/devel', array(), NULL, 'edit-devel-node-access-debug-mode')) ) ."

\n"; $output .= '

'. t('This module also provides a !summary_page which shows general information about your node_access table. If you have installed the Views module, you may browse node_access by realm.', array('!summary_page' => l(t('summary page'), 'devel/node_access/summary')) ) ."

\n"; $output .= '

'. t('') ."

\n"; return $output; } } function devel_node_access_menu() { $items = array(); // add this to the custom menu 'devel' created by devel module. $items['devel/node_access/summary'] = array( 'title' => 'Node_access summary', 'page callback' => 'dna_summary', 'access arguments' => array(DNA_ACCESS_VIEW), 'menu_name' => 'devel', ); return $items; } function dna_summary() { // Warn user if they have any entries that could grant access to all nodes $output = ''; $result = db_query('SELECT DISTINCT realm FROM {node_access} WHERE nid=0 AND gid=0'); $rows = array(); while ($row = db_fetch_object($result)) { $rows[] = array($row->realm); } if (!empty($rows)) { $output .= '

'. t('Access Granted to All Nodes (All Users)') ."

\n"; $output .= '

'. t('Your node_access table contains entries that may be granting all users access to all nodes. Depending on which access control module(s) you use, you may want to delete these entries. If you are not using an access control module, you should probably leave these entries as is.') ."

\n"; $headers = array(t('realm')); $output .= theme('table', $headers, $rows); } // how many nodes are not represented in the node_access table $result = db_fetch_object(db_query('SELECT COUNT(n.nid) as num_nodes FROM {node} n LEFT JOIN {node_access} na ON n.nid = na.nid WHERE na.nid IS NULL')); if ($num = $result->num_nodes) { $output .= '

'. t('Legacy Nodes') ."

\n"; $output .= '

'. t('You have !num nodes in your node table which are not represented in your node_access table. If you have an access control module installed, these nodes may be hidden from all users. This could be caused by publishing nodes before enabling the access control module. If this is the case, manually updating each node should add it to the node_access table and fix the problem.', array('!num' => l($num, 'devel/node_access/view/NULL'))) ."

\n"; } else { $output .= '

'. t('All Nodes Represented') ."

\n"; $output .= '

'. t('All nodes are represented in the node_access table.') ."

\n"; } // a similar warning to the one above, but slightly more specific $result = db_query('SELECT DISTINCT realm FROM {node_access} WHERE nid = 0 AND gid <> 0'); $rows = array(); while ($row = db_fetch_object($result)) { $rows[] = array($row->realm); } if (!empty($rows)) { $output .= '

'. t('Access Granted to All Nodes (Some Users)') ."

\n"; $output .= '

'. t('Your node_access table contains entries that may be granting some users access to all nodes. This may be perfectly normal, depending on which access control module(s) you use.') ."

\n"; $headers = array(t('realm')); $output .= theme('table', $headers, $rows); } // find specific nodes which may be visible to all users $result = db_query('SELECT DISTINCT realm, COUNT(DISTINCT nid) as node_count FROM {node_access} WHERE gid = 0 AND nid > 0 GROUP BY realm'); $rows = array(); while ($row = db_fetch_object($result)) { $rows[] = array($row->realm, array('data' => $row->node_count, 'align' => 'center')); } if (!empty($rows)) { $output .= '

'. t('Access Granted to Some Nodes') ."

\n"; $output .= '

'. t('The following realms appear to grant all users access to some specific nodes. This may be perfectly normal, if some of your content is available to the public.') ."

\n"; $headers = array(t('realm'), t('public nodes')); $output .= theme('table', $headers, $rows, array(), t('Public Nodes')); } // find specific nodes protected by node_access table $result = db_query('SELECT DISTINCT realm, COUNT(DISTINCT nid) as node_count FROM {node_access} WHERE gid <> 0 AND nid > 0 GROUP BY realm'); $rows = array(); while ($row = db_fetch_object($result)) { $rows[] = array(l($row->realm, "devel/node_access/view/$row->realm"), array('data' => $row->node_count, 'align' => 'center')); } if (!empty($rows)) { $output .= '

'. t('Summary by Realm') ."

\n"; $output .= '

'. t('The following realms grant limited access to some specific nodes.') ."

\n"; $headers = array(t('realm'), t('private nodes')); $output .= theme('table', $headers, $rows, array(), t('Protected Nodes')); } return $output; } function dna_visible_nodes($nid = null) { static $nids = array(); if ($nid) { $nids[$nid] = $nid; } return $nids; } function devel_node_access_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { if ($op == 'view') { // remember this node, for display in our block dna_visible_nodes($node->nid); } } function devel_node_access_block($op = 'list', $delta = 0) { switch ($op) { case 'list': $blocks[0]['info'] = t('Devel Node Access'); $blocks[0]['status'] = 1; $blocks[0]['region'] = 'footer'; $blocks[1]['info'] = t('Devel Node Access by User'); $blocks[1]['status'] = 0; $blocks[1]['region'] = 'footer'; return $blocks; case 'view': if (!user_access(DNA_ACCESS_VIEW)) { return; } switch ($delta) { case 0: if (!count(dna_visible_nodes())) { return; } // include rows where nid == 0 $nids = array_merge(array(0 => 0), dna_visible_nodes()); $result = db_query('SELECT na.*, n.title FROM {node_access} na LEFT JOIN {node} n ON n.nid = na.nid WHERE na.nid IN (%s) ORDER BY na.nid', implode(',', $nids)); $headers = array(t('node'), t('realm'), t('gid'), t('view'), t('update'), t('delete'), t('explained')); $rows = array(); while ($row = db_fetch_object($result)) { $explained = module_invoke_all('node_access_explain', $row); $rows[] = array($row->title ? $row->title : $row->nid, $row->realm, $row->gid, $row->grant_view, $row->grant_update, $row->grant_delete, implode('; ', $explained)); } $output = theme('table', $headers, $rows, array('style' => 'text-align: left')); $subject = t('node_access entries for nodes shown on this page'); return array('subject' => $subject, 'content' => $output .'

'); case 1: // show which users can access this node if (arg(0) == 'node' && is_numeric(arg(1))) { $nid = arg(1); $node = node_load($nid); $headers = array(t('username'), t('view'), t('update'), t('delete')); $rows = array(); // Find all users. The following operations are very inefficient, so we // limit the number of users returned. It would be better to make a // pager query, or at least make the number of users configurable. If // anyone is up for that please submit a patch. $result = db_query_range('SELECT DISTINCT u.* FROM {users} u ORDER BY u.access DESC', 0, 10); while ($data = db_fetch_object($result)) { $account = user_load(array('uid' => $data->uid)); $rows[] = array(theme('username', $data), theme('dna_permission', node_access('view', $node, $account)), theme('dna_permission', node_access('update', $node, $account)), theme('dna_permission', node_access('delete', $node, $account)), ); } if (count($rows)) { $output = theme('table', $headers, $rows, array('style' => 'text-align: left')); return array('subject' => t('Access permissions by user'), 'content' => $output); } } break; } break; } } /** * Implementation of hook_node_access_explain */ function devel_node_access_node_access_explain($row) { if ($row->gid == 0 && $row->realm == 'all') { if ($row->nid == 0) { return 'All users may view all nodes.'; } else { return 'All users may view this node.'; } } } /** * Implementation of hook_theme. */ function devel_node_access_theme() { return array( 'dna_permission' => array( 'arguments' => array('permission'), ), ); } /** * Indicate whether user has a permission or not. * * TODO: use good looking images. */ function theme_dna_permission($permission) { if ($permission) { return t('yes'); } else { return t('no'); } } function devel_node_access_views_tables() { $tables['node_access'] = array('name' => 'node_access', 'join' => array('left' => array('table' => 'node', 'field' => 'nid'), 'right' => array('field' => 'nid')), 'fields' => array('realm' => array('name' => t('Node Access: realm'), 'sortable' => true, ), ), 'filters' => array('realm' => array('name' => t('Node Access Realm'), 'operator' => 'views_handler_operator_eqneq', ), ), ); return $tables; } function devel_node_access_views_arguments() { $arguments = array('realm' => array('name' => t('Node Access: Realm'), 'handler' => 'dna_handler_arg_realm', ), ); return $arguments; } function dna_handler_arg_realm($op, &$query, $argtype, $arg = '') { switch ($op) { case 'summary': $query->ensure_table('node_access', true); $query->add_field('realm', 'node_access'); $fieldinfo['field'] = 'realm'; $query->add_orderby('node_access', 'realm', 'ASC'); return $fieldinfo; break; case 'filter': $query->ensure_table('node_access'); if ($arg == 'NULL') { $query->add_where("node_access.realm IS NULL"); } else { $query->add_where("node_access.realm = '$arg'"); } break; case 'link': if ($query->realm) { return l($query->realm, "$arg/$query->realm"); } else { return l('NULL', "$arg/NULL"); } break; case 'title': return $query; } } function devel_node_access_views_default_views() { $view = new stdClass(); $view->name = 'devel_node_access'; $view->description = 'View nodes in the node_access table'; $view->access = array(); $view->page = TRUE; $view->page_title = 'Nodes in the node_access table'; $view->page_header = ''; $view->page_header_format = '1'; $view->page_type = 'table'; $view->url = 'devel/node_access/view'; $view->use_pager = TRUE; $view->nodes_per_page = '100'; $view->sort = array(); $view->argument = array( array( 'type' => 'realm', 'argdefault' => '3', 'title' => 'Nodes in the node_access table where realm is %1', 'options' => '', ), ); $view->field = array( array( 'tablename' => 'node', 'field' => 'title', 'label' => 'Title', 'handler' => 'views_handler_field_nodelink', 'sortable' => '1', 'defaultsort' => 'ASC', ), array( 'tablename' => 'node', 'field' => 'type', 'label' => 'Type', 'sortable' => '1', ), array( 'tablename' => 'node', 'field' => 'changed', 'label' => 'Updated', 'handler' => 'views_handler_field_date_small', 'sortable' => '1', ), ); $view->filter = array(); $view->requires = array(node); $views[$view->name] = $view; return $views; }