Code

Updated mailGroup handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Dec 2008 12:29:01 +0000 (12:29 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Dec 2008 12:29:01 +0000 (12:29 +0000)
-Add and remove acls if user is removed or mail account is created.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13203 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/mail/personal/mail/class_mail-methods.inc
gosa-plugins/mail/personal/mail/class_mailAccount.inc

index 7490d8c3fc2fdefcbc142d8f76f931d10554bdbc..b22c042683cb4041fa0b6949cb5f98cbd2fe3e92 100644 (file)
@@ -44,7 +44,6 @@ class mailMethod{
   protected $parent             = NULL;   
   protected $MailServer         = "";
 
-
   protected $acl_map = array(
       "lrsw"     => "read",
       "lrswp"    => "post",
index ccad100f2d001db248428ab9266ff98710a8c131..d5b87ef2e9c3b370544a1e09cc4c8c86e754d48d 100644 (file)
@@ -194,6 +194,7 @@ class mailAccount extends plugin
 
   function execute()
   {
+
     /* Call parent execute */
     $display = plugin::execute();
 
@@ -841,6 +842,25 @@ class mailAccount extends plugin
       $this->mail = $this->mail."@".$this->mailDomainPart;
     }
 
+    /* Update sharedFolder dependencies. 
+       Open each shared folder and remove this account. 
+       Then Save the group to ensure that all necessary 
+        actions will be taken (imap acls updated aso.).
+     */
+    $ldap = $this->config->get_ldap_link();    
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
+    while($attrs = $ldap->fetch()){
+      $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
+      if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
+        $grp->by_object['group']->removeUser($this->uid);
+
+        /* Do not save the complete group! This will quit the complete membership 
+         */
+        $grp->by_object['mailgroup']->save();
+      } 
+    }
+
     /* Remove GOsa attributes */
     plugin::remove_from_parent();
 
@@ -876,10 +896,6 @@ class mailAccount extends plugin
           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox! Error was: %s."), 
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
-        if(!$this->mailMethod->updateSharedFolder()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions! Error was: %s."), 
-                $this->mailMethod->get_error()), ERROR_DIALOG);
-        }
       }
     }
     $this->mailMethod->disconnect();
@@ -929,8 +945,6 @@ class mailAccount extends plugin
     $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs);
-  
-
 
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
@@ -961,7 +975,6 @@ class mailAccount extends plugin
 
         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
 
-
           /* Do not write sieve settings if this account is new and 
              doesn't seem to exist.
            */
@@ -974,20 +987,32 @@ class mailAccount extends plugin
             }
           }
         }else{
-      
          echo "Check sieve management here";
-
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
               "User uses an own sieve script, skipping sieve update.".$str."</b>","");
         }
+      }
+    }
+    $this->mailMethod->disconnect();
 
-        if(!$this->mailMethod->updateSharedFolder()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions! Error was: %s."), 
-                $this->mailMethod->get_error()), ERROR_DIALOG);
+    /* Update sharedFolder dependencies.
+       Open each shared folder and remove this account.
+       Then Save the group to ensure that all necessary
+       actions will be taken (imap acls updated aso.).
+     */
+    if(!$this->initially_was_account){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
+      while($attrs = $ldap->fetch()){
+        $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
+        if(isset($grp->by_object['mailgroup'])){
+          /* Do not save the complete group! This will quit the complete membership
+           */
+          $grp->by_object['mailgroup']->save();
         }
       }
     }
-    $this->mailMethod->disconnect();
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){