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

feat(supann) Add configuration for possible supann substates

issue #5907
parent 693f179c
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 FusionDirectory
Copyright (C) 2013-2019 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
......@@ -20,6 +21,8 @@
class supannConfig extends simplePlugin
{
protected $officialSubstates;
static function plInfo (): array
{
return [
......@@ -35,9 +38,17 @@ class supannConfig extends simplePlugin
static function getAttributesInfo (): array
{
$officialStates = supannAccountStatus::getOfficialSubstates();
$defaultStates = [];
foreach ($officialStates as $state => $substates) {
foreach (array_keys($substates) as $substate) {
$defaultStates[] = $state.':'.$substate;
}
}
return [
'main' => [
'name' => _('SupAnn'),
'class' => ['fullwidth'],
'attrs' => [
new StringAttribute(
_('SupAnn RDN'), _('Branch in which SupAnn structures will be stored'),
......@@ -49,8 +60,78 @@ class supannConfig extends simplePlugin
'fdSupannPasswordRecovery', FALSE,
TRUE
),
new OrderedArrayAttribute(
new CharSeparatedCompositeAttribute(
_('Allowed substates for an account'),
'fdSupannRessourceSubStates',
[
new SelectAttribute(
_('Status'), _('Active status this substatus is tied to'),
'fdSupannRessourceSubStates_status', TRUE,
['A','I','S'], 'A',
[_('Active'), _('Inactive'), _('Suspended')]
),
new StringAttribute(
_('Substatus'), _('LDAP value for this substatus'),
'fdSupannRessourceSubStates_substatus', TRUE
),
],
':',
'',
_('Substates')
),
TRUE,
$defaultStates
),
new OrderedArrayAttribute(
new CharSeparatedCompositeAttribute(
_('Labels for custom substates'),
'fdSupannRessourceSubStatesLabels',
[
new SelectAttribute(
_('Substatus'), _('LDAP value for this substatus'),
'fdSupannRessourceSubStatesLabels_substatus', TRUE
),
new StringAttribute(
_('Label'), _('Label shown for this substatus'),
'fdSupannRessourceSubStatesLabels_label', TRUE
),
],
':',
'',
_('Custom labels')
),
FALSE,
[],
TRUE
),
]
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
global $config;
parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['fdSupannRessourceSubStates']->setSubmitForm('updateFieldsChoices');
$this->officialSubstates = array_merge(...array_values(array_map('array_keys', supannAccountStatus::getOfficialSubstates())));
$this->updateFieldsChoices();
}
function updateFieldsChoices ()
{
$substateChoices = [];
foreach ($this->fdSupannRessourceSubStates as $line) {
list($state, $substate) = explode(':', $line, 2);
if (!in_array($substate, $this->officialSubstates)) {
$substateChoices[] = $substate;
}
}
$this->attributesAccess['fdSupannRessourceSubStatesLabels']->attribute->attributes[0]->setChoices(
$substateChoices
);
}
}
......@@ -16,9 +16,24 @@ attributetype ( 1.3.6.1.4.1.38414.17.1.2 NAME 'fdSupannPasswordRecovery'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.17.1.3 NAME 'fdSupannRessourceSubStates'
DESC 'FusionDirectory - SupAnn supannRessourceEtatDate allowed substates'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
attributetype ( 1.3.6.1.4.1.38414.17.1.4 NAME 'fdSupannRessourceSubStatesLabels'
DESC 'FusionDirectory - SupAnn labels for custom supannRessourceEtatDate substates'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)
# Object Class
objectclass ( 1.3.6.1.4.1.38414.17.2.1 NAME 'fdSupannPluginConf'
DESC 'FusionDirectory SupAnn plugin configuration'
SUP top AUXILIARY
MUST ( cn )
MAY ( fdSupannStructuresRDN $ fdSupannPasswordRecovery ) )
MAY (
fdSupannStructuresRDN $ fdSupannPasswordRecovery $
fdSupannRessourceSubStates $ fdSupannRessourceSubStatesLabels
) )
......@@ -105,26 +105,7 @@ class supannAccountStatus extends simplePlugin
parent::__construct($dn, $object, $parent, $mainTab);
$this->substatus = [
'A' => [
'SupannAnticipe' => _('Anticipated'),
'SupannActif' => _('Active'),
'SupannSursis' => _('Extension'),
],
'I' => [
'SupannPrecree' => _('Precreated'),
'SupannCree' => _('Created'),
'SupannExpire' => _('Expired'),
'SupannInactif' => _('Inactive'),
'SupannSupprDonnees' => _('Data deletion'),
'SupannSupprCompte' => _('Account deletion'),
],
'S' => [
'SupannVerrouille' => _('Locked'),
'SupannVerrouAdministratif' => _('Administrative lock'),
'SupannVerrouTechnique' => _('Technical lock'),
],
];
$this->substatus = static::getConfiguredSubstates();
$this->attributesAccess['supannRessourceEtatDate']->setLinearRendering(FALSE);
$this->attributesAccess['supannRessourceEtatDate']->setRequired(TRUE);
......@@ -199,4 +180,61 @@ class supannAccountStatus extends simplePlugin
return $errors;
}
static function getOfficialSubstates (): array
{
return [
'A' => [
'SupannAnticipe' => _('Anticipated'),
'SupannActif' => _('Active'),
'SupannSursis' => _('Extension'),
],
'I' => [
'SupannPrecree' => _('Precreated'),
'SupannCree' => _('Created'),
'SupannExpire' => _('Expired'),
'SupannInactif' => _('Inactive'),
'SupannSupprDonnees' => _('Data deletion'),
'SupannSupprCompte' => _('Account deletion'),
],
'S' => [
'SupannVerrouille' => _('Locked'),
'SupannVerrouAdministratif' => _('Administrative lock'),
'SupannVerrouTechnique' => _('Technical lock'),
],
];
}
static function getConfiguredSubstates (): array
{
global $config;
$officialSubstates = static::getOfficialSubstates();
$substates = [
'A' => [],
'I' => [],
'S' => [],
];
$labels = [];
foreach ($config->get_cfg_value('SupannRessourceSubStatesLabels', []) as $line) {
list($substate,$label) = explode(':', $line, 2);
$labels[$substate] = $label;
}
foreach ($config->get_cfg_value('SupannRessourceSubStates', []) as $line) {
list(,$state,$substate) = explode(':', $line, 3);
if (isset($officialSubstates[$state][$substate])) {
$substates[$state][$substate] = $officialSubstates[$state][$substate];
} elseif (isset($labels[$substate])) {
$substates[$state][$substate] = $labels[$substate];
} else {
$substates[$state][$substate] = $substate;
}
}
return $substates;
}
}
Markdown is supported
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