From 1df484ade1d24e73f249aca373c179998ff32114 Mon Sep 17 00:00:00 2001 From: psc Date: Mon, 12 Oct 2009 09:15:20 +0000 Subject: [PATCH] Update for Trac Ticket #3181 - 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 --- .../admin/ogroups/class_ogroupManagement.inc | 23 +---------- .../goto/events/class_DaemonEvent_notify.inc | 40 +++++++++++++++++++ .../events/class_EventTargetAddUsersList.inc | 13 +++++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/trunk/gosa-core/plugins/admin/ogroups/class_ogroupManagement.inc b/trunk/gosa-core/plugins/admin/ogroups/class_ogroupManagement.inc index 5e5b985d2..72b51c0a1 100644 --- a/trunk/gosa-core/plugins/admin/ogroups/class_ogroupManagement.inc +++ b/trunk/gosa-core/plugins/admin/ogroups/class_ogroupManagement.inc @@ -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); diff --git a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent_notify.inc b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent_notify.inc index e2599414b..35f920602 100644 --- a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent_notify.inc +++ b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent_notify.inc @@ -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() { diff --git a/trunk/gosa-plugins/goto/addons/goto/events/class_EventTargetAddUsersList.inc b/trunk/gosa-plugins/goto/addons/goto/events/class_EventTargetAddUsersList.inc index 714b6edde..56df71e0a 100644 --- a/trunk/gosa-plugins/goto/addons/goto/events/class_EventTargetAddUsersList.inc +++ b/trunk/gosa-plugins/goto/addons/goto/events/class_EventTargetAddUsersList.inc @@ -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 = 'U'; }elseif(in_array("posixGroup",$obj['objectClass'])){ $img = 'G'; + }elseif(in_array("gosaGroupOfNames", $obj['objectClass'])){ + $img = 'O'; } $field1 = array("string" => "", @@ -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); -- 2.30.2