Code

Cleaned up aclResolver
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 21 Apr 2010 14:34:38 +0000 (14:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 21 Apr 2010 14:34:38 +0000 (14:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17780 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/references/class_aclResolver.inc
gosa-core/plugins/generic/references/class_reference.inc
gosa-core/plugins/generic/references/contents.tpl

index d3c16f5f8d97a27901f26a188456ec0d03eaf03d..9e178f422b545abf4e46ada4e55a6f6a11b50be0 100644 (file)
@@ -1,40 +1,57 @@
 <?php
 
-class aclResolver extends userinfo
+class aclResolver 
 {
-    private $attrs = array();
 
+    private $classMapping = array();
+    private $aclTypes = array();
     private $affectingACLs = array();
-    private $acl_category = "none";
 
     function __construct($config, $dn, $parent)
     {
         $this->config = &$config;
         $this->dn = $dn;
-        $this->parent = &$parent;
-
-        $ldap = $this->config->get_ldap_link();
-        $ldap->cd($this->config->current['BASE']);
-        $ldap->cat($dn);
-        $this->attrs = $ldap->fetch();
-   
-        if(isset($this->parent->acl_category) && !empty($this->parent->acl_category)){
-            $this->acl_category = preg_replace("/\/$/","",$this->parent->acl_category);
-        }
-        if(isset($attrs['uid'][0])){
-            $this->uid = $attrs['uid'][0];
+
+        // Get ACL category for the current object.
+        if(isset($parent->acl_category) && !empty($parent->acl_category)){
+            $this->acl_category = preg_replace("/\/$/","",$parent->acl_category);
         }
-    
-        $this->ignoreACL = ($this->config->get_cfg_value("ignoreAcl") == $this->dn);
-        $this->reset_acl_cache(); 
-        $this->loadACL(); 
 
+        // Build class mapping
+        if(!session::is_set('aclConverter::classMapping')){
+            $tmp= session::global_get('plist');
+            $plist= $tmp->info;
+            $map = array();
+            $map['all']= _("All categories");
+            foreach($plist as $class => $plInfo){
+                if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
+                    foreach($plInfo['plCategory'] as $category => $desc){
+                        if(!is_numeric($category)){
+                            $map[$category] = $desc['description'];
+                        }
+                    }
+                }
+            }
+            foreach($plist as $class => $plInfo){
+                if(isset($plInfo['plCategory']) && is_array($plInfo['plCategory'])){
+                    foreach($plInfo['plCategory'] as $category => $desc){
+                        if(!is_numeric($category)){
+                            $map[$category."/".$class] = $map[$category]." - ".$plInfo['plDescription'];
+                        }else{
+                            $map[$desc."/".$class] = $map[$desc]." - ".$plInfo['plDescription'];
+                        }
+                    }
 
+                }
+            }
+            session::set('aclConverter::classMapping', $map);
+        }
+        $this->classMapping = session::get('aclConverter::classMapping');
 
-        foreach($this->allACLs as $dn => $acls){
+        // Go through all ACLs and get those matching out DN.
+        $ui = get_userinfo();
+        foreach($ui->allACLs as $dn => $acls){
             if(preg_match("/".preg_quote($dn,'/')."$/i", $this->dn)){
-    
                 foreach($acls as $prio => $acl){
                     if($acl['type'] == "reset"){
                         $this->affectingACLs[$dn][$prio] = $acl;
@@ -51,33 +68,34 @@ class aclResolver extends userinfo
                 }
             }
         }
+
+        // Define ACL type translations
+        $this->aclTypes= array("reset" => _("Reset ACLs"),
+                "one" => _("One level"),
+                "base" => _("Current object"),
+                "sub" => _("Complete subtree"),
+                "psub" => _("Complete subtree (permanent)"),
+                "role" => _("Use ACL defined in role"));
     }
 
-        
+
+    /*! \brief   Create a human readable HTML result 
+     */    
     function getReadableACL() 
     {
         $str = "<table summary='"._("Object permissions")."' width='100%'>";
-        
         foreach($this->affectingACLs as $dn => $acls){
-
             foreach($acls as $acl){
-              
                 $str.="<tr>"; 
                 if(isset($this->config->idepartments[$dn])){
                     $image= image("images/select_department.png");
                 }else{
                     $image= image("images/lists/element.png");
                 }
-                $aclTypes= array("reset" => _("Reset ACLs"),
-                        "one" => _("One level"),
-                        "base" => _("Current object"),
-                        "sub" => _("Complete subtree"),
-                        "psub" => _("Complete subtree (permanent)"),
-                        "role" => _("Use ACL defined in role"));
 
                 $str.="<td style='width:20px;'>".$image."</td>";
                 $str.="<td><b>".$dn."</b></td>";
-                $str.="<td>".$aclTypes[$acl['type']]."</td>";
+                $str.="<td rowspan=3>".$this->aclTypes[$acl['type']]."</td>";
                 $str.="</tr><tr>";
                 $str.="<td></td><td><b>"._("Members")."</b><ul>";
                 foreach($acl['members'] as $type => $name){
@@ -85,36 +103,52 @@ class aclResolver extends userinfo
                 }
                 $str .= "</ul>"; 
                 $str .= "</td>"; 
-                $str.="";
-        
+                $str .= "</tr><tr><td></td>";
+
                 if($acl['type']!='reset'){
                     $str.="<td><b>"._("Acls")."</b><ul>";
-                    foreach($acl['acl'] as $type => $name){
-                        $str .= "<li>".$type.": <i>".$this->aclToString(implode(array_unique($name)))."</i></li>";
+                    foreach($acl['acl'] as $type => $acl){
+
+                        if(isset($this->classMapping[$type])){
+                            $str .= "<li>".$this->classMapping[$type].": ".$this->aclToString($acl)."</li>";
+                        }else{
+                            $str .= "<li>".$type.": ".$this->aclToString($acl)."</li>";
+                        }
                     }
                     $str .= "</ul>"; 
                     $str .= "</td>"; 
                     $str .= "</tr>"; 
+                }else{
+                    $str .= "<td></td>";
                 }
                 $str .= "<tr><td colspan=3><hr></td></tr>"; 
             }
         }
-                $str .= "</table>"; 
+        $str .= "</table>"; 
         return($str);
     }
 
-    function aclToString($acl)
+    function aclToString($acls)
     {
-        $str ="";
-        if(preg_match("/r/", $acl)) $str.= _("read").', '; 
-        if(preg_match("/w/", $acl)) $str.= _("write").', '; 
-        if(preg_match("/c/", $acl)) $str.= _("Create").', '; 
-        if(preg_match("/d/", $acl)) $str.= _("Remove").', '; 
-        if(preg_match("/m/", $acl)) $str.= _("Move").', '; 
-        if(preg_match("/s/", $acl)) $str.= _("Owner").', '; 
-        return(trim($str,', '));
+        $str ="<ul>";
+        foreach($acls as $name => $acl){
+
+            if($name == "0") $name = _("All");
+
+            $str .= "<li>".$name.": <i>";
+
+            if(preg_match("/r/", $acl)) $str.= _("read").', '; 
+            if(preg_match("/w/", $acl)) $str.= _("write").', '; 
+            if(preg_match("/c/", $acl)) $str.= _("Create").', '; 
+            if(preg_match("/d/", $acl)) $str.= _("Remove").', '; 
+            if(preg_match("/m/", $acl)) $str.= _("Move").', '; 
+            if(preg_match("/s/", $acl)) $str.= _("Owner").', '; 
+            $str = trim($str,', ');
+            $str.= "</i></li>";
+        }
+        return($str."</ul>");
     }
 }
 
 ?>
-    
+
index 1c36e1b10f88c8efe4afc9ea20ccdfdda3901a66..db662408cbb44559b12ad4d461a7a98ceb860c58 100644 (file)
@@ -83,8 +83,6 @@ class reference extends plugin
     $ui = get_userinfo();
     
 
-    $r = new aclResolver($this->config, $this->dn, $this);
-    return($r->getReadableACL());
 
     /* Set government mode */
     $smarty= get_smarty();
@@ -101,6 +99,8 @@ class reference extends plugin
     /* Fill array */
     $this->reload();
     $smarty->assign("objectList", $this->objectlist);
+    $r = new aclResolver($this->config, $this->dn, $this);
+    $smarty->assign("acls",$r->getReadableACL());
 
     /* Show main page */
     return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
index c97cfbbf361a7354075d8bbb752ff8fb64642de1..6550d8b60ecde2e620add48f9ee8a860dea5ba97 100644 (file)
@@ -1,20 +1,28 @@
-{if $objectList ne ""}
-<table style='width:100%;' summary="{t}Object references{/t}">
+<table summary='{t}Object references{/t}'>
+    <tr>
+        <td style='width:50%;'>
+            {if $objectList ne ""}
+            <table style='width:100%;' summary="{t}Object references{/t}">
 
+             <colgroup>
+              <col width="20%">
+              <col width="20%">
+              <col width="60%">
+             </colgroup>
 
- <colgroup>
-  <col width="20%">
-  <col width="20%">
-  <col width="60%">
- </colgroup>
+             <tr style="background-color: #E8E8E8; height:26px;font-weight:bold;">
+              <td>{t}Object name{/t}</td><td>{t}Description{/t}</td><td>{t}Contents{/t}</td>
+             </tr>
 
- <tr style="background-color: #E8E8E8; height:26px;font-weight:bold;">
-  <td>{t}Object name{/t}</td><td>{t}Description{/t}</td><td>{t}Contents{/t}</td>
- </tr>
-
- {$objectList}
+             {$objectList}
 
+            </table>
+            {else}
+            <b>{t}This object has no relationship to other objects.{/t}</b>
+            {/if}
+        </td>
+        <td>
+            {$acls}
+        </td>
+    </tr>
 </table>
-{else}
-<b>{t}This object has no relationship to other objects.{/t}</b>
-{/if}