Commit 8fa205a2 authored by dockx thibault's avatar dockx thibault
Browse files

Merge branch...

Merge branch '6333-archive-new-task-automation-of-archiving-logic-based-on-supann-resources' into 'dev'

Resolve "[Archive] - New task - automation of archiving logic based on supann resources"

See merge request fusiondirectory/fd-plugins!1091
Showing with 208 additions and 0 deletions
+208 -0
...@@ -44,3 +44,39 @@ objectclass (1.3.6.1.4.1.38414.81.2.1 NAME 'fdArchivedObject' ...@@ -44,3 +44,39 @@ objectclass (1.3.6.1.4.1.38414.81.2.1 NAME 'fdArchivedObject'
fdArchivedField $ fdArchivedUniqueField $ fdArchivedField $ fdArchivedUniqueField $
fdArchivedDateTime $ fdArchivedObjectType $ fdArchivedOriginDn fdArchivedDateTime $ fdArchivedObjectType $ fdArchivedOriginDn
) ) ) )
#### Managing archive tasks ####
# Attributes
attributetype ( 1.3.6.1.4.1.38414.81.1.6 NAME 'fdArchiveTaskResource'
DESC 'Fusion Directory - SupAnn resource to be archived'
EQUALITY caseExactMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.81.1.7 NAME 'fdArchiveTaskState'
DESC 'Fusion Directory - SupAnn state triggering the archive task'
EQUALITY caseExactMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.81.1.8 NAME 'fdArchiveTaskSubState'
DESC 'Fusion Directory - SupAnn sub-state triggering the archive task'
EQUALITY caseExactMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.81.1.9 NAME 'fdArchiveTaskMembers'
DESC 'Fusion Directory - List of users or groups to monitor for archiving'
EQUALITY caseExactMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
# Object Class
objectclass ( 1.3.6.1.4.1.38414.81.2.2 NAME 'fdArchiveTasks' SUP top AUXILIARY
DESC 'FusionDirectory - Archive tasks plugin Object Class'
MUST ( fdArchiveTaskResource $ fdArchiveTaskState $ fdArchiveTaskMembers )
MAY ( fdArchiveTaskSubState ) )
\ No newline at end of file
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2025 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
class archiveTask extends simplePlugin
{
protected $displayHeader = TRUE;
private $subStates;
static function plInfo (): array
{
return [
'plShortName' => _('Tasks Archive'),
'plDescription' => _('Tasks Archive Object'),
'plIcon' => 'geticon.php?context=mimetypes&icon=application-x-archive&size=48',
'plPriority' => 42,
'plObjectClass' => ['fdArchiveTasks'],
'plFilter' => '(objectClass=fdArchiveTasks)',
'plObjectType' => ['tasks'],
'plConflicts' => ['tasksMail', 'tasksLifeCycle', 'tasksNotifications', 'auditTasks'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()),
'plForeignKeys' => [],
];
}
static function getAttributesInfo (): array
{
return [
'section1' => [
'name' => _('SupAnn Resource Archiving Settings'),
'attrs' => [
new SelectAttribute(
_('Resource'), _('Supann resources'),
'fdArchiveTaskResource', TRUE, [], "None"
),
new SelectAttribute(
_('State'), _('Resource state'),
'fdArchiveTaskState', TRUE, [], "None"
),
new SelectAttribute(
_('Sub state'), _('Resource sub state'),
'fdArchiveTaskSubState', FALSE, [], "None"
),
]
],
'UserGroupSelection' => [
'name' => _('Recipients Users and/or Groups'),
'attrs' => [
new UsersGroupsRolesAttribute(
_('Monitored Members'), _('Users or Groups requiring monitoring for archiving.'),
'fdArchiveTaskMembers', TRUE
),
],
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
// SupAnn Status management
if (class_available('supannAccountStatus')) {
$this->setSupannStates();
} else {
msg_dialog::display(
_('Warning'),
_('The SupAnn Account Status plugin is not activated. This task cannot function properly without it.'),
WARNING_DIALOG
);
}
}
/**
* @return void
* Note : Simply get the existing SupAnn states to the archive attributes.
*/
protected function setSupannStates (): void
{
global $config;
// Define the mandatory ones and get the remaining from configuration.
$resources = ['COMPTE' => _('Account'), 'MAIL' => _('Mail'), 'NONE' => _('None')];
foreach ($config->get_cfg_value('SupannRessourceLabels', []) as $line) {
list($resource, $label) = explode(':', $line, 2);
$resources[$resource] = $label;
}
$this->subStates = supannAccountStatus::getConfiguredSubstates(); // Keys are states and Values are subStates
$this->attributesAccess['fdArchiveTaskResource']->setChoices(array_keys($resources), array_values($resources));
$this->attributesAccess['fdArchiveTaskState']->setChoices(array_keys($this->subStates));
// Allows the sub states to be listed when state is modified.
$this->attributesAccess['fdArchiveTaskState']->setSubmitForm('updateFieldsChoices');
$this->updateFieldsChoices();
}
/**
* @return void
* Note : Update list of subStates which depends on the state selected
*/
function updateFieldsChoices ()
{
$subStatesList = $this->subStates[$this->attributesAccess['fdArchiveTaskState']->getValue()] ?? [];
$this->attributesAccess['fdArchiveTaskSubState']->setChoices(array_keys($subStatesList), array_values($subStatesList));
}
/**
* Generate slave tasks for archiving
*/
function generateSlaveTasks ()
{
$monitoredMembers = $this->attributesAccess['fdArchiveTaskMembers']->getValue();
$listOfDN = tasks::extractMembersFromGroups($monitoredMembers);
// Call the method from parent tasks object (first tab) to create sub-tasks.
$this->parent->getBaseObject()->createSlaveTasks($listOfDN, 'fdTasksGranularDN', NULL, 'archive');
}
/**
* @return bool
*/
function update (): bool
{
parent::update();
return TRUE;
}
/**
* @return array
*/
function save (): array
{
// Check if the SupAnn Account Status plugin is available (It should not happen as attributes verification will trigger errors before save)
if (!class_available('supannAccountStatus')) {
msg_dialog::display(
_('Error'),
_('The SupAnn Account Status plugin is not activated. This task cannot be saved or executed without it.'),
ERROR_DIALOG
);
return []; // Return an empty array to indicate no action was taken
}
// Verify if this task has to be executed upon saving
$execTasks = $this->parent->getBaseObject()->fdSubTasksActivation ?? NULL;
if ($execTasks) {
$this->generateSlaveTasks();
}
return parent::save();
}
}
\ No newline at end of file
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