diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema index da9453bad3c0a1cc1ae722f28fd9c10f1d793793..a90e631490b91308ce5ac679bd67cf49304cf09a 100644 --- a/contrib/openldap/core-fd.schema +++ b/contrib/openldap/core-fd.schema @@ -372,6 +372,26 @@ attributetype ( 1.3.6.1.4.1.38414.62.1.50 NAME 'fdPluginManagerSupportContractUr SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) +##### Tasks Granular Part 2 ##### + +attributetype ( 1.3.6.1.4.1.38414.62.1.52 NAME 'fdTasksRepeatable' + DESC 'Allow a given task to be repeatable' + EQUALITY booleanMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX '1.3.6.1.4.1.1466.115.121.1.7') + +attributetype ( 1.3.6.1.4.1.38414.62.1.53 NAME 'fdTasksUpdatable' + DESC 'Allow a given task to be updatable' + EQUALITY booleanMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX '1.3.6.1.4.1.1466.115.121.1.7') + +attributetype ( 1.3.6.1.4.1.38414.62.1.54 NAME 'fdTasksRepeatableSchedule' + DESC 'Set the repetition of the tasks via a set attribute' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX '1.3.6.1.4.1.1466.115.121.1.15') + ##### Classes ##### ### old gosa ObjectClass ### @@ -441,7 +461,7 @@ objectclass ( 1.3.6.1.4.1.38414.62.2.5 NAME 'fdMailTemplateConf' objectclass (1.3.6.1.4.1.38414.62.2.6 NAME 'fdTasks' DESC 'FusionDirectory - Tasks objects' MUST ( cn $ fdTasksStatus $ fdTasksCreationDate ) - MAY ( fdTasksScheduleDate $ fdTasksEndDate) ) + MAY ( fdTasksScheduleDate $ fdTasksEndDate $ fdTasksRepeatableSchedule $ fdTasksUpdatable $ fdTasksRepeatable ) ) objectclass (1.3.6.1.4.1.38414.62.2.7 NAME 'fdTasksMail' DESC 'FusionDirectory - Tasks objects Mail' diff --git a/plugins/configuration/tasks/class_tasks.inc b/plugins/configuration/tasks/class_tasks.inc index 53ffe01da9d28b7676a73785954fa33972e63602..78e2c8553a06d503a52be74aba9af6e27284dc12 100644 --- a/plugins/configuration/tasks/class_tasks.inc +++ b/plugins/configuration/tasks/class_tasks.inc @@ -45,7 +45,7 @@ class tasks extends simplePlugin return [ // Attributes are grouped by section 'tasks' => [ - 'name' => _('Tasks Generic | Saving will create un-modifiable subtasks'), + 'name' => _('Tasks Generic'), 'attrs' => [ new StringAttribute( _('Task Name'), _('Name for this task'), @@ -69,6 +69,23 @@ class tasks extends simplePlugin ), ] ], + 'taskSetting' => [ + 'name' => _('Advanced settings'), + 'attrs' => [ + new BooleanAttribute( + _('Only with new members'), _('Allows creation of sub-tasks for "NEW MEMBERS" only. (Case of Dynamic Group)'), + 'fdTasksUpdatable', FALSE, TRUE + ), + new BooleanAttribute( + _('Repeatable Task'), _('Set the task to be repeatable.'), + 'fdTasksRepeatable', FALSE + ), + new SelectAttribute( + _('Repeatable Schedule'), _('Select the desired schedule.'), + 'fdTasksRepeatableSchedule', FALSE, ['Yearly', 'Monthly', 'Daily', 'Hourly'], 'Daily' + ), + ] + ], ]; } @@ -78,6 +95,16 @@ class tasks extends simplePlugin global $config; parent::__construct($dn, $object, $parent, $mainTab); + $this->attributesAccess['fdTasksRepeatable']->setManagedAttributes( + [ + 'disable' => [ + FALSE => [ + 'fdTasksRepeatableSchedule', + ] + ] + ] + ); + $this->attributesAccess['fdSubTasksActivation']->setInLdap(FALSE); } diff --git a/plugins/configuration/tasks/class_tasksMail.inc b/plugins/configuration/tasks/class_tasksMail.inc index a0bc997d33e26754157eb4b5c2db410d769f8037..cb87811186390bc913f39653713f68e4aa36a61c 100644 --- a/plugins/configuration/tasks/class_tasksMail.inc +++ b/plugins/configuration/tasks/class_tasksMail.inc @@ -26,18 +26,18 @@ class tasksMail extends simplePlugin static function plInfo (): array { return [ - 'plShortName' => _('Tasks Mail'), + 'plShortName' => _('Tasks Mail'), 'plDescription' => _('Tasks Mail Object'), - 'plIcon' => 'geticon.php?context=applications&icon=tasks&size=16', - 'plPriority' => 42, + 'plIcon' => 'geticon.php?context=applications&icon=tasks&size=16', + 'plPriority' => 42, 'plObjectClass' => ['fdTasksMail'], - 'plFilter' => '(objectClass=fdTasksMail)', - 'plObjectType' => ['tasks'], - 'plConflicts' => [''], - 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()), - 'plForeignKeys' => [ + 'plFilter' => '(objectClass=fdTasksMail)', + 'plObjectType' => ['tasks'], + 'plConflicts' => [''], + 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()), + 'plForeignKeys' => [ 'fdTasksMailUsers' => [ - ['user','dn','fdTasksMailUsers=%oldvalue%','*'] + ['user', 'dn', 'fdTasksMailUsers=%oldvalue%', '*'] ] ], ]; @@ -48,7 +48,7 @@ class tasksMail extends simplePlugin return [ // Attributes are grouped by section 'taskMail' => [ - 'name' => _('Task Mail Object'), + 'name' => _('Task Mail Object'), 'attrs' => [ new SelectAttribute( _('Mail Template'), _('Mail Template Object Selection'), @@ -58,15 +58,15 @@ class tasksMail extends simplePlugin ] ], 'From Component' => [ - 'name' => _('Sender email address'), + 'name' => _('Sender email address'), 'attrs' => [ - new MailAttribute( - _('Sender email address'), - _('Email address from which mails will be sent'), 'fdTasksEmailSender', TRUE, 'to.be@chang.ed'), + new MailAttribute( + _('Sender email address'), + _('Email address from which mails will be sent'), 'fdTasksEmailSender', TRUE, 'to.be@chang.ed'), ] ], 'UserGroupSelection' => [ - 'name' => _('Recipients Users and/or Groups'), + 'name' => _('Recipients Users and/or Groups'), 'attrs' => [ new UsersGroupsRolesAttribute( _('Members'), _('Users or groups to assign to this task.'), @@ -75,7 +75,7 @@ class tasksMail extends simplePlugin ], ], 'tasksMailType' => [ - 'name' => _('Type of e-mail address desired'), + 'name' => _('Type of e-mail address desired'), 'attrs' => [ new SelectAttribute( _('Mail Type - If not found, priority will apply'), _('Mail Type Object Selection'), @@ -103,12 +103,12 @@ class tasksMail extends simplePlugin $this->attributesAccess['fdTasksMailObject']->setChoices(array_keys($tmpSearch), array_values($tmpSearch)); $mailAttrTypes = [ - 'mail' => 'mail - [gosaMailAccount primary]', - 'gosaMailAlternateAddress' => 'gosaMailAlternateAddress', + 'mail' => 'mail - [gosaMailAccount primary]', + 'gosaMailAlternateAddress' => 'gosaMailAlternateAddress', 'gosaMailForwardingAddress' => 'gosaMailForwardingAddress', - 'supannAutreMail' => 'supannAutreMail', - 'supannMailPerso' => 'supannMailPerso', - 'supannMailPrive' => 'supannMailPrive' + 'supannAutreMail' => 'supannAutreMail', + 'supannMailPerso' => 'supannMailPerso', + 'supannMailPrive' => 'supannMailPrive' ]; $this->attributesAccess['fdTasksMailType']->setChoices(array_keys($mailAttrTypes), array_values($mailAttrTypes)); @@ -124,7 +124,7 @@ class tasksMail extends simplePlugin parent::update(); // get the value of type mail desired and if null set default - $mailAttr = $this->attributesAccess['fdTasksMailType']->getValue(); + $mailAttr = $this->attributesAccess['fdTasksMailType']->getValue(); if (empty($mailAttr)) { $mailAttr = 'mail'; } @@ -141,7 +141,7 @@ class tasksMail extends simplePlugin /* * Return the objectype searched for by setEmailFromSelectedDN */ - public function getMailObject (string $mailAttr) : string + public function getMailObject (string $mailAttr): string { switch ($mailAttr) { case 'mail' : @@ -159,10 +159,10 @@ class tasksMail extends simplePlugin } } - /* - * Populate the fdTasksEmailsFromDN attribute with related mails addresses. - */ - public function setEmailsFromSelectedDN ($mailObject, $mailAttr) : void + /* + * Populate the fdTasksEmailsFromDN attribute with related mails addresses. + */ + public function setEmailsFromSelectedDN ($mailObject, $mailAttr): void { global $config; @@ -241,50 +241,82 @@ class tasksMail extends simplePlugin */ public function generateSlaveTasks () { + global $config; + $ldap = $config->get_ldap_link(); + $emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue(); // Ref is supposed to be the mail object CN in this class - $ref = $this->attributesAccess['fdTasksMailObject']->getValue(); + $ref = $this->attributesAccess['fdTasksMailObject']->getValue(); $from = $this->attributesAccess['fdTasksEmailSender']->getValue(); - // Incremental id allowing creation of different CN for sub-tasks - $id = 0; // Take the attribute from the other tabs - attribute cannot be null or unset by default $schedule = $this->parent->getBaseObject()->fdTasksScheduleDate ?? NULL; + // Verify if members can have multiple sub-tasks for that main task. + $newMemberOnly = $this->parent->getBaseObject()->fdTasksUpdatable; + + // remove 'dn' keeping only 'cn' + $rmDn = preg_replace('/(?=,).*/', '', $this->dn); + // only take the cn without dc + preg_match('/cn=(.*)/', $rmDn, $matches); + if (!empty($emails)) { - foreach ($emails as $email) { - // Using ID incrementation in order to have sub-tasks CN with different name. - // Enhancement possible is to use dateTime instead. - $id ++; + // Condition allowing the creation of subtasks for existing members + if ($newMemberOnly === TRUE) { + $ldap->cd($config->current['BASE']); + $filter = '(&(objectClass=fdTasksGranular)(fdTasksGranularMaster='.$this->dn.'))'; + + $attrs = ['fdTasksGranularMail']; + $ldap->search($filter, $attrs); + // The while loop is important to get all info from ldap into the array. + while ($info = $ldap->fetch()) { + $subTasks[] = $info; + } + + if (!empty($subTasks)) { + // Recuperate members email from the ldap search. + foreach ($subTasks as $subTask) { + $membersEmailsList[] = $subTask['fdTasksGranularMail'][0]; + } + // Verify the emails differences and only keep those. + if (!empty($membersEmailsList)) { + $emails = array_diff($emails, $membersEmailsList); + } + // Simple re-index the array. + $emails = array_values($emails); + } + } + + foreach ($emails as $email) { // Here we create the object taskGranular $tabObject = objects::create('TasksGranular'); - // remove 'dn' keeping only 'cn' - $rmDn = preg_replace('/(?=,).*/', '', $this->dn); - - // only take the cn without dc - preg_match('/cn=(.*)/', $rmDn, $matches); + // Create a unique ID based on timestamp (Allowing duplicate subtasks for same members in case of repeat). + $timestamp = microtime(TRUE); // Get the current timestamp with microseconds + $timestamp = (string)$timestamp; // Convert the float to a string, str_replace expect array or string. + $uniqueID = str_replace(".", "_", $timestamp); // Remove . with _ for correct CN - $subTaskName = $matches[1].'-SubTask-'.$id; + // Array matches come from preg_match function above with rmDn + $subTaskName = $matches[1] . '-SubTask-' . $uniqueID; $values['tasksGranular'] = [ - "cn" => $subTaskName, - "fdTasksGranularType" => 'Mail Object', - "fdTasksGranularMaster" => $this->dn, - "fdTasksGranularMail" => $email, + "cn" => $subTaskName, + "fdTasksGranularType" => 'Mail Object', + "fdTasksGranularMaster" => $this->dn, + "fdTasksGranularMail" => $email, "fdTasksGranularSchedule" => $schedule, - "fdTasksGranularRef" => $ref, + "fdTasksGranularRef" => $ref, "fdTasksGranularMailFrom" => $from ]; foreach ($values as $tab => $tabvalues) { if (!isset($tabObject->by_object[$tab])) { - echo "Error tab does not contains attributes values" .PHP_EOL; + echo "Error tab does not contains attributes values" . PHP_EOL; } $error = $tabObject->by_object[$tab]->deserializeValues($tabvalues); if ($error !== TRUE) { - echo 'Error during deserializing' .$error .PHP_EOL; + echo 'Error during deserializing' . $error . PHP_EOL; } $tabObject->current = $tab; diff --git a/plugins/configuration/tasks/class_tasksManagement.inc b/plugins/configuration/tasks/class_tasksManagement.inc index 821b34bcb4c62e9c018a3a16f66dffefa644182e..db8ab17c78593df0475baf1f0ccfd039cb9adf14 100644 --- a/plugins/configuration/tasks/class_tasksManagement.inc +++ b/plugins/configuration/tasks/class_tasksManagement.inc @@ -24,11 +24,10 @@ class tasksManagement extends management protected $skipCpHandler = TRUE; /* - * LinkColumn exists by class collumn - * TasksColumn is a new class for Tasks bassed on argonaut column definition + * LinkColumn exists by class column + * TasksColumn is a new class for Tasks based on argonaut column definition */ public static $columns = [ - ['LinkColumn', ['attributes' => 'cn', 'label' => 'Tasks']], //below fdTasksMailObject must be change to have a type defined within task creation (new ldap attributes ?hidden) ['TasksColumn', ['attributes' => 'fdTasksMailObject', 'label' => 'Types']], ['Column', ['attributes' => 'fdTasksCreationDate', 'label' => 'Creation Date']],