Verified Commit 367b3527 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(archive) Create an archive plugin

First bits of the archive plugin.
Does not do much yet, code is needed on core side.

issue #6075
# Veuillez saisir le message de validation pour vos modifications. Les lignes
# commençant par '#' seront ignorées, et un message vide abandonne la validation.
#
# Sur la branche 6075-add-an-account-archival-plugin-to-fusiondirectory
# Votre branche est à jour avec 'gitlab/6075-add-an-account-archival-plugin-to-fusiondirectory'.
#
# Modifications qui seront validées :
#	nouveau fichier : archive/admin/archive/class_archiveManagement.inc
#	nouveau fichier : archive/admin/archive/class_archivedObject.inc
#	nouveau fichier : archive/config/archive/class_archiveConfig.inc
#	nouveau fichier : archive/contrib/openldap/archive-fd-conf.schema
#	nouveau fichier : archive/contrib/openldap/archive-fd.schema
#
# Fichiers non suivis:
#	.php_cs.cache
#	.php_cs.dist
#	0001-ambulance-fix-interfaces-Attempt-at-fixing-webservic-old.patch
#	0001-ambulance-fix-interfaces-Attempt-at-fixing-webservic.patch
#	groupofuniquenames/
#	kerberos.schema
#	mail/personal/mail/class_sieve_new.inc
#	webservice/contrib/test/composer.json
#	webservice/contrib/test/composer.lock
#	webservice/contrib/test/dredd.out
#	webservice/contrib/test/vendor/
#	webservice/html/openapi-custom.yaml
#	webservice/html/openapi-test.yaml
#	webservice/html/rest.php.orig
#
Showing with 400 additions and 0 deletions
+400 -0
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2019-2020 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 archiveManagement extends management
{
protected $skipCpHandler = TRUE;
public static $skipSnapshots = TRUE;
/* Default columns */
public static $columns = [
['ObjectTypeColumn', []],
['LdapGeneralizedTimeColumn', ['attributes' => 'fdArchivedDateTime', 'label' => 'Time']],
['LinkColumn', ['attributes' => 'fdArchivedObjectType', 'label' => 'Type']],
['LinkColumn', ['attributes' => 'fdArchivedOriginDn', 'label' => 'Origin']],
];
public static function plInfo (): array
{
return [
'plShortName' => _('Archived objects'),
'plTitle' => _('Archived objects'),
'plDescription' => _('Browse archived objects'),
'plIcon' => 'geticon.php?context=mimetype&icon=application-x-archive&size=48',
'plSection' => 'reporting',
'plManages' => ['archivedObject'],
];
}
function __construct ()
{
parent::__construct();
$this->filter->addElement(new DateFilterElement($this->filter, 'fdArchivedDateTime', _('Date'), date('Y-m-d')));
/*$items = [];
Please register or sign in to reply
foreach (logging::$validActions as $validAction) {
$items[$validAction] = [
'name' => $validAction,
'filter' => '(fdAuditAction='.$validAction.')',
];
}
$this->filter->addElement(new CheckBoxesFilterElement($this->filter, _('Action'), $items, '|'));*/
}
protected function setUpListing ()
{
/* Disable multi select */
$this->listing = new managementListing($this, TRUE, FALSE);
/* Newer archives first */
$this->listing->setSortColumn(1, TRUE);
}
protected function configureActions ()
{
parent::configureActions();
/* Remove create */
$removeActions = ['new'];
foreach ($removeActions as $action) {
foreach ($this->actions[$action]->listActions() as $actionName) {
unset($this->actionHandlers[$actionName]);
}
unset($this->actions[$action]);
}
unset($this->actions['removeConfirmed']);
$this->actions['edit']->setInMenu(FALSE);
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2019-2020 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 archivedObject extends simplePlugin
{
public $base;
public static function plInfo (): array
{
return [
'plShortName' => _('Archived Object'),
'plDescription' => _('An object which have been archived through archive plugin'),
'plObjectClass' => ['fdArchivedObject'],
'plObjectType' => ['archivedObject' => [
'name' => _('Archived Object'),
'icon' => 'geticon.php?context=mimetypes&icon=application-x-archive&size=16',
'ou' => get_ou('archiveRDN'),
'mainAttr' => FALSE,
]],
'plSearchAttrs' => [],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
];
}
static function getAttributesInfo (): array
{
return [
'main' => [
'name' => _('Data'),
'attrs' => [
new GeneralizedTimeDisplayAttribute(
_('Time'), _('Date and time this object was archived'),
'fdArchivedDateTime', TRUE
),
new DisplayLDAPAttribute(
_('Object type'), _('Object type'),
'fdArchivedObjectType', TRUE
),
new DisplayLDAPAttribute(
_('Origin DN'), _('DN of the object before deletion'),
'fdArchivedOriginDn', TRUE
),
new DisplayLDAPArrayAttribute(
_('Fields'), _('Archived fields'),
'fdArchivedField', FALSE
),
new DisplayLDAPArrayAttribute(
_('Unique fields'), _('Archived unique fields'),
'fdArchivedUniqueField', FALSE
),
]
],
];
}
public function compute_dn (): string
{
return $this->create_unique_dn('fdArchivedDateTime', get_ou('archiveRDN').$this->base);
}
/*!
* \brief Archive object data and delete it
*/
public static function archiveObject (string $type, string $dn): array
{
global $config;
$typesAndFields = $config->get_cfg_value('fdArchivedTypesAndFields', []);
foreach ($typesAndFields as $typeAndFields) {
list($configType, $fields, $uniquefields) = explode('|', $typeAndFields);
if ($configType == $type) {
$fields = explode(',', $fields);
$uniquefields = explode(',', $uniquefields);
$attrs = [];
foreach ($fields as $field) {
$attrs[$field] = '*';
}
foreach ($uniquefields as $field) {
$attrs[$field] = '*';
}
$objects = objects::ls('user', $attrs, $dn, '', FALSE, 'base');
$fdArchivedField = [];
foreach ($fields as $field) {
if (isset($objects[$dn][$field])) {
foreach ($objects[$dn][$field] as $value) {
$fdArchivedField[] = $field.':'.$value;
}
}
}
$fdArchivedUniqueField = [];
foreach ($uniquefields as $field) {
if (isset($objects[$dn][$field])) {
foreach ($objects[$dn][$field] as $value) {
$fdArchivedUniqueField[] = $field.':'.$value;
}
}
}
/* Archive data */
$archivedObject = objects::create('archivedObject');
$baseObject = $archivedObject->getBaseObject();
$baseObject->fdArchivedDateTime = new DateTime('now');
$baseObject->fdArchivedObjectType = $type;
$baseObject->fdArchivedOriginDn = $dn;
$baseObject->fdArchivedField = $fdArchivedField;
$baseObject->fdArchivedUniqueField = $fdArchivedUniqueField;
$baseObject->base = dn2base($dn);
$errors = $archivedObject->save();
if (!empty($errors)) {
return $errors;
}
/* Delete object */
$tabObject = objects::open($dn, $type);
if (!$tabObject->delete()) {
/* Deletion failed */
$archivedObject->delete();
}
/* No errors */
return [];
}
}
return [new FusionDirectoryException('No configuration found for archiving type '.$type)];
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2019-2020 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 archiveConfig extends simplePlugin
{
static function plInfo (): array
{
return [
'plShortName' => _('Archive configuration'),
'plDescription' => _('FusionDirectory archive plugin configuration'),
'plObjectClass' => ['fdArchivePluginConf'],
'plCategory' => ['configuration'],
'plObjectType' => ['smallConfig'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
];
}
static function getAttributesInfo (): array
{
return [
'main' => [
'name' => _('Archive'),
'attrs' => [
new StringAttribute(
_('Archive RDN'), _('Branch in which archived objects will be stored'),
'fdArchiveRDN', TRUE,
'ou=archive'
),
new OrderedArrayAttribute(
new PipeSeparatedCompositeAttribute(
_('Use this to hide some menu entry to specific groups of users'),
'fdArchivedTypesAndFields',
[
new SelectAttribute(
_('Type'), _('Object type'),
'fdArchivedTypesAndFields_type', TRUE,
/* People usually archive users, so set it as default */
['USER'], 'USER'
),
new StringAttribute(
_('Fields'), _('Comma separated list of fields to archive for history purposes'),
'fdArchivedTypesAndFields_fields', FALSE
),
new StringAttribute(
_('Unique fields'), _('Comma separated list of fields to archive for history purposes and unicity checks'),
'fdArchivedTypesAndFields_uniquefields', FALSE
),
],
'',
_('Type and fields')
),
// no order
FALSE,
[]
),
]
],
];
}
function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$choices = static::getManagedTypes();
$this->attributesAccess['fdArchivedTypesAndFields']->attribute->attributes[0]->setChoices(array_keys($choices), array_values($choices));
$this->attributesAccess['fdArchivedTypesAndFields']->setLinearRendering(FALSE);
}
public static function getManagedTypes (): array
{
$result = [];
$types = objects::types();
foreach ($types as $type) {
$infos = objects::infos($type);
if (isset($infos['management'])) {
$result[$type] = $infos['name'];
}
}
asort($result);
return $result;
}
}
##
## archive-fd-conf.schema - Needed by Fusion Directory for managing archive plugin configuration
##
attributetype ( 1.3.6.1.4.1.38414.82.1.1 NAME 'fdArchivedTypesAndFields'
DESC 'FusionDirectory - Which fields of which type to archive, with syntax type|field1,field2|uniquefield1,uniquefield2'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
attributetype ( 1.3.6.1.4.1.38414.82.1.2 NAME 'fdArchiveRDN'
DESC 'FusionDirectory - Archive RDN'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
objectclass ( 1.3.6.1.4.1.38414.82.2.1 NAME 'fdArchivePluginConf'
DESC 'FusionDirectory archive plugin configuration'
SUP top AUXILIARY
MUST ( cn )
MAY ( fdArchivedTypesAndFields $ fdArchiveRDN ) )
##
## archive-fd.schema - Needed by Fusion Directory for archive plugin
##
# Attributes
attributetype ( 1.3.6.1.4.1.38414.81.1.1 NAME 'fdArchivedField'
DESC 'FusionDirectory - archived field'
EQUALITY octetStringMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40)
attributetype ( 1.3.6.1.4.1.38414.81.1.2 NAME 'fdArchivedUniqueField'
DESC 'FusionDirectory - archived field for unicity checks'
EQUALITY octetStringMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40)
attributetype ( 1.3.6.1.4.1.38414.81.1.3 NAME 'fdArchivedDateTime'
DESC 'FusionDirectory - archived object date and time'
EQUALITY generalizedTimeMatch
ORDERING generalizedTimeOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.81.1.4 NAME 'fdArchivedObjectType'
DESC 'FusionDirectory - archived object type'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.81.1.5 NAME 'fdArchivedOriginDn'
DESC 'FusionDirectory - archived object DN'
EQUALITY distinguishedNameMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
SINGLE-VALUE )
# Objectclasses
objectclass (1.3.6.1.4.1.38414.81.2.1 NAME 'fdArchivedObject'
DESC 'FusionDirectory - archived object'
MUST ( )
MAY (
fdArchivedField $ fdArchivedUniqueField $
fdArchivedDateTime $ fdArchivedObjectType $ fdArchivedOriginDn
) )
  • SonarQube analysis reported 1 issue

    • :warning: 1 major

    Watch the comments in this conversation to review them.

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