Code

Updated application acls
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationManagement.inc
index 109847bd36e1047dd48cbe9841ed10c8c8b0dbb0..b2a9cd44340de905b79c5de595ce65ce067154b6 100644 (file)
@@ -36,6 +36,8 @@ class applicationManagement extends plugin
   var $app_base     ="";
   var $app_release  ="";
 
+  var $dns = array();
+
   function IsReleaseManagementActivated()
   {
     /* Check if we should enable the release selection */
@@ -127,7 +129,7 @@ class applicationManagement extends plugin
 
     /* These vars will be stored if you try to open a locked app, 
         to be able to perform your last requests after showing a warning message */
-    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/"));
+    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/","/^menu_action/"));
 
     $smarty       = get_smarty();             // Smarty instance
     $s_action     = "";                       // Contains the action to proceed
@@ -228,8 +230,7 @@ class applicationManagement extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
-      del_lock ($this->apptabs->dn);
-      unset ($this->apptabs);
+      $this->remove_lock();
       $this->apptabs= NULL;
       session::un_set('objectinfo');
     }
@@ -259,9 +260,8 @@ class applicationManagement extends plugin
           /* Application has been saved successfully, remove lock from
              LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
-          unset ($this->apptabs);
           $this->apptabs= NULL;
           session::un_set('objectinfo');
         }else{
@@ -316,25 +316,40 @@ class applicationManagement extends plugin
       $ids = $this->list_get_selected_items();
 
       if(count($ids)){
+        $this->dns = array();
 
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->applications[$id]['dn'];
-          $this->dns[$id] = $dn;
-        }
-        if ($user= get_multiple_locks($this->dns)){
-          return(gen_locked_message($user,$this->dns));
+          $acl = $this->ui->get_permissions($dn, "application/application");
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
+          }
         }
 
-        $dns_names = array();
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names[] =@LDAP::fix($dn);
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        $smarty->assign("intro",  msgPool::deleteInfo($dns_names,_("application")));
-        $smarty->assign("multiple", true);
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        if(count($this->dns)){
+
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
+
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            add_lock ($dn, $this->ui->dn);
+            $dns_names[] =@LDAP::fix($dn);
+          }
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("intro",  msgPool::deleteInfo($dns_names,_("application")));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        }
       }
     }
 
@@ -367,10 +382,11 @@ class applicationManagement extends plugin
           msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
           new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
         }
-        /* Remove lock file after successfull deletion */
-        del_lock ($dn);
-        unset($this->dns[$key]);
       }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -380,10 +396,10 @@ class applicationManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_application_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
     /**************** 
@@ -454,7 +470,7 @@ class applicationManagement extends plugin
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
     }
 
 
@@ -464,7 +480,7 @@ class applicationManagement extends plugin
 
     /* Delete application canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -579,13 +595,20 @@ class applicationManagement extends plugin
       return("");
     }
 
+    $ui = get_userinfo();
+
     /* Add a single entry to queue */
     if($s_action == "cut" || $s_action == "copy"){
 
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
       $dn = $this->applications[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      if($s_action == "copy" && preg_match("/r/",$ui->has_complete_category_acls($dn,"application"))){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      }
+      if($s_action == "cut" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,"application"))){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      }
     }
 
 
@@ -599,10 +622,10 @@ class applicationManagement extends plugin
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->applications[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && preg_match("/r/",$ui->has_complete_category_acls($dn,"application"))){
           $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && preg_match("/(r.*d|d.*r)/",$ui->has_complete_category_acls($dn,"application"))){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
         }
       }
@@ -657,13 +680,21 @@ class applicationManagement extends plugin
     $this->postcreate();
   }
 
+
   function remove_lock()
   {
     if (isset($this->apptabs->dn)){
       del_lock ($this->apptabs->dn);
     }
+    if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+      del_lock($this->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock($this->dns);
+    }
   }
 
+
   function save_object() 
   {
     $this->DivListApplication->save_object();