Commit 2105e38e authored by dockx thibault's avatar dockx thibault
Browse files

Merge branch '6302-core-tasks-tasks-must-be-set-as-repeatable-and-updatable' into 'dev'

Resolve "[CORE][TASKS] - Tasks must be set as repeatable and updatable"

See merge request fusiondirectory/fd!1056
Showing with 130 additions and 52 deletions
+130 -52
...@@ -372,6 +372,26 @@ attributetype ( 1.3.6.1.4.1.38414.62.1.50 NAME 'fdPluginManagerSupportContractUr ...@@ -372,6 +372,26 @@ attributetype ( 1.3.6.1.4.1.38414.62.1.50 NAME 'fdPluginManagerSupportContractUr
SUBSTR caseIgnoreSubstringsMatch SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) 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 ##### ##### Classes #####
### old gosa ObjectClass ### ### old gosa ObjectClass ###
...@@ -441,7 +461,7 @@ objectclass ( 1.3.6.1.4.1.38414.62.2.5 NAME 'fdMailTemplateConf' ...@@ -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' objectclass (1.3.6.1.4.1.38414.62.2.6 NAME 'fdTasks'
DESC 'FusionDirectory - Tasks objects' DESC 'FusionDirectory - Tasks objects'
MUST ( cn $ fdTasksStatus $ fdTasksCreationDate ) 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' objectclass (1.3.6.1.4.1.38414.62.2.7 NAME 'fdTasksMail'
DESC 'FusionDirectory - Tasks objects Mail' DESC 'FusionDirectory - Tasks objects Mail'
......
...@@ -45,7 +45,7 @@ class tasks extends simplePlugin ...@@ -45,7 +45,7 @@ class tasks extends simplePlugin
return [ return [
// Attributes are grouped by section // Attributes are grouped by section
'tasks' => [ 'tasks' => [
'name' => _('Tasks Generic | Saving will create un-modifiable subtasks'), 'name' => _('Tasks Generic'),
'attrs' => [ 'attrs' => [
new StringAttribute( new StringAttribute(
_('Task Name'), _('Name for this task'), _('Task Name'), _('Name for this task'),
...@@ -69,6 +69,23 @@ class tasks extends simplePlugin ...@@ -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 ...@@ -78,6 +95,16 @@ class tasks extends simplePlugin
global $config; global $config;
parent::__construct($dn, $object, $parent, $mainTab); parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['fdTasksRepeatable']->setManagedAttributes(
[
'disable' => [
FALSE => [
'fdTasksRepeatableSchedule',
]
]
]
);
$this->attributesAccess['fdSubTasksActivation']->setInLdap(FALSE); $this->attributesAccess['fdSubTasksActivation']->setInLdap(FALSE);
} }
......
...@@ -26,18 +26,18 @@ class tasksMail extends simplePlugin ...@@ -26,18 +26,18 @@ class tasksMail extends simplePlugin
static function plInfo (): array static function plInfo (): array
{ {
return [ return [
'plShortName' => _('Tasks Mail'), 'plShortName' => _('Tasks Mail'),
'plDescription' => _('Tasks Mail Object'), 'plDescription' => _('Tasks Mail Object'),
'plIcon' => 'geticon.php?context=applications&icon=tasks&size=16', 'plIcon' => 'geticon.php?context=applications&icon=tasks&size=16',
'plPriority' => 42, 'plPriority' => 42,
'plObjectClass' => ['fdTasksMail'], 'plObjectClass' => ['fdTasksMail'],
'plFilter' => '(objectClass=fdTasksMail)', 'plFilter' => '(objectClass=fdTasksMail)',
'plObjectType' => ['tasks'], 'plObjectType' => ['tasks'],
'plConflicts' => [''], 'plConflicts' => [''],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()), 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()),
'plForeignKeys' => [ 'plForeignKeys' => [
'fdTasksMailUsers' => [ 'fdTasksMailUsers' => [
['user','dn','fdTasksMailUsers=%oldvalue%','*'] ['user', 'dn', 'fdTasksMailUsers=%oldvalue%', '*']
] ]
], ],
]; ];
...@@ -48,7 +48,7 @@ class tasksMail extends simplePlugin ...@@ -48,7 +48,7 @@ class tasksMail extends simplePlugin
return [ return [
// Attributes are grouped by section // Attributes are grouped by section
'taskMail' => [ 'taskMail' => [
'name' => _('Task Mail Object'), 'name' => _('Task Mail Object'),
'attrs' => [ 'attrs' => [
new SelectAttribute( new SelectAttribute(
_('Mail Template'), _('Mail Template Object Selection'), _('Mail Template'), _('Mail Template Object Selection'),
...@@ -58,15 +58,15 @@ class tasksMail extends simplePlugin ...@@ -58,15 +58,15 @@ class tasksMail extends simplePlugin
] ]
], ],
'From Component' => [ 'From Component' => [
'name' => _('Sender email address'), 'name' => _('Sender email address'),
'attrs' => [ 'attrs' => [
new MailAttribute( new MailAttribute(
_('Sender email address'), _('Sender email address'),
_('Email address from which mails will be sent'), 'fdTasksEmailSender', TRUE, 'to.be@chang.ed'), _('Email address from which mails will be sent'), 'fdTasksEmailSender', TRUE, 'to.be@chang.ed'),
] ]
], ],
'UserGroupSelection' => [ 'UserGroupSelection' => [
'name' => _('Recipients Users and/or Groups'), 'name' => _('Recipients Users and/or Groups'),
'attrs' => [ 'attrs' => [
new UsersGroupsRolesAttribute( new UsersGroupsRolesAttribute(
_('Members'), _('Users or groups to assign to this task.'), _('Members'), _('Users or groups to assign to this task.'),
...@@ -75,7 +75,7 @@ class tasksMail extends simplePlugin ...@@ -75,7 +75,7 @@ class tasksMail extends simplePlugin
], ],
], ],
'tasksMailType' => [ 'tasksMailType' => [
'name' => _('Type of e-mail address desired'), 'name' => _('Type of e-mail address desired'),
'attrs' => [ 'attrs' => [
new SelectAttribute( new SelectAttribute(
_('Mail Type - If not found, priority will apply'), _('Mail Type Object Selection'), _('Mail Type - If not found, priority will apply'), _('Mail Type Object Selection'),
...@@ -103,12 +103,12 @@ class tasksMail extends simplePlugin ...@@ -103,12 +103,12 @@ class tasksMail extends simplePlugin
$this->attributesAccess['fdTasksMailObject']->setChoices(array_keys($tmpSearch), array_values($tmpSearch)); $this->attributesAccess['fdTasksMailObject']->setChoices(array_keys($tmpSearch), array_values($tmpSearch));
$mailAttrTypes = [ $mailAttrTypes = [
'mail' => 'mail - [gosaMailAccount primary]', 'mail' => 'mail - [gosaMailAccount primary]',
'gosaMailAlternateAddress' => 'gosaMailAlternateAddress', 'gosaMailAlternateAddress' => 'gosaMailAlternateAddress',
'gosaMailForwardingAddress' => 'gosaMailForwardingAddress', 'gosaMailForwardingAddress' => 'gosaMailForwardingAddress',
'supannAutreMail' => 'supannAutreMail', 'supannAutreMail' => 'supannAutreMail',
'supannMailPerso' => 'supannMailPerso', 'supannMailPerso' => 'supannMailPerso',
'supannMailPrive' => 'supannMailPrive' 'supannMailPrive' => 'supannMailPrive'
]; ];
$this->attributesAccess['fdTasksMailType']->setChoices(array_keys($mailAttrTypes), array_values($mailAttrTypes)); $this->attributesAccess['fdTasksMailType']->setChoices(array_keys($mailAttrTypes), array_values($mailAttrTypes));
...@@ -124,7 +124,7 @@ class tasksMail extends simplePlugin ...@@ -124,7 +124,7 @@ class tasksMail extends simplePlugin
parent::update(); parent::update();
// get the value of type mail desired and if null set default // 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)) { if (empty($mailAttr)) {
$mailAttr = 'mail'; $mailAttr = 'mail';
} }
...@@ -141,7 +141,7 @@ class tasksMail extends simplePlugin ...@@ -141,7 +141,7 @@ class tasksMail extends simplePlugin
/* /*
* Return the objectype searched for by setEmailFromSelectedDN * Return the objectype searched for by setEmailFromSelectedDN
*/ */
public function getMailObject (string $mailAttr) : string public function getMailObject (string $mailAttr): string
{ {
switch ($mailAttr) { switch ($mailAttr) {
case 'mail' : case 'mail' :
...@@ -159,10 +159,10 @@ class tasksMail extends simplePlugin ...@@ -159,10 +159,10 @@ class tasksMail extends simplePlugin
} }
} }
/* /*
* Populate the fdTasksEmailsFromDN attribute with related mails addresses. * Populate the fdTasksEmailsFromDN attribute with related mails addresses.
*/ */
public function setEmailsFromSelectedDN ($mailObject, $mailAttr) : void public function setEmailsFromSelectedDN ($mailObject, $mailAttr): void
{ {
global $config; global $config;
...@@ -241,50 +241,82 @@ class tasksMail extends simplePlugin ...@@ -241,50 +241,82 @@ class tasksMail extends simplePlugin
*/ */
public function generateSlaveTasks () public function generateSlaveTasks ()
{ {
global $config;
$ldap = $config->get_ldap_link();
$emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue(); $emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue();
// Ref is supposed to be the mail object CN in this class // 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(); $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 // Take the attribute from the other tabs - attribute cannot be null or unset by default
$schedule = $this->parent->getBaseObject()->fdTasksScheduleDate ?? NULL; $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)) { if (!empty($emails)) {
foreach ($emails as $email) { // Condition allowing the creation of subtasks for existing members
// Using ID incrementation in order to have sub-tasks CN with different name. if ($newMemberOnly === TRUE) {
// Enhancement possible is to use dateTime instead. $ldap->cd($config->current['BASE']);
$id ++; $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 // Here we create the object taskGranular
$tabObject = objects::create('TasksGranular'); $tabObject = objects::create('TasksGranular');
// remove 'dn' keeping only 'cn' // Create a unique ID based on timestamp (Allowing duplicate subtasks for same members in case of repeat).
$rmDn = preg_replace('/(?=,).*/', '', $this->dn); $timestamp = microtime(TRUE); // Get the current timestamp with microseconds
$timestamp = (string)$timestamp; // Convert the float to a string, str_replace expect array or string.
// only take the cn without dc $uniqueID = str_replace(".", "_", $timestamp); // Remove . with _ for correct CN
preg_match('/cn=(.*)/', $rmDn, $matches);
$subTaskName = $matches[1].'-SubTask-'.$id; // Array matches come from preg_match function above with rmDn
$subTaskName = $matches[1] . '-SubTask-' . $uniqueID;
$values['tasksGranular'] = [ $values['tasksGranular'] = [
"cn" => $subTaskName, "cn" => $subTaskName,
"fdTasksGranularType" => 'Mail Object', "fdTasksGranularType" => 'Mail Object',
"fdTasksGranularMaster" => $this->dn, "fdTasksGranularMaster" => $this->dn,
"fdTasksGranularMail" => $email, "fdTasksGranularMail" => $email,
"fdTasksGranularSchedule" => $schedule, "fdTasksGranularSchedule" => $schedule,
"fdTasksGranularRef" => $ref, "fdTasksGranularRef" => $ref,
"fdTasksGranularMailFrom" => $from "fdTasksGranularMailFrom" => $from
]; ];
foreach ($values as $tab => $tabvalues) { foreach ($values as $tab => $tabvalues) {
if (!isset($tabObject->by_object[$tab])) { 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); $error = $tabObject->by_object[$tab]->deserializeValues($tabvalues);
if ($error !== TRUE) { if ($error !== TRUE) {
echo 'Error during deserializing' .$error .PHP_EOL; echo 'Error during deserializing' . $error . PHP_EOL;
} }
$tabObject->current = $tab; $tabObject->current = $tab;
......
...@@ -24,11 +24,10 @@ class tasksManagement extends management ...@@ -24,11 +24,10 @@ class tasksManagement extends management
protected $skipCpHandler = TRUE; protected $skipCpHandler = TRUE;
/* /*
* LinkColumn exists by class collumn * LinkColumn exists by class column
* TasksColumn is a new class for Tasks bassed on argonaut column definition * TasksColumn is a new class for Tasks based on argonaut column definition
*/ */
public static $columns = [ 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) //below fdTasksMailObject must be change to have a type defined within task creation (new ldap attributes ?hidden)
['TasksColumn', ['attributes' => 'fdTasksMailObject', 'label' => 'Types']], ['TasksColumn', ['attributes' => 'fdTasksMailObject', 'label' => 'Types']],
['Column', ['attributes' => 'fdTasksCreationDate', 'label' => 'Creation Date']], ['Column', ['attributes' => 'fdTasksCreationDate', 'label' => 'Creation Date']],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment