diff --git a/plugins/configuration/tasks/class_tasks.inc b/plugins/configuration/tasks/class_tasks.inc index eecd250c45ece57b5a971fc559f90cf6345c8222..c90dc1b602bd835364b3e84c266a353082c43c5c 100644 --- a/plugins/configuration/tasks/class_tasks.inc +++ b/plugins/configuration/tasks/class_tasks.inc @@ -26,15 +26,15 @@ class tasks extends simplePlugin static function plInfo (): array { return [ - 'plShortName' => _('Tasks'), - 'plDescription' => _('Tasks'), - 'plObjectClass' => ['fdTasks'], - 'plFilter' => '(objectClass=fdTasks)', - 'plPriority' => 41, - 'plObjectType' => ['tasks' => [ - 'name' => _('Tasks'), - 'ou' => get_ou('tasksRDN'), - 'icon' => 'geticon.php?context=applications&icon=tasks&size=16', + 'plShortName' => _('Tasks'), + 'plDescription' => _('Tasks'), + 'plObjectClass' => ['fdTasks'], + 'plFilter' => '(objectClass=fdTasks)', + 'plPriority' => 41, + 'plObjectType' => ['tasks' => [ + 'name' => _('Tasks'), + 'ou' => get_ou('tasksRDN'), + 'icon' => 'geticon.php?context=applications&icon=tasks&size=16', ]], 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()) ]; @@ -44,25 +44,25 @@ class tasks extends simplePlugin { return [ // Attributes are grouped by section - 'tasks' => [ + 'tasks' => [ 'name' => _('Tasks Generic'), 'attrs' => [ - new StringAttribute( - _('Task Name'), _('Name for this task'), - 'cn', TRUE - ), - new DateTimeAttribute( - _('Schedule'), '', - 'fdTasksScheduleDate', FALSE - ), - - new HiddenAttribute('fdTasksStatus', TRUE, '1', '', 'Status', 'Status of the task'), - new HiddenAttribute('fdTasksLastExec', FALSE, '', '', 'LastExec', 'Last exec date'), - new HiddenAttribute('fdTasksCreationDate', TRUE, date("Y-m-d h:i:sa"), '', 'StartDate', 'Start Date And Time Of A Task'), + new StringAttribute( + _('Task Name'), _('Name for this task'), + 'cn', TRUE + ), + new DateTimeAttribute( + _('Schedule'), '', + 'fdTasksScheduleDate', FALSE + ), + + new HiddenAttribute('fdTasksStatus', TRUE, '1', '', 'Status', 'Status of the task'), + new HiddenAttribute('fdTasksLastExec', FALSE, '', '', 'LastExec', 'Last exec date'), + new HiddenAttribute('fdTasksCreationDate', TRUE, date("Y-m-d h:i:sa"), '', 'StartDate', 'Start Date And Time Of A Task'), ] ], - 'subTasks' => [ - 'name' => _('Creation of Sub Tasks - Starting this task'), + 'subTasks' => [ + 'name' => _('Creation of Sub Tasks - Starting this task'), 'attrs' => [ new BooleanAttribute( _('Activate SubTasks'), _('Trigger the creation of this task and related subtasks'), @@ -71,7 +71,7 @@ class tasks extends simplePlugin ] ], 'taskSetting' => [ - 'name' => _('Advanced settings'), + 'name' => _('Advanced settings'), 'attrs' => [ new BooleanAttribute( _('Only with new members'), _('Allows creation of sub-tasks for "NEW MEMBERS" only. (Case of Dynamic Group)'), @@ -113,9 +113,58 @@ class tasks extends simplePlugin { // Verification if the bool of activation is ticked and activate the last exec accordingly. if ($this->fdSubTasksActivation == TRUE) { - $currentDateTime = date("Y-m-d h:i:sa", time()); + $currentDateTime = date("Y-m-d h:i:sa", time()); $this->fdTasksLastExec = $currentDateTime; } return parent::save(); } + + /** + * @param array $groups + * @return array + */ + public static function extractMembersFromGroups (array $groups): array + { + global $config; + + $ldap = $config->get_ldap_link(); + $listMemberDN = []; + + if (!empty($groups)) { + // Verify if the values received is a member or a group and collect the members DN + foreach ($groups as $group) { + if (strpos($group, "ou=groups") !== FALSE) { + + // Position ldap to the dn required (limit search). + $ldap->cd($group); + $filter = '(|(objectClass=groupOfUrls)(objectClass=groupOfNames))'; + $attrs = ['member']; + + $ldap->search($filter, $attrs); + $info = $ldap->fetch(); + + // Verify if the group is not empty of members + if (!empty($info['member'])) { + //unset the count from the array + unset($info['member']['count']); + foreach ($info['member'] as $memberDN) { + $listMemberDN[] = $memberDN; + } + + // Add the member DN to the list of DN + $listMemberDN = array_unique($listMemberDN); + } + } + } + + // Iterate on the DN list to remove any members representing a group (members of that potential groups were extracted). + foreach ($listMemberDN as $key => $value) { + if (strpos($value, 'ou=groups') !== FALSE) { + unset($listMemberDN[$key]); + } + } + } + return $listMemberDN; + } + } diff --git a/plugins/configuration/tasks/class_tasksLifeCycle.inc b/plugins/configuration/tasks/class_tasksLifeCycle.inc index 1a6064f1955a7c3a6944f2837616db04af92d8cd..3915926b2f0b45ed353a40a6230d82cb3e83e0fe 100644 --- a/plugins/configuration/tasks/class_tasksLifeCycle.inc +++ b/plugins/configuration/tasks/class_tasksLifeCycle.inc @@ -173,43 +173,13 @@ class tasksLifeCycle extends simplePlugin */ public function getListOfDN (): void { - global $config; - $ldap = $config->get_ldap_link(); - // Get the members or groups selected $membersAndGroups = $this->attributesAccess['fdTasksLifeCycleMembers']->getValue(); - - if (!empty($membersAndGroups)) { - - // Verify if the values received is a member or a group and collect the members DN - foreach ($membersAndGroups as $group) { - if (strpos($group, "ou=groups") !== FALSE) { - - // Position ldap to the dn required (limit search). - $ldap->cd($group); - $filter = '(|(objectClass=groupOfUrls)(objectClass=groupOfNames))'; - $attrs = ['member']; - $ldap->search($filter, $attrs); - $info = $ldap->fetch(); - - // Remove the DN of the group from the list of DN - unset($membersAndGroups[$group]); - - // Add the member DN to the list of DN - // Verify if the group is not empty of members - if (!empty($info['member'])) { - foreach ($info['member'] as $memberDN) { - $membersAndGroups[] = $memberDN; - } - $membersAndGroups = array_unique($membersAndGroups); - } - } - } - - $this->attributesAccess['fdTasksLifeCycleListOfDN']->setValue(array_values($membersAndGroups)); - } + // Call static function from tasks object, always return an array. + $this->attributesAccess['fdTasksLifeCycleListOfDN']->setValue(array_values(tasks::extractMembersFromGroups($membersAndGroups))); } + /** * Generate slave tasks, careful that main task cannot be changed cause subtasks are not updated. * It would be dangerous to edit subs tasks if some are under processed already. diff --git a/plugins/configuration/tasks/class_tasksMail.inc b/plugins/configuration/tasks/class_tasksMail.inc index aab830e8077f322740613a27be82c0fca091fc52..5da8ec361d57e1df765e50ae7446696a7dc7f97f 100644 --- a/plugins/configuration/tasks/class_tasksMail.inc +++ b/plugins/configuration/tasks/class_tasksMail.inc @@ -168,67 +168,35 @@ class tasksMail extends simplePlugin public function setEmailsFromSelectedDN ($mailObject, $mailAttr): void { global $config; - - $ldap = $config->get_ldap_link(); + $ldap = $config->get_ldap_link(); + $mailList = []; // Get the members or groups selected $attributeValue = $this->attributesAccess['fdTasksMailUsers']->getValue(); + // Extract members from potential groups and dyn-groups. + $listOfDN = tasks::extractMembersFromGroups($attributeValue); - if (!empty($attributeValue)) { - - // listOfDN will contain only DN of members after below methods condition - $listOfDN = $attributeValue; - - // Verify if the values received is a member or a group and collect the members DN - foreach ($attributeValue as $group) { - if (strpos($group, "ou=groups") !== FALSE) { + foreach ($listOfDN as $dn) { + // Position ldap to the dn required (limit search). + $ldap->cd($dn); - // Position ldap to the dn required (limit search). - $ldap->cd($group); + // filter and attributes should be equals to the arguments passed to this method + $filter = "(objectClass=$mailObject)"; + $attrs = [$mailAttr]; - $filter = '(|(objectClass=groupOfUrls)(objectClass=groupOfNames))'; - $attrs = ['member']; - $ldap->search($filter, $attrs); - $info = $ldap->fetch(); + $ldap->search($filter, $attrs); + $info = $ldap->fetch(); - // Remove the DN of the group from the list of DN - unset($listOfDN[$group]); - - // Verify if the group is not empty of members - if (!empty($info['member'])) { - // Add the member DN to the list of DN - foreach ($info['member'] as $memberDN) { - $listOfDN[] = $memberDN; - } - $listOfDN = array_unique($listOfDN); - } - } - } + if (!empty($info[$mailAttr][0])) { + // In case of private supann mail, remove the prefix + $mailList[] = preg_replace('/.+?(?=supann)/', '', $info[$mailAttr][0]); - $mailList = []; - foreach ($listOfDN as $dn) { - - // Position ldap to the dn required (limit search). - $ldap->cd($dn); - - // filter and attributes should be equals to the arguments passed to this method - $filter = "(objectClass=$mailObject)"; - $attrs = [$mailAttr]; - - $ldap->search($filter, $attrs); - $info = $ldap->fetch(); - - if (!empty($info[$mailAttr][0])) { - // In case of private supann mail, remove the prefix - $mailList[] = preg_replace('/.+?(?=supann)/', '', $info[$mailAttr][0]); - - // Render the mailing list unique, somewhat mandatory when updating the members lists with dynGroups and members. - $mailList = array_unique($mailList); - // A possible enhancement is to recall itself with another mailObject / attr - } + // Render the mailing list unique, somewhat mandatory when updating the members lists with dynGroups and members. + $mailList = array_unique($mailList); + // A possible enhancement is to recall itself with another mailObject / attr } - $this->attributesAccess['fdTasksEmailsFromDN']->setValue(array_values($mailList)); } + $this->attributesAccess['fdTasksEmailsFromDN']->setValue(array_values($mailList)); } function save (): array