? views_node_access.patch
Index: modules/node.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/node.views.inc,v
retrieving revision 1.93
diff -u -p -r1.93 node.views.inc
--- modules/node.views.inc	8 Apr 2009 20:54:57 -0000	1.93
+++ modules/node.views.inc	1 Jun 2009 04:26:34 -0000
@@ -480,6 +480,31 @@ function node_views_data() {
   );
 
   // ----------------------------------------------------------------------
+  // Node access table
+
+  // Define the base group of this table. Fields that don't
+  // have a group defined will go into this field by default.
+  $data['node_access']['table']['group']  = t('Node access');
+
+  // For other base tables, explain how we join
+  $data['node_access']['table']['join'] = array(
+    // Directly links to node table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    ),
+  );
+  // nid field
+  $data['node_access']['nid'] = array(
+    'title' => t('Access'),
+    'help' => t('Filter by access.'),
+    'filter' => array(
+      'handler' => 'views_handler_filter_node_access',
+      'help' => t('Filter for nodes by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
+    ),
+  );
+
+  // ----------------------------------------------------------------------
   // History table
 
   // We're actually defining a specific instance of the table, so let's
@@ -604,7 +629,9 @@ function node_views_handlers() {
       'views_handler_filter_node_status' => array(
         'parent' => 'views_handler_filter',
       ),
-
+      'views_handler_filter_node_access' => array(
+        'parent' => 'views_handler_filter',
+      ),
     ),
   );
 }
Index: modules/node/views_handler_filter_node_access.inc
===================================================================
RCS file: modules/node/views_handler_filter_node_access.inc
diff -N modules/node/views_handler_filter_node_access.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/node/views_handler_filter_node_access.inc	1 Jun 2009 04:26:34 -0000
@@ -0,0 +1,33 @@
+<?php
+// $Id$
+/**
+ * Filter by node_access records.
+ */
+class views_handler_filter_node_access extends views_handler_filter {
+  function admin_summary() { }
+  function operator_form() { }
+  function can_expose() {
+    return FALSE;
+  }
+
+  /**
+   * See _node_access_where_sql() for a non-views query based implementation.
+   */
+  function query() {
+    if (!user_access('administer nodes')) {
+      $table = $this->ensure_my_table();
+      $grants = array();
+      foreach (node_access_grants($op, $account) as $realm => $gids) {
+        foreach ($gids as $gid) {
+          $grants[] = "($table.gid = $gid AND $table.realm = '$realm')";
+        }
+      }
+      $grants_sql = '';
+      if (count($grants)) {
+        $grants_sql = implode(' OR ', $grants);
+      }
+      $this->query->add_where('AND', $grants_sql);
+      $this->query->add_where('AND', "$table.grant_view >= 1");
+    }
+  }
+}
