Code

Fixed saving of users which are member in a sharedFolder.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 22 Nov 2007 09:35:26 +0000 (09:35 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 22 Nov 2007 09:35:26 +0000 (09:35 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7849 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/groups/class_groupMail.inc
plugins/personal/mail/class_mailAccount.inc

index 46a521a8aa2a6a0e5b3ab7d23ce4c5fc31bfc5f2..952aab3e5f5cd7eb152614c8620e751e052e1894 100644 (file)
@@ -840,21 +840,41 @@ I: Only insider delivery */
     $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
     $this->attrs['gosaSharedFolderTarget']    = "share+".$this->uid;
 
+    /* Only do IMAP actions if we are not a template */
+    if(preg_match("/olab/i",$this->mmethod)){
+      if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
+        if(isset($this->attrs['gosaMailServer'][0])){
+          $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
+        }
+      }
+    }  
+
+    /* Exchange '%member%' pseudo entry */
+    $memberacl= $this->imapacl['%members%'];
+
+    foreach ($this->members as $user){
+      if (!isset($this->imapacl[$user])){
+        $this->imapacl[$user]= $memberacl;
+      }
+    }
     if(preg_match("/olab/i",$this->mmethod)){
+
       /* Save acl's */
       $this->attrs['acl']= array();
       foreach ($this->imapacl as $user => $acl){
-        if ($user == ""){
+        if ($user == "" || preg_match("/%members%/",$user)){
           continue;
         }
         $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
         $mail = $ldap->fetch();
-        if($mail){
-          if(isset($mail['mail'][0])){
-            $this->attrs['acl'][]= $mail['mail'][0]." $acl";
-          }
+        if(isset($mail['mail'][0])){
+          $sacl = $mail['mail'][0]." ".$acl;
         }else{
-          $this->attrs['acl'][]= "$user $acl";
+          $sacl= "$user $acl";
+        }
+        if(!in_array($sacl,$this->attrs['acl'])){
+          $this->attrs['acl'][]= $sacl;
         }
       }
    
@@ -864,63 +884,17 @@ I: Only insider delivery */
         $this->attrs['kolabFolderType'] = array();
       }
     }else{
+
       /* Save acl's */
       $this->attrs['acl']= array();
       foreach ($this->imapacl as $user => $acl){
-        if ($user == ""){
+        if ($user == "" || preg_match("/%members%/",$user)){
           continue;
         }
         $this->attrs['acl'][]= "$user $acl";
       }
     }
 
-    /* Only do IMAP actions if we are not a template */
-    if(preg_match("/olab/i",$this->mmethod)){
-      if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
-        if(isset($this->attrs['gosaMailServer'][0])){
-          $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
-        }
-      }
-    }  
-
-
-    /* Exchange '%member%' pseudo entry */
-    $memberacl= $this->imapacl['%members%'];
-
-    foreach ($this->members as $user){
-      if(preg_match("/olab/i",$this->mmethod)){
-        $ldap->cd($this->config->current['BASE']);
-        $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
-        $at = $ldap->fetch();
-        if(isset($at['mail'][0])){
-          $user = $at['mail'][0];
-        }
-      }
-      if (!isset($this->imapacl[$user])){
-        $this->imapacl[$user]= $memberacl;
-      }
-    }
-    $this->attrs['acl'] = array();
-    
-    
-    foreach($this->imapacl as $user => $acl){
-
-      /* Remove empty user entry, to avoid entry like this im imap 
-       *   "" lrs
-       */
-      if(empty($user)){
-        unset($this->imapacl[$user]);
-      }
-   
-      /* Skip invalid values */
-      if(preg_match("/%members%/",$user) || empty($user)){
-        continue;
-      }
-
-      /* Append ldap acl entries */
-      $this->attrs['acl'][] = $user." ".$acl;
-    }
-
     if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
       $method= new $this->method($this->config);
       $method->fixAttributesOnStore($this);
@@ -1171,6 +1145,17 @@ I: Only insider delivery */
             "acl"                       => _("Permissions"))
           ));
   }
+
+  
+  /* Remove given ACL for given member (uid,mail) ..
+   */
+  function removeUserAcl($index )
+  {
+    if(isset($this->imapacl[$index])){
+      unset($this->imapacl[$index]);
+    }
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index f1a5cd7dca413d37dded0506f0efb31b33f11101..cf0db85918cabde7edeeca1faa07a374f4dc199d 100644 (file)
@@ -696,6 +696,9 @@ class mailAccount extends plugin
       }
     }
 
+    /* Update shared folder membership, ACL may need to be updated */
+    $this->updateSharedFolder(); 
+
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove",array("uid" => $this->uid));
   }
@@ -884,6 +887,7 @@ class mailAccount extends plugin
       $this->handle_post_events("add", array("uid" => $this->uid));
     }
 
+    $this->updateSharedFolder();
   }
 
 
@@ -1168,6 +1172,28 @@ class mailAccount extends plugin
             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
         ));
   }
+
+  /* Upated shared folder ACLs 
+   */
+  function updateSharedFolder()
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array('dn','cn'));
+    if(class_exists("grouptabs")){
+      while($attrs = $ldap->fetch()){
+        $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
+        if(isset($tmp->by_object['mailgroup'])){
+          $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
+          if(!$this->is_account){
+            $tmp->by_object['mailgroup']->removeUserAcl($this->uid);
+            $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
+          }
+          $tmp->by_object['mailgroup']->save();
+        }
+      }
+    } 
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: