From 8f2a33d0c522e56bbaec1e42307e613a0a60e808 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Mon, 23 Oct 2023 15:07:23 +0100
Subject: [PATCH] :sparkles: Feat(tasks) - Repeatable tasks

Allows the creation of repeatable tasks as well as defining scope of new or old members
---
 contrib/openldap/core-fd.schema             | 22 +++++++++++++++-
 plugins/configuration/tasks/class_tasks.inc | 29 ++++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema
index da9453bad..a90e63149 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 53ffe01da..78e2c8553 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);
   }
 
-- 
GitLab