Code

Update for Trac Ticket #3181
authorpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 12 Oct 2009 09:15:20 +0000 (09:15 +0000)
committerpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 12 Oct 2009 09:15:20 +0000 (09:15 +0000)
- Move ogroup resolving logic to a new function in
  class_DaemonEvent_notify.inc
- Use new function in add_targets to resolve object groups
- Make it possible to add object group targets when using the
  'Add target' function while sending a message.

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@14579 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-core/plugins/admin/ogroups/class_ogroupManagement.inc
trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent_notify.inc
trunk/gosa-plugins/goto/addons/goto/events/class_EventTargetAddUsersList.inc

index 5e5b985d2543704226d17410b346c1d0b597c864..72b51c0a145f36c6f3330b198d2ff2a6a7ff9b0b 100644 (file)
@@ -151,28 +151,7 @@ class ogroupManagement extends plugin
       $targets = array();
       foreach($ids as $id){
         $ogroup = $this->ogrouplist[$id]['cn'][0];
-        $ldap = $this->config->get_ldap_link();
-        $ldap->search("(&(cn=".$ogroup.")(member=*))", array('member'));
-
-        while ($entry = $ldap->fetch()) {
-          $members = $entry['member'];
-          for($i=0;$i<$members['count'];$i++) {
-            $ldap->cat($members[$i], array('uid','cn','objectClass'));
-            if ($ldap->count() > 0) {
-              $attrs = $ldap->fetch();
-
-              /* Determine which type the object has */
-              if (array_search('gosaAccount', $attrs['objectClass'])) {
-                $uid = $attrs['uid'][0];
-                $targets['USERS'][] = $uid;
-              }
-              elseif (array_search('posixGroup', $attrs['objectClass'])) {
-                $group = $attrs['cn'][0];
-                $targets['GROUPS'][] = $group;
-              }
-            }
-          }
-        }
+        $targets['OBJECTGROUPS'][] = $ogroup;
       }
       if(count($targets)){
         $events = DaemonEvent::get_event_types(USER_EVENT);
index e2599414b2f862d6741603323a87eb4e6fd3b159..35f92060206918782ecdbbd88cdf9e01179a4c38 100644 (file)
@@ -187,6 +187,11 @@ class DaemonEvent_notify extends DaemonEvent
    */
   public function add_targets($targets)
   {
+    if(isset($targets['OBJECTGROUPS'])){
+      $ogroup_targets = $this->resolve_objectgroups($targets['OBJECTGROUPS']);
+      $targets = array_merge_recursive($targets, $ogroup_targets);
+    }
+
     if(isset($targets['USERS'])){
       $this->add_users($targets['USERS']);
     }
@@ -195,6 +200,41 @@ class DaemonEvent_notify extends DaemonEvent
     }
   }
 
+  /*! \brief Resolve an object group to the contained users and groups
+      @param Array A list of all object groups
+   */
+  public function resolve_objectgroups($targets)
+  {
+    $result = array();
+
+    foreach($targets as $ogroup) {
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd(get_groups_ou().$this->config->current['BASE']);
+      $ldap->search("(&(cn=".$ogroup.")(member=*))", array('member'));
+      while ($entry = $ldap->fetch()) {
+        $members = $entry['member'];
+          for($i=0;$i<$members['count'];$i++) {
+            $ldap->cat($members[$i], array('uid','cn','objectClass'));
+            if ($ldap->count() > 0) {
+              $attrs = $ldap->fetch();
+              /* Determine which type the object has */
+              if (array_search('gosaAccount', $attrs['objectClass'])) {
+                $uid = $attrs['uid'][0];
+                $result['USERS'][] = $uid;
+              }
+              elseif (array_search('posixGroup', $attrs['objectClass'])) {
+                $group = $attrs['cn'][0];
+                $result['GROUPS'][] = $group;
+              }
+            }
+          }
+       }
+    }
+    return $result;
+  }
+
+
+
 
   public function save()
   {
index 714b6edde058857b3af0f512a37d1828f9b3f0c2..56df71e0aa2764b94067aef9dad9a1f34c19945f 100644 (file)
@@ -64,6 +64,7 @@ class EventTargetAddUserList extends MultiSelectWindow
 
     $this->AddCheckBox("display_users"  ,"1", _("Display users"),TRUE);
     $this->AddCheckBox("display_groups" ,"1", _("Display groups"),TRUE);
+    $this->AddCheckBox("display_objectgroups" ,"1", _("Display object groups"),TRUE);
   }
 
 
@@ -150,6 +151,11 @@ class EventTargetAddUserList extends MultiSelectWindow
           get_sub_list("(objectClass=posixGroup)","groups",get_groups_ou(),get_groups_ou().$this->selectedBase,
             array("cn","objectClass","description"),GL_NONE));
     }
+    if($this->display_objectgroups){
+      $_target_list = array_merge($_target_list,
+          get_sub_list("(|(gosaGroupObjects=*G*)(gosaGroupObjects=*U*))","groups",get_groups_ou(),get_groups_ou().$this->selectedBase,
+            array("cn", "objectClass", "description"),GL_NONE));
+    }
     $this->_target_list = $_target_list;
 
     $tmp = array();
@@ -171,6 +177,8 @@ class EventTargetAddUserList extends MultiSelectWindow
         $img = '<img class="center" src="plugins/users/images/select_user.png" alt="U" title="'._("User").'">';
       }elseif(in_array("posixGroup",$obj['objectClass'])){
         $img = '<img class="center" src="plugins/groups/images/groups.png" alt="G" title="'._("Group").'">';
+      }elseif(in_array("gosaGroupOfNames", $obj['objectClass'])){
+        $img = '<img class="center" src="plugins/ogroups/images/ogroup.png" alt="O" title="'._("Object group").'">';
       }
 
       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>",
@@ -185,7 +193,7 @@ class EventTargetAddUserList extends MultiSelectWindow
 
   function get_selected_targets()
   {
-    $a_targets = array("USERS" => array(),"GROUPS" => array());
+    $a_targets = array("USERS" => array(),"GROUPS" => array(), "OBJECTGROUPS" => array());
 
     foreach($this->list_get_selected_items() as $id){
       $obj = $this->_target_list[$id];
@@ -195,6 +203,9 @@ class EventTargetAddUserList extends MultiSelectWindow
       if(in_array("gosaAccount",$obj['objectClass'])){
         $a_targets['USERS'][] = $obj['uid'][0];
       }
+      if(in_array("gosaGroupOfNames", $obj['objectClass'])){
+        $a_targets['OBJECTGROUPS'][] = $obj['cn'][0];
+      }
     }
 
     return($a_targets);