? views-305250-35.patch
? views-305250-40-6.x-3.x.patch
Index: views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v
retrieving revision 1.332.2.29
diff -u -p -r1.332.2.29 views.module
--- views.module	29 Apr 2010 18:26:02 -0000	1.332.2.29
+++ views.module	2 Jun 2010 21:35:09 -0000
@@ -486,6 +486,42 @@ function views_check_roles($rids, $accou
   $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
   return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles);
 }
+
+/**
+ * Access callback to determine if logged in user matches the UID argument.
+ *
+ * Access can either allow the current user if the user id matches
+ * the UID argument, or if the ids don't match.
+ */
+function views_check_logged_in_user($view_name, $display_id, $argument, $access) {
+  global $user;
+
+  $view = views_get_view($view_name);
+  $view->set_display($display_id);
+  $view->init_handlers();
+
+  // Find the values for any arguments embedded in the path via '%'.
+  $i = 0;
+  foreach (explode('/', $view->display_handler->get_option('path')) as $element) {
+    if ($element == '%') {
+      $view->args[] = arg($i);
+    }
+    $i++;
+  }
+  // Now handle any implicit arguments from the end of the path.
+  $num_arguments = count($view->argument);
+  while (count($view->args) < $num_arguments) {
+    $view->args[] = arg($i);
+    $i++;
+  }
+
+  $arg_uid = FALSE;
+  if ($view->argument[$argument]) {
+    $arg_uid = $view->argument[$argument]->get_value();
+  }
+  return !(($user->uid === $arg_uid) XOR $access);
+
+}
 // ------------------------------------------------------------------
 // Functions to help identify views that are running or ran
 
Index: includes/plugins.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/plugins.inc,v
retrieving revision 1.152.2.11
diff -u -p -r1.152.2.11 plugins.inc
--- includes/plugins.inc	12 Mar 2010 18:51:17 -0000	1.152.2.11
+++ includes/plugins.inc	2 Jun 2010 21:35:09 -0000
@@ -235,6 +235,12 @@ function views_views_plugins() {
         'uses options' => TRUE,
         'help topic' => 'access-perm',
       ),
+      'logged_in_user' => array(
+        'title' => t('Logged In User'),
+        'help' => t('Access will be granted if the logged in user matches or doesn\'t match the user ID in the argument.'),
+        'handler' => 'views_plugin_access_logged_in_user',
+        'uses options' => TRUE,
+      ),
     ),
     'query' => array(
       'parent' => array(
Index: plugins/views_plugin_access_logged_in_user.inc
===================================================================
RCS file: plugins/views_plugin_access_logged_in_user.inc
diff -N plugins/views_plugin_access_logged_in_user.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/views_plugin_access_logged_in_user.inc	2 Jun 2010 21:35:09 -0000
@@ -0,0 +1,73 @@
+<?php
+// $Id$
+
+/**
+ * Validate whether the current logged in user matches the UID argument in the URL.
+ */
+class views_plugin_access_logged_in_user extends views_plugin_access {
+
+  /**
+   * Check access outside of the menu system (e.g. used for block displays).
+   */
+  function access($account) {
+    global $user;
+    $this->view->set_display($this->display->id);
+    $this->view->init_handlers();
+    $user_arg = $this->options['logged_in_user_argument'];
+    $user_access = $this->options['logged_in_user_access'];
+    $argument = $this->view->argument[$user_arg];
+    $arg_uid = FALSE;
+    if (!$argument) {
+      $arg_uid = $argument->get_value();
+    }
+    return !(($user->uid === $arg_uid) XOR $user_access);
+  }
+
+  function get_access_callback() {
+    return array('views_check_logged_in_user', array($this->view->name, $this->display->id, $this->options['logged_in_user_argument'], $this->options['logged_in_user_access']));
+  }
+
+  function summary_title() {
+    return t('Logged in user.');
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['logged_in_user_argument'] = array('default' => '');
+    $options['logged_in_user_access'] = array('default' => 1);
+
+    return $options;
+  }
+  
+  function options_form(&$form, &$form_state) {
+    $arguments = array();
+    foreach ($this->view->display_handler->get_handlers('argument') as $id => $handler) {
+      $arguments[$id] = $handler->definition['title'];
+    }
+    if (!$arguments) {
+      $form['arguments'] = array(
+        '#value' => t('Create an user uid argument before configuring this access control.'),
+      );
+    }
+    $form['logged_in_user_argument'] = array(
+      '#type' => 'select',
+      '#options' => $arguments,
+      '#title' => t('Logged in user argument'),
+      '#description' => t('Select which argument represents the user whose will be compared to the logged in user.'),
+      '#default_value' => $this->options['logged_in_user_argument'],
+      '#required' => TRUE,
+    );
+
+    $form['logged_in_user_access'] = array(
+      '#type' => 'radios',
+      '#options' => array(
+        '0' => t('Fail if the user is the user ID in the argument'),
+        '1' => t('Pass if the user is the user ID in the argument'),
+      ),
+      '#title' => t('Logged in user argument'),
+      '#description' => t('Select how the currently logged in user should be compared to the user ID argument.'),
+      '#default_value' => $this->options['logged_in_user_access'],
+    );
+  }
+
+}
