Code

Added some fixes:
[gosa.git] / plugins / admin / fai / class_faiPartitionTable.inc
index c299d6d9ae84c0aeaa75eecd33648337da85b0c0..550e719991cc036a9955d983edb24279c90b7179 100644 (file)
@@ -20,6 +20,7 @@ class faiPartitionTable extends plugin
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
 
   var $FAIstate         = "";
+  var $ui;
 
   function faiPartitionTable ($config, $dn= NULL)
   {
@@ -28,6 +29,8 @@ class faiPartitionTable extends plugin
 
     $this->acl ="#all#";
 
+    $this->ui = get_userinfo();    
+
     /* If "dn==new" we try to create a new entry
      * Else we must read all objects from ldap which belong to this entry.
      * First read disks from ldap ... and then the partition definitions for the disks.
@@ -35,13 +38,6 @@ class faiPartitionTable extends plugin
     if($dn != "new"){
       $this->dn =$dn;
 
-      /* Set acls
-       */
-      $ui   = get_userinfo();
-      $acl  = get_permissions ($this->dn, $ui->subtreeACL);
-      $acli = get_module_permission($acl, "FAIclass", $this->dn);
-      $this->acl=$acli;
-
       /* Get FAIstate
        */
       if(isset($this->attrs['FAIstate'][0])){
@@ -107,6 +103,20 @@ class faiPartitionTable extends plugin
     ksort($this->disks);
   }
 
+
+  function acl_base_for_current_object($dn)
+  {
+    if($dn == "new"){
+      if($this->dn == "new"){
+        $dn= $_SESSION['CurrentMainBase'];
+      }else{
+        $dn = $this->dn;
+      }
+    }
+    return($dn);
+  }
+
+
   function execute()
   {
        /* Call parent execute */
@@ -126,7 +136,8 @@ class faiPartitionTable extends plugin
         $usedDiskNames[]= $key;
       }
       $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); 
-      $this->dialog->acl = $this->acl;
+      $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
+      $this->dialog->set_acl_category("fai");
       $this->dialog->FAIstate = $this->FAIstate;
       $this->is_dialog = true;
     }
@@ -149,17 +160,21 @@ class faiPartitionTable extends plugin
           $usedDiskNames[]= $key;
         }
       }
-      $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
-      $this->dialog->acl = $this->acl;
-      $this->dialog->FAIstate = $this->FAIstate;
-     
+    
       /* Set object info string, which will be displayed in plugin info line */ 
       if(isset($this->disks[$Udisk]['dn'])){
         $_SESSION['objectinfo'] = $this->disks[$Udisk]['dn'];
+        $dn = $this->disks[$Udisk]['dn'];
       }else{
         $_SESSION['objectinfo'] = "";
+        $dn = "new";
       }
-    
+
+      $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
+      $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
+      $this->dialog->set_acl_category("fai");
+      $this->dialog->FAIstate = $this->FAIstate;
+     
       $this->is_dialog = true;
     }
 
@@ -256,10 +271,15 @@ class faiPartitionTable extends plugin
       }
     }
    
-    foreach($this->attributes as $attr){
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    $dn = $this->acl_base_for_current_object($this->dn);
+    $smarty->assign("sub_object_is_addable",
+        preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
+        !preg_match("/freeze/",$this->FAIstate));
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
-
     $disks = $this->getDisks();
     $smarty->assign("disks"   ,$disks);
     $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
@@ -272,24 +292,34 @@ class faiPartitionTable extends plugin
      */
     $a_return = array();
     foreach($this->disks as $key => $disk){
-      if($disk['status'] != "delete"){
-        $cnt=0;
-        foreach($disk['partitions'] as $val){
-          if($val['status']!="delete"){
-            $cnt ++;
-          }
-        }
-        if(!empty($disk['description'])){
-          if($cnt == 1){
-            $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
-          }else{
-            $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+
+      $dn = "new";
+      if(isset($obj['dn'])){
+        $dn = $obj['dn'];
+      }
+      $dn = $this->acl_base_for_current_object($dn);
+      $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
+      if(preg_match("/(r|w)/",$acl)) {
+
+        if($disk['status'] != "delete"){
+          $cnt=0;
+          foreach($disk['partitions'] as $val){
+            if($val['status']!="delete"){
+              $cnt ++;
+            }
           }
-        }else{
-          if($cnt == 1){
-            $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
+          if(!empty($disk['description'])){
+            if($cnt == 1){
+              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
+            }else{
+              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+            }
           }else{
-            $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+            if($cnt == 1){
+              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
+            }else{
+              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+            }
           }
         }
       }
@@ -305,7 +335,8 @@ class faiPartitionTable extends plugin
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
 
-    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+#    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $this->dn);
     if($_SESSION['faifilter']['branch'] == "main"){
       $use_dn = $this->dn;
     }
@@ -315,7 +346,8 @@ class faiPartitionTable extends plugin
     foreach($this->disks as $disk){
 
       $disk_dn = "cn=".$disk['cn'].",".$this->dn;
-      $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $disk_dn);
+#      $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $disk_dn);
+      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $disk_dn);
       if($_SESSION['faifilter']['branch'] == "main"){
         $use_dn = $disk_dn;
       }
@@ -324,7 +356,8 @@ class faiPartitionTable extends plugin
       foreach($disk['partitions'] as $key => $partition){    
      
         $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;      
-        $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $partition_dn);
+#        $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $partition_dn);
+        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $partition_dn);
         if($_SESSION['faifilter']['branch'] == "main"){
           $use_dn = $disk_dn;
         }
@@ -478,6 +511,24 @@ class faiPartitionTable extends plugin
     }
     $this->handle_post_events("add");
   }
+
+
+  /* Return plugin informations for acl handling */ 
+  function plInfo()
+  {
+    return (array( 
+          "plShortName" => _("Partition table"),
+          "plDescription" => _("FAI partition table"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 26,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name")." ("._("Read only").")",
+            "description"       => _("Description"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: