ACL: Added API call to edit rule based only on numeric rule ID; to be used later with lister for existing rules and effective permissions viewer
authorDan
Thu, 27 Mar 2008 16:41:07 -0400
changeset 512 13532b0a223f
parent 511 f88c8c79d784
child 513 c15fbf197a54
ACL: Added API call to edit rule based only on numeric rule ID; to be used later with lister for existing rules and effective permissions viewer
includes/clientside/static/acl.js
includes/pageutils.php
--- a/includes/clientside/static/acl.js	Wed Mar 26 20:20:22 2008 -0400
+++ b/includes/clientside/static/acl.js	Thu Mar 27 16:41:07 2008 -0400
@@ -34,12 +34,11 @@
           return false;
         }
         try {
-          data = parseJSON(ajax.responseText);
+          var groups = parseJSON(ajax.responseText);
         } catch(e) {
           handle_invalid_json(ajax.responseText);
         }
         __aclBuildWizardWindow();
-        groups = parseJSON(ajax.responseText);
         if ( groups.mode == 'error' )
         {
           alert(groups.error);
@@ -53,6 +52,46 @@
   return false;
 }
 
+function ajaxOpenDirectACLRule(rule_id)
+{
+  var params = {
+    target_id: rule_id,
+    mode: 'seltarget_id'
+  };
+  params = ajaxEscape(toJSONString(params));
+  ajaxPost(stdAjaxPrefix+'&_mode=acljson', 'acl_params='+params, function() {
+      if ( ajax.readyState == 4 && ajax.status == 200 )
+      {
+        var response = String(ajax.responseText + '');
+        if ( response.substr(0, 1) != '{' )
+        {
+          handle_invalid_json(ajax.responseText);
+          return false;
+        }
+        try
+        {
+          response = parseJSON(response);
+        }
+        catch(e)
+        {
+          handle_invalid_json(response);
+        }
+        if ( !document.getElementById(aclManagerID) )
+        {
+          __aclBuildWizardWindow();
+        }
+        if ( response.mode == 'error' )
+        {
+          alert(response.error);
+          killACLManager();
+          return false;
+        }
+        aclDataCache = response;
+        aclBuildRuleEditor(response);
+      }
+    }, true);
+}
+
 function ajaxACLSwitchToSelector()
 {
   params = {
@@ -335,92 +374,7 @@
           case 'seltarget':
             
             // Build the ACL edit form
-            // try {
-            
-              var act_desc = ( data.type == 'new' ) ? $lang.get('acl_lbl_editwin_title_create') : $lang.get('acl_lbl_editwin_title_edit');
-              var target_type_t = ( data.target_type == 1 ) ? $lang.get('acl_target_type_group') : $lang.get('acl_target_type_user');
-              var target_name_t = data.target_name;
-              var scope_type = ( data.page_id == false && data.namespace == false ) ? $lang.get('acl_scope_type_wholesite') : ( data.namespace == '__PageGroup' ) ? $lang.get('acl_scope_type_pagegroup') : $lang.get('acl_scope_type_thispage');
-              
-              html = '<h2>'+act_desc+'</h2>';
-              html += '<p>' + $lang.get('acl_lbl_editwin_body', { target_type: target_type_t, target: target_name_t, scope_type: scope_type }) + '</p>';
-              parser = new templateParser(data.template.acl_field_begin);
-              html += parser.run();
-              
-              cls = 'row2';
-              for(var i in data.acl_types)
-              {
-                if(typeof(data.acl_types[i]) == 'number')
-                {
-                  cls = ( cls == 'row1' ) ? 'row2' : 'row1';
-                  p = new templateParser(data.template.acl_field_item);
-                  vars = new Object();
-                  if ( data.acl_descs[i].match(/^([a-z0-9_]+)$/) )
-                  {
-                    vars['FIELD_DESC'] = $lang.get(data.acl_descs[i]);
-                  }
-                  else
-                  {
-                    vars['FIELD_DESC'] = data.acl_descs[i];
-                  }
-                  vars['FIELD_INHERIT_CHECKED'] = '';
-                  vars['FIELD_DENY_CHECKED'] = '';
-                  vars['FIELD_DISALLOW_CHECKED'] = '';
-                  vars['FIELD_WIKIMODE_CHECKED'] = '';
-                  vars['FIELD_ALLOW_CHECKED'] = '';
-                  vars['FIELD_NAME'] = i;
-                  if ( !data.current_perms[i] )
-                  {
-                    data.current_perms[i] = 'i';
-                  }
-                  switch(data.current_perms[i])
-                  {
-                    case 'i':
-                    default:
-                      vars['FIELD_INHERIT_CHECKED'] = 'checked="checked"';
-                      break;
-                    case 1:
-                      vars['FIELD_DENY_CHECKED'] = 'checked="checked"';
-                      break;
-                    case 2:
-                      vars['FIELD_DISALLOW_CHECKED'] = 'checked="checked"';
-                      break;
-                    case 3:
-                      vars['FIELD_WIKIMODE_CHECKED'] = 'checked="checked"';
-                      break;
-                    case 4:
-                      vars['FIELD_ALLOW_CHECKED'] = 'checked="checked"';
-                      break;
-                  }
-                  vars['ROW_CLASS'] = cls;
-                  p.assign_vars(vars);
-                  html += p.run();
-                }
-              }
-              
-              var parser = new templateParser(data.template.acl_field_end);
-              html += parser.run();
-              
-              if(data.type == 'edit')
-                html += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'' + $lang.get('acl_msg_deleterule_confirm') + '\')) __aclDeleteRule(); return false;" style="color: red;">' + $lang.get('acl_lbl_deleterule') + '</a></p>';
-              
-              var main = document.getElementById(aclManagerID + '_main');
-              main.innerHTML = html;
-              
-              var form = document.getElementById(aclManagerID + '_formobj_id');
-              
-              var modeobj = form_fetch_field(form, 'mode');
-              if ( modeobj )
-                modeobj.value = 'save_' + data.type;
-              else
-                alert('modeobj is invalid: '+modeobj);
-              
-              aclPermList = array_keys(data.acl_types);
-              
-              document.getElementById(aclManagerID + '_back').style.display = 'inline';
-              document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
-              
-            // } catch(e) { alert(e); aclDebug(ajax.responseText); }
+            aclBuildRuleEditor(data);
             
             break;
           case 'success':
@@ -530,6 +484,92 @@
     }, true);
 }
 
+function aclBuildRuleEditor(data)
+{
+  var act_desc = ( data.type == 'new' ) ? $lang.get('acl_lbl_editwin_title_create') : $lang.get('acl_lbl_editwin_title_edit');
+  var target_type_t = ( data.target_type == 1 ) ? $lang.get('acl_target_type_group') : $lang.get('acl_target_type_user');
+  var target_name_t = data.target_name;
+  var scope_type = ( data.page_id == false && data.namespace == false ) ? $lang.get('acl_scope_type_wholesite') : ( data.namespace == '__PageGroup' ) ? $lang.get('acl_scope_type_pagegroup') : $lang.get('acl_scope_type_thispage');
+  
+  html = '<h2>'+act_desc+'</h2>';
+  html += '<p>' + $lang.get('acl_lbl_editwin_body', { target_type: target_type_t, target: target_name_t, scope_type: scope_type }) + '</p>';
+  parser = new templateParser(data.template.acl_field_begin);
+  html += parser.run();
+  
+  cls = 'row2';
+  for(var i in data.acl_types)
+  {
+    if(typeof(data.acl_types[i]) == 'number')
+    {
+      cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+      p = new templateParser(data.template.acl_field_item);
+      vars = new Object();
+      if ( data.acl_descs[i].match(/^([a-z0-9_]+)$/) )
+      {
+        vars['FIELD_DESC'] = $lang.get(data.acl_descs[i]);
+      }
+      else
+      {
+        vars['FIELD_DESC'] = data.acl_descs[i];
+      }
+      vars['FIELD_INHERIT_CHECKED'] = '';
+      vars['FIELD_DENY_CHECKED'] = '';
+      vars['FIELD_DISALLOW_CHECKED'] = '';
+      vars['FIELD_WIKIMODE_CHECKED'] = '';
+      vars['FIELD_ALLOW_CHECKED'] = '';
+      vars['FIELD_NAME'] = i;
+      if ( !data.current_perms[i] )
+      {
+        data.current_perms[i] = 'i';
+      }
+      switch(data.current_perms[i])
+      {
+        case 'i':
+        default:
+          vars['FIELD_INHERIT_CHECKED'] = 'checked="checked"';
+          break;
+        case 1:
+          vars['FIELD_DENY_CHECKED'] = 'checked="checked"';
+          break;
+        case 2:
+          vars['FIELD_DISALLOW_CHECKED'] = 'checked="checked"';
+          break;
+        case 3:
+          vars['FIELD_WIKIMODE_CHECKED'] = 'checked="checked"';
+          break;
+        case 4:
+          vars['FIELD_ALLOW_CHECKED'] = 'checked="checked"';
+          break;
+      }
+      vars['ROW_CLASS'] = cls;
+      p.assign_vars(vars);
+      html += p.run();
+    }
+  }
+  
+  var parser = new templateParser(data.template.acl_field_end);
+  html += parser.run();
+  
+  if(data.type == 'edit')
+    html += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'' + $lang.get('acl_msg_deleterule_confirm') + '\')) __aclDeleteRule(); return false;" style="color: red;">' + $lang.get('acl_lbl_deleterule') + '</a></p>';
+  
+  var main = document.getElementById(aclManagerID + '_main');
+  main.innerHTML = html;
+  
+  var form = document.getElementById(aclManagerID + '_formobj_id');
+  
+  var modeobj = form_fetch_field(form, 'mode');
+  if ( modeobj )
+    modeobj.value = 'save_' + data.type;
+  else
+    alert('modeobj is invalid: '+modeobj);
+  
+  aclPermList = array_keys(data.acl_types);
+  
+  document.getElementById(aclManagerID + '_back').style.display = 'inline';
+  document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
+}
+
 function __aclBuildGroupsHTML(groups)
 {
   groups = groups.groups;
--- a/includes/pageutils.php	Wed Mar 26 20:20:22 2008 -0400
+++ b/includes/pageutils.php	Thu Mar 27 16:41:07 2008 -0400
@@ -1647,6 +1647,37 @@
               );
           }
           break;
+        case 'seltarget_id':
+          if ( !is_int($parms['target_id']) )
+          {
+            return Array(
+              'mode' => 'error',
+              'error' => 'Expected parameter target_id type int'
+              );
+          }
+          $q = $db->sql_query('SELECT target_id, target_type, page_id, namespace, rules FROM ' . table_prefix . "acl WHERE rule_id = {$parms['target_id']};");
+          if ( !$q )
+            return Array(
+              'mode' => 'error',
+              'error' => $db->get_error()
+              );
+          if ( $db->numrows() < 1 )
+            return Array(
+              'mode' => 'error',
+              'error' => "No rule with ID {$parms['target_id']} found"
+              );
+            $parms = $db->fetchrow();
+            $db->free_result();
+            
+            // regenerate page selection
+            $parms['page_id'] = ( isset($parms['page_id']) ) ? $parms['page_id'] : false;
+            $parms['namespace'] = ( isset($parms['namespace']) ) ? $parms['namespace'] : false;
+            $page_id =& $parms['page_id'];
+            $namespace =& $parms['namespace'];
+            $page_where_clause      = ( empty($page_id) || empty($namespace) ) ? 'AND a.page_id IS NULL AND a.namespace IS NULL' : 'AND a.page_id=\'' . $db->escape($page_id) . '\' AND a.namespace=\'' . $db->escape($namespace) . '\'';
+            $page_where_clause_lite = ( empty($page_id) || empty($namespace) ) ? 'AND page_id IS NULL AND namespace IS NULL' : 'AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\'';
+            
+            // From here, let the seltarget handler take over
         case 'seltarget':
           $return['mode'] = 'seltarget';
           $return['acl_types'] = $perms_obj->acl_types;