Index: subuser.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/subuser/subuser.module,v
retrieving revision 1.4
diff -u -r1.4 subuser.module
--- subuser.module	29 Apr 2009 05:45:54 -0000	1.4
+++ subuser.module	8 Sep 2009 22:31:34 -0000
@@ -13,6 +13,7 @@
 define('SUBUSER_PARENT', variable_get('subuser_parent', 'Parent'));
 define('SUBUSER_LIST', variable_get('subuser_list', 'Subusers'));
 define('SUBUSER_CREATE', variable_get('subuser_create', 'Create subuser'));
+define('SUBUSER_ADMINISTER', variable_get('subuser_administer', 'Administer subusers'));
 
 /**
  * Implementation of hook_menu().
@@ -52,7 +53,12 @@
  * Implementation of hook_perm().
  */
 function subuser_perm() {
-  return array('create subuser', 'switch subuser', 'administer subuser settings');
+  return array(
+    'create subuser',
+    'switch subuser',
+    'administer subuser settings',
+    'administer subusers',
+  );
 }
 
 /**
@@ -82,6 +88,94 @@
 }
 
 /**
+ * Implementation of hook_menu_link_alter().
+ */
+function subuser_menu_alter(&$items) {
+  $items['user/%user_category/edit']['access callback'] = 'subuser_user_edit_access';
+  $items['admin/user/user']['access callback'] = 'subuser_administer_users_access';
+  $items['admin/user/user']['title callback'] = 'subuser_administer_users_title';
+}
+
+/**
+ * Modified version of user_edit_access() for 'administer subusers' logic.
+ */
+function subuser_user_edit_access($account) {
+  // Condition from user_edit_access().
+  if ((($GLOBALS['user']->uid == $account->uid) || user_access('administer users')) && $account->uid > 0) {
+    return TRUE;
+  }
+
+  // Check if user can administer subusers and the user being editted is a
+  // subuser of the active user.
+  if (user_access('administer subusers') &&
+      db_result(db_query('SELECT uid FROM {user_relationship} WHERE uid = %d AND parent_id = %d', $account->uid, $GLOBALS['user']->uid))) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+ * Access callback for admin/user/user page.
+ *
+ * If user has 'administer users' or 'administer subusers' then allow them to
+ * view the administer users page. Filter the view to only the user's they are
+ * a parent of if they do not have the 'administer users' permission.
+ *
+ * @return boolean TRUE access granted, otherwise FALSE.
+ */
+function subuser_administer_users_access() {
+  if (user_access('administer users')) {
+    return TRUE;
+  }
+
+  if (user_access('administer subusers')) {
+    global $user;
+
+    if (!isset($_SESSION['user_overview_filter'])) {
+      $_SESSION['user_overview_filter'] = array();
+    }
+
+    // Look for the subuser filter and ensure it is set to the current user if
+    // found, otherwise it will be added bellow.
+    $found = FALSE;
+    foreach ($_SESSION['user_overview_filter'] as $index => $filter) {
+      list($key, $value) = $filter;
+
+      if ($key == 'subuser') {
+        $_SESSION['user_overview_filter'][$index][1] = $user->uid;
+        $found = TRUE;
+        break;
+      }
+    }
+
+    // Explicitly add the filter.
+    if (!$found) {
+      $_SESSION['user_overview_filter'][] = array(
+        'subuser',
+        $user->uid,
+      );
+    }
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+ * Title callback for admin/user/user page.
+ *
+ * Set the title to the custom subuser administer title when user has
+ * 'administer subusers' and not 'administer users' permission.
+ *
+ * @return string Either default title or custom subuser title.
+ */
+function subuser_administer_users_title() {
+  if (!user_access('administer users') && user_access('administer subusers')) {
+    return t(SUBUSER_ADMINISTER);
+  }
+  return t('Users');
+}
+
+/**
  * Check if the user has permission to switch the specified user.
  *
  * Pass cases:
@@ -149,14 +243,26 @@
 
       // The parent user should either have access to create subusers, or have
       // existing subusers.
-      $access = user_access('create subuser');
+      $create = user_access('create subuser');
+      $administer = user_access('administer subusers');
       $view = views_get_view('subusers');
-      if ($access || (isset($view->results) && $view->results)) {
+      if ($create || (isset($view->results) && $view->results)) {
         $view = views_embed_view('subusers');
+
+        if ($create) {
+          $links[] = l(t(SUBUSER_CREATE), 'user/' . $account->uid . '/subuser/create');
+        }
+        if ($administer) {
+          $links[] = l(t(SUBUSER_ADMINISTER), 'admin/user/user');
+        }
+
+        $output = implode(' | ', $links);
+        $output .= '<br />' . $view;
+
         $account->content['subusers'] = array(
           '#type' => 'user_profile_item',
           '#title' => t(SUBUSER_LIST),
-          '#value' => ($access ? l(t(SUBUSER_CREATE), 'user/' . $account->uid . '/subuser/create') : '') . '<br />' . $view,
+          '#value' => $output,
           '#weight' => 11,
         );
       }
Index: subuser.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/subuser/subuser.pages.inc,v
retrieving revision 1.1
diff -u -r1.1 subuser.pages.inc
--- subuser.pages.inc	24 Apr 2009 02:06:43 -0000	1.1
+++ subuser.pages.inc	8 Sep 2009 22:31:34 -0000
@@ -41,6 +41,12 @@
     '#description' => t('The text used for the link and page title when creating a subuser.'),
     '#default_value' => SUBUSER_CREATE,
   );
+  $form['display']['subuser_administer'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Administer'),
+    '#description' => t('The text used for the link and page title when administering subusers.'),
+    '#default_value' => SUBUSER_ADMINISTER,
+  );
 
   if ($roles) {
     $form['roles'] = array(
Index: INSTALL.txt
===================================================================
RCS file: INSTALL.txt
diff -N INSTALL.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ INSTALL.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,13 @@
+// $Id$
+
+AUTHOR
+------
+
+  Jimmy Berry ("boombatower", http://drupal.org/user/214218)
+
+INSTALLATION
+------------
+
+1.  Apply the subuser.patch file to Drupal 6 core.
+
+2.  Enabled subuser.
Index: subuser.test
===================================================================
RCS file: subuser.test
diff -N subuser.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ subuser.test	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,55 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provide test of functionality.
+ *
+ * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
+ */
+
+class SubuserTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('Subuser'),
+      'description' => t('...'),
+      'group' => t('Subuser'),
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  public function setUp() {
+    parent::setUp('views', 'subuser');
+  }
+
+  /**
+   * Confirm the various client management interfaces function properly.
+   */
+  public function testSubuser() {
+    // Create user that has the necessary PIFR permissions.
+    $user = $this->drupalCreateUser(array('pifr add project client', 'pifr add test client', 'pifr manage own client'));
+    $this->drupalLogin($user);
+
+    // Create a test client.
+    $client_id = $this->createClient($user->uid, PIFR_SERVER_CLIENT_TYPE_TEST);
+
+    // Attempt to set the test client URL to an invalid value.
+    $edit = array(
+      'url' => 'fail',
+      'type' => PIFR_SERVER_CLIENT_TYPE_PROJECT
+    );
+    $this->drupalPost("user/$user->uid/pifr/edit/$client_id", $edit, t('Save'));
+    $this->assertText(t('Client URL must end with a slash.'));
+
+    // Change the test client to a project client.
+    unset($edit['url']);
+    $this->drupalPost("user/$user->uid/pifr/edit/$client_id", $edit, t('Save'));
+    $this->assertText(t('Changes saved successfully.'));
+  }
+}
Index: subuser.patch
===================================================================
RCS file: subuser.patch
diff -N subuser.patch
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ subuser.patch	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,23 @@
+Index: modules/user/user.module
+===================================================================
+RCS file: /cvs/drupal/drupal/modules/user/user.module,v
+retrieving revision 1.892.2.15
+diff -u -r1.892.2.15 user.module
+--- modules/user/user.module	10 Aug 2009 11:34:59 -0000	1.892.2.15
++++ modules/user/user.module	8 Sep 2009 22:09:55 -0000
+@@ -1986,6 +1986,15 @@
+     'join' => '',
+     'options' => array(1 => t('active'), 0 => t('blocked')),
+   );
++
++  // Subuser filter.
++  global $user;
++  $filters['subuser'] = array(
++    'title' => 'parent',
++    'join' => 'JOIN {user_relationship} subuser ON u.uid = subuser.uid',
++    'where' => 'subuser.parent_id = %d',
++    'options' => array($user->uid => $user->name),
++  );
+   return $filters;
+ }
+ 
