From 42181356996121f9f7ea96470c3e881f2164aa75 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Thu, 4 Apr 2024 11:29:00 +0100
Subject: [PATCH] :sparkles: (Tasks) - Change hiddenAttribute to array for
 Referal

Change hiddenAttribute to array for Referal data.
---
 contrib/openldap/core-fd.schema               |  3 +-
 plugins/configuration/tasks/class_tasks.inc   |  4 +--
 .../tasks/class_tasksGranular.inc             | 28 +++++++++----------
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema
index f7c7ea363..0ffe82de9 100644
--- a/contrib/openldap/core-fd.schema
+++ b/contrib/openldap/core-fd.schema
@@ -307,8 +307,7 @@ attributetype ( 1.3.6.1.4.1.38414.62.1.56 NAME 'fdTasksGranularMailBCC'
 attributetype ( 1.3.6.1.4.1.38414.62.1.26 NAME 'fdTasksGranularRef'
   DESC 'Fusion Directory - Reference towards a CN (E.g Mail Template)'
   EQUALITY caseExactMatch
-  SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
-  SINGLE-VALUE )
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
 
 ## Any tasks requiring to store DN (Such as lifeCycle). ##
 
diff --git a/plugins/configuration/tasks/class_tasks.inc b/plugins/configuration/tasks/class_tasks.inc
index f692dce0a..bf92be135 100644
--- a/plugins/configuration/tasks/class_tasks.inc
+++ b/plugins/configuration/tasks/class_tasks.inc
@@ -205,7 +205,7 @@ class tasks extends simplePlugin
               "fdTasksGranularDN"   => $dn,
               "fdTasksGranularType" => $taskType,
               // Verification as 'ref' could potentially not be present depending on the logic of the main task.
-              "fdTasksGranularRef"  => !empty($attrs['ref']) ? $attrs['ref'] : null,
+              "fdTasksGranularRef"  => !empty($attrs['ref'][$dn]) ? array_values($attrs['ref'][$dn]) : [],
             ];
             break;
         }
@@ -218,7 +218,7 @@ class tasks extends simplePlugin
         ];
         // Simply merged the common values and the custom ones depending on the attribute type passed.
         $values['tasksGranular'] = array_merge($prepData['tasksGranular'], $defaultData['tasksGranular']);
-
+        print_r($values);
         foreach ($values as $tab => $tabvalues) {
           if (!isset($tabObject->by_object[$tab])) {
             echo "Error tab does not contains attributes values" . PHP_EOL;
diff --git a/plugins/configuration/tasks/class_tasksGranular.inc b/plugins/configuration/tasks/class_tasksGranular.inc
index 2504202dd..8dfbdd777 100644
--- a/plugins/configuration/tasks/class_tasksGranular.inc
+++ b/plugins/configuration/tasks/class_tasksGranular.inc
@@ -25,15 +25,15 @@ class tasksGranular extends simplePlugin
   static function plInfo (): array
   {
     return [
-      'plShortName'   => _('Tasks Granular'),
-      'plDescription' => _('Granular tasks management allowing details reports'),
-      'plObjectClass' => ['fdTasksGranular'],
-      'plFilter'      => '(objectClass=fdTasksGranular)',
-      'plPriority'    => 41,
-      'plObjectType'  => ['tasksGranular' => [
-        'name'        => _('TasksGranular'),
-        'ou'          => get_ou('tasksRDN'),
-        'icon'        => 'geticon.php?context=applications&icon=tasks&size=16',
+      'plShortName'    => _('Tasks Granular'),
+      'plDescription'  => _('Granular tasks management allowing details reports'),
+      'plObjectClass'  => ['fdTasksGranular'],
+      'plFilter'       => '(objectClass=fdTasksGranular)',
+      'plPriority'     => 41,
+      'plObjectType'   => ['tasksGranular' => [
+        'name' => _('TasksGranular'),
+        'ou'   => get_ou('tasksRDN'),
+        'icon' => 'geticon.php?context=applications&icon=tasks&size=16',
       ]],
       'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
     ];
@@ -59,7 +59,7 @@ class tasksGranular extends simplePlugin
           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('fdTasksGranularRef', FALSE, '', '', 'Type', 'Reference towards a required CN (mail template E.g'),
+          new HiddenArrayAttribute('fdTasksGranularRef', FALSE, '', '', 'Type', 'Reference towards a required CN (mail template E.g'),
           new DateTimeAttribute(
             _('Schedule'), '',
             'fdTasksGranularSchedule', FALSE
@@ -71,11 +71,11 @@ class tasksGranular extends simplePlugin
           ),
           // Below attributes are for tasks of type Mail
           new MailAttribute(
-             _('Email'),
-             _('Email address to which messages will be sent'), 'fdTasksGranularMail', FALSE),
+            _('Email'),
+            _('Email address to which messages will be sent'), 'fdTasksGranularMail', FALSE),
           new MailAttribute(
-             _('Email'),
-             _('Email address from which emails will be sent'), 'fdTasksGranularMailFrom', FALSE),
+            _('Email'),
+            _('Email address from which emails will be sent'), 'fdTasksGranularMailFrom', FALSE),
           new MailAttribute(
             _('Email'),
             _('BCC Email address'), 'fdTasksGranularMailBCC', FALSE),
-- 
GitLab