From c63884be8b25f70b9925aa1c8a34a89da17ba113 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Thu, 27 Oct 2022 17:07:48 +0100 Subject: [PATCH] :sparkles: Feat(Tasks) - Dashboard v0.2 Adding some features to create dynamically tasks dashboard. Allowing tasks mail to create granular objects. --- contrib/openldap/core-fd.schema | 34 +++++++++++ plugins/addons/tasks/class_tasks.inc | 1 + plugins/addons/tasks/class_tasksGranular.inc | 62 +++++++------------- plugins/addons/tasks/class_tasksMail.inc | 48 ++++++++++++++- plugins/admin/tasks/class_tasksDashboard.inc | 13 ++-- 5 files changed, 107 insertions(+), 51 deletions(-) diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema index 5fbdc63bf..22613dcf1 100644 --- a/contrib/openldap/core-fd.schema +++ b/contrib/openldap/core-fd.schema @@ -328,6 +328,35 @@ attributetype ( 1.3.6.1.4.1.38414.89.1.8 NAME 'fdTasksEmailSender' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) +##### Tasks Granular ##### + +attributetype ( 1.3.6.1.4.1.38414.89.1.9 NAME 'fdTasksGranularStatus' + DESC 'Fusion Directory - Task Status' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) + +attributetype ( 1.3.6.1.4.1.38414.89.1.10 NAME 'fdTasksGranularSchedule' + DESC 'Scheduling of the Task - required processed date' + EQUALITY caseExactIA5Match + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) + +attributetype ( 1.3.6.1.4.1.38414.89.1.11 NAME 'fdTasksGranularMaster' + DESC 'Fusion Directory - Tasks Master objects' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.89.1.12 NAME 'fdTasksGranularType' + DESC 'Fusion Directory - Tasks Type' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.89.1.13 NAME 'fdTasksGranularMail' + DESC 'Fusion Directory - Task Mail' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) + ##### Classes ##### objectclass ( 1.3.6.1.4.1.10098.1.2.1.19.4 NAME 'gosaDepartment' SUP top AUXILIARY @@ -422,3 +451,8 @@ objectclass (1.3.6.1.4.1.38414.89.2.2 NAME 'fdTasksMail' SUP top AUXILIARY MUST ( fdTasksMailObject $ fdTasksEmailSender ) MAY ( fdTasksMailUsers $ fdTasksEmailsFromDN ) ) + +objectclass (1.3.6.1.4.1.38414.89.2.3 NAME 'fdTasksGranular' + DESC 'FusionDirectory - Tasks granular objects' + MUST ( fdTasksGranularMaster $ cn $ fdTasksGranularMail $ + fdTasksGranularType $ fdTasksGranularSchedule $ fdTasksGranularStatus )) diff --git a/plugins/addons/tasks/class_tasks.inc b/plugins/addons/tasks/class_tasks.inc index 4c3d4849e..6f4138279 100644 --- a/plugins/addons/tasks/class_tasks.inc +++ b/plugins/addons/tasks/class_tasks.inc @@ -55,6 +55,7 @@ class tasks extends simplePlugin _('Schedule'), '', 'fdTasksScheduleDate', FALSE ), + new HiddenAttribute('fdTasksStatus', TRUE, '1', '', 'Status', 'Status of the task'), new HiddenAttribute('fdTasksCreationDate', TRUE, date("Y-m-d h:i:sa"), '', 'StartDate', 'Start Date And Time Of A Task'), ] diff --git a/plugins/addons/tasks/class_tasksGranular.inc b/plugins/addons/tasks/class_tasksGranular.inc index d7b3b0924..65b34f5f4 100644 --- a/plugins/addons/tasks/class_tasksGranular.inc +++ b/plugins/addons/tasks/class_tasksGranular.inc @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class tasksGranular extends tasks +class tasksGranular extends simplePlugin { static function plInfo (): array @@ -27,11 +27,11 @@ class tasksGranular extends tasks return [ 'plShortName' => _('Tasks Granular'), 'plDescription' => _('Granular tasks mangement allowing details reports'), - 'plObjectClass' => ['fdTasks'], - 'plFilter' => '(objectClass=fdTasks)', + 'plObjectClass' => ['fdTasksGranular'], + 'plFilter' => '(objectClass=fdTasksGranular)', 'plPriority' => 41, 'plObjectType' => ['tasksGranular' => [ - 'name' => _('Tasks'), + 'name' => _('TasksGranular'), 'ou' => get_ou('tasksRDN'), 'icon' => 'geticon.php?context=applications&icon=dsa&size=16', ]], @@ -43,41 +43,23 @@ class tasksGranular extends tasks { return [ // Attributes are grouped by section - 'tasks' => [ - 'name' => _('List of sub tasks'), + 'tasksGranular' => [ + 'name' => _('Tasks Granular'), 'attrs' => [ - new StringAttribute( - _('Task Name'), _('Name for this task'), - 'cn', TRUE - ), - new DateTimeAttribute( + new StringAttribute( + _('Task Granular Name'), _('Name for this task'), + 'cn', TRUE + ), + new HiddenAttribute('fdTasksGranularStatus', TRUE, '1', '', 'Status', 'Status of the task'), + new HiddenAttribute('fdTasksGranularMaster', TRUE, '', '', 'Master CN', 'Name of the Master task'), + new HiddenAttribute('fdTasksGranularType', TRUE, '', '', 'Type', 'Type of the task'), + new HiddenAttribute('fdTasksGranularMail', TRUE, '', '', 'Mail', 'Mail of the task'), + new DateTimeAttribute( _('Schedule'), '', - 'fdTasksScheduleDate', FALSE - ), - new HiddenAttribute('fdTasksStatus', TRUE, '1', '', 'Status', 'Status of the task'), - new HiddenAttribute('fdTasksCreationDate', TRUE, date("Y-m-d h:i:sa"), '', 'StartDate', 'Start Date And Time Of A Task'), - new SetAttribute( - new CompositeAttribute( - _('Macro definitions'), - 'fdSubTasks', - [ - new SelectAttribute( - '', _('Macro type'), - 'fdSubTasks', TRUE - ), - new StringAttribute( - _('Macros User Definition'), _('Macro that will be used'), - 'fdSubTasks', TRUE, '' - ), - ], - '/^{(.+)}(.*)$/', - '{%s}%s', - '', - _('To be defined properly') + 'fdTasksGranularSchedule', FALSE ) - ), ] - ], + ] ]; } @@ -86,13 +68,9 @@ class tasksGranular extends tasks global $config; parent::__construct($dn, $object, $parent, $mainTab); - // As this class inherit from tasks, attributes must not be seen or be modifiable - $this->attributesAccess['cn']->setVisible(FALSE); - $this->attributesAccess['fdTasksScheduleDate']->setVisible(FALSE); - $this->read_only = TRUE; - + $this->attributesAccess['fdTasksGranularMaster']->setValue('testMaster'); + $this->attributesAccess['fdTasksGranularType']->setValue('testType'); + $this->attributesAccess['fdTasksGranularMail']->setValue('testMail'); } - - } diff --git a/plugins/addons/tasks/class_tasksMail.inc b/plugins/addons/tasks/class_tasksMail.inc index fda93953b..5247534ec 100644 --- a/plugins/addons/tasks/class_tasksMail.inc +++ b/plugins/addons/tasks/class_tasksMail.inc @@ -56,7 +56,7 @@ class tasksMail extends simplePlugin 'fdTasksMailObject', FALSE ), new HiddenArrayAttribute('fdTasksEmailsFromDN', FALSE, ''), - ] + ] ], 'From Component' => [ 'name' => _('Sender Address'), @@ -93,7 +93,6 @@ class tasksMail extends simplePlugin } asort($tmpSearch); $this->attributesAccess['fdTasksMailObject']->setChoices(array_keys($tmpSearch), array_values($tmpSearch)); - } /* @@ -140,4 +139,49 @@ class tasksMail extends simplePlugin } } + function save (): array + { + $this->generateSlaveTasks(); + + $errors = parent::save(); + return $errors; + } + + public function generateSlaveTasks () : void + { + $tabobject = objects::create('TasksGranular'); + $infos = objects::infos('TasksGranular'); + $emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue(); + + // Testing purposes + $id = 1; + + if (isset($emails) && !empty($emails)) { + foreach ($emails as $email) { + $id += $id; + $values['tasksGranular'] = [ + "cn" => "testCN-.$id", + "fdTasksGranularType" => 'Mail Object', + ]; + + foreach ($values as $tab => $tabvalues) { + if (!isset($tabobject->by_object[$tab])) { + echo "Error tabObject by object tab is not set"; + } + $error = $tabobject->by_object[$tab]->deserializeValues($tabvalues); + if ($error !== TRUE) { + echo $error; + } + + $tabobject->current = $tab; + $tabobject->update(); + $tabobject->loadTabs(); + } + $errors = $tabobject->save(); + if (!empty($errors)) { + print_r($errors); + } + } + } + } } diff --git a/plugins/admin/tasks/class_tasksDashboard.inc b/plugins/admin/tasks/class_tasksDashboard.inc index ffa78bae8..8c6c286ef 100644 --- a/plugins/admin/tasks/class_tasksDashboard.inc +++ b/plugins/admin/tasks/class_tasksDashboard.inc @@ -18,18 +18,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class tasksDashboard extends tasksManagement +class tasksDashboard extends management { // Actions collumn are removed compared to parent 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']], - ['TasksColumn', ['attributes' => 'fdTasksScheduleDate', 'label' => 'Schedule']], - //below fdTasksStatus attribute needs to be calculated based on the type of the task. - ['TasksColumn', ['attributes' => 'fdTasksStatus', 'label' => 'Status']], - ['Column', ['attributes' => 'fdTasksCreationDate', 'label' => 'Creation Date']] + ['Column', ['attributes' => 'fdTasksGranularMaster', 'label' => 'Master Task']], + ['Column', ['attributes' => 'fdTasksGranularType', 'label' => 'Types']], + ['Column', ['attributes' => 'fdTasksGranularMail', 'label' => 'Email']], + ['Column', ['attributes' => 'fdTasksGranularSchedule', 'label' => 'Schedule']], + ['Column', ['attributes' => 'fdTasksGranularStatus', 'label' => 'Status']], ]; // No modification tools are required -- GitLab