TwoGrunts
 


Navigation


 

Access Control UI Enhancement

mike  2006-08-15 08:11     

I've proposed the following UI enhancement to the Drupal Access Control panel:

My pet peeve is the fact that when you have any non-standard roles, you have more columns of checkboxes to select from, and when you have many modules enabled, you also have many rows to view and the header row (with the role names) disappears, causing one to scroll back and forth to be sure that you are checking the box for the desired role.

I'm aware that merlinofchaos is working to improve the core administrative UI, and I applaud that effort. But, for those of us who are stuck with the current implementation, this solves one of those irritations.

My proposal for a quick and simple solution is to prepend the role name to the permission label tooltip that is displayed when you hover the mouse cursor over the checkbox. (I can think of other, more elegant ways to do this, including a fixed header, or scrolling regions with the header at the top, but I don't have the time to implement those right now.)

So, prior to this patch the tooltip/hover text read "edit own blog", and after, the tooltip reads: "allow contributing editor to edit own blog" (see below).

Now, the screen snapshot above is not a great example, because the header row is visible. But consider what will happen if you scroll down to access those hard-to-reach modules. Here's a snapshot with the cursor hovering over the "administer search" permission:

Here's the patch between the Drupal 4.7.3 CVS user.module and my proposed changes.


diff -u -uF^function -- user.module (in directory C:\devroot\cvs-drupal\drupal\modules\)
Index: user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/Attic/user.module,v
retrieving revision 1.612.2.17
diff -u -u -F^function -r1.612.2.17 user.module
--- user.module	3 Aug 2006 13:53:15 -0000	1.612.2.17
+++ user.module	15 Aug 2006 14:56:45 -0000
@@ -1799,6 +1799,15 @@ function user_admin_perm($str_rids = NUL
 }
 
 function theme_user_admin_perm($form) {
+  // I want to add the role name to the 'title' (hover  pop-up) text for each perm
+  // So, I get a list of role names (because I can't figure out how to get 
+  // the list from the $form[] array)
+  $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
+  $role_names = array();
+  while ($role = db_fetch_object($result)) {
+    $role_names[$role->rid] = $role->name;
+  }
+
   foreach (element_children($form['permission']) as $key) {
     // Don't take form control structures
     if (is_array($form['permission'][$key])) {
@@ -1812,7 +1821,7 @@ function theme_user_admin_perm($form) {
         $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'permission');
         foreach (element_children($form['checkboxes']) as $rid) {
           if (is_array($form['checkboxes'][$rid])) {
-            $row[] = array('data' => form_render($form['checkboxes'][$rid][$key]), 'align' => 'center', 'title' => t($key));
+            $row[] = array('data' => form_render($form['checkboxes'][$rid][$key]), 'align' => 'center', 'title' =>  t('allow ') . $role_names[$rid] . t(' to ') . t($key) );
           }
         }
       }

Here's the full text of the theme_user_admin_perm() function:

function theme_user_admin_perm($form) {
  // I want to add the role name to the 'title' (hover  pop-up) text for each perm
  // So, I get a list of role names (because I can't figure out how to get 
  // the list from the $form[] array)
  $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
  $role_names = array();
  while ($role = db_fetch_object($result)) {
    $role_names[$role->rid] = $role->name;
  }

  foreach (element_children($form['permission']) as $key) {
    // Don't take form control structures
    if (is_array($form['permission'][$key])) {
      $row = array();
      // Module name
      if (is_numeric($key)) {
        $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'module', 'colspan' => count($form['role_names']) + 1);
      // Permissions
      }
      else {
        $row[] = array('data' => form_render($form['permission'][$key]), 'class' => 'permission');
        foreach (element_children($form['checkboxes']) as $rid) {
          if (is_array($form['checkboxes'][$rid])) {
            $row[] = array('data' => form_render($form['checkboxes'][$rid][$key]), 'align' => 'center', 'title' =>  t('allow ') . $role_names[$rid] . t(' to ') . t($key) );
          }
        }
      }
      $rows[] = $row;
    }
  }
  $header[] = (t('Permission'));
  foreach (element_children($form['role_names']) as $rid) {
    if (is_array($form['role_names'][$rid])) {
      $header[] = form_render($form['role_names'][$rid]);
    }
  }
  $output = theme('table', $header, $rows, array('id' => 'permissions'));
  $output .= form_render($form);
  return $output;
}

Update:
This has been proposed before:

But I'm not sure these patches work in 4.7.x