Commit 08a70bd1 authored by Côme Chilliet's avatar Côme Chilliet

feat(supann) Add support for supannCMSAppAffectation

And the associated fields

issue #6015
parent 80bf781c
......@@ -136,6 +136,32 @@ class supannConfig extends simplePlugin
'/^.+@.+$/', 'unicampus@univ.example.com'
)
),
new OrderedArrayAttribute(
new CharSeparatedCompositeAttribute(
_('Domains for card applications'),
'fdSupannCMSAppDomains',
[
new StringAttribute(
_('Option'), _('Attribute option to use, starting with x-'),
'fdSupannCMSAppDomains_option', TRUE,
'', '',
'/^x-.+$/', 'x-biblio-xlsb'
),
new StringAttribute(
_('Domain'), _('Domain to use'),
'fdSupannCMSAppDomains_domain', TRUE,
'', '',
'', 'xlsb.biblio.univ.example.com'
),
],
';',
'',
_('Card application domains')
),
FALSE,
[],
TRUE
),
]
],
];
......
......@@ -40,6 +40,12 @@ attributetype ( 1.3.6.1.4.1.38414.17.1.6 NAME 'fdSupannCMSSources'
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)
attributetype ( 1.3.6.1.4.1.38414.17.1.7 NAME 'fdSupannCMSAppDomains'
DESC 'FusionDirectory - SupAnn possible domains for card applications - format option;domain'
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'
......@@ -48,5 +54,5 @@ objectclass ( 1.3.6.1.4.1.38414.17.2.1 NAME 'fdSupannPluginConf'
MAY (
fdSupannStructuresRDN $ fdSupannPasswordRecovery $
fdSupannRessourceSubStates $ fdSupannRessourceSubStatesLabels $ fdSupannRessourceLabels $
fdSupannCMSSources
fdSupannCMSSources $ fdSupannCMSAppDomains
) )
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2010-2012 Antoine Gallavardin
Copyright (C) 2013-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 SupannCMSAppAffectationAttribute extends SupannCompositeAttribute
{
function __construct ($label, $description, $ldapName, $acl = '')
{
global $config;
list($types, $typeLabels) = supann::get_choices_for('cmstype');
$attributes = [
new SelectAttribute(
_('Type'), _('supannCMSType - Card type'),
'supannCMSType_type', TRUE,
$types, '', $typeLabels
),
new SelectAttribute(
_('Source'), _('Card managing system and establishment'),
'supannCMSSource_source', TRUE,
$config->get_cfg_value('supannCMSSources', [])
),
new SelectAttribute(
_('Domain'), _('Application domain'),
'none_domaine', TRUE,
array_column($this->getConfigAppDomains(), 1)
),
new StringAttribute(
_('Id'), _('Application id'),
'none_id', TRUE
),
new BooleanAttribute(
_('Valid'), _('Application validity'),
'none_valide', TRUE,
TRUE, '',
'vrai', 'faux'
),
new GeneralizedTimeDateAttribute(
_('End date'), _('End of validity date, if any'),
'supannCMSDateFin_datefin', FALSE,
''
),
];
parent::__construct($description, $ldapName, $attributes, $acl, $label);
}
protected function isValid (): bool
{
return ($this->attributes[4]->getValue() === TRUE);
}
protected function getConfigAppDomains (): array
{
global $config;
return array_map(
function ($supannCMSAppDomain) {
return explode(';', $supannCMSAppDomain, 2);
},
$config->get_cfg_value('supannCMSAppDomains', [])
);
}
function supannGetValues (&$values)
{
foreach ($this->attributes as &$attribute) {
$shortname = preg_replace('/^([^_]+)_.*$/', '\\1', $attribute->getLdapName());
if ($shortname == 'none') {
continue;
}
$value = $attribute->getValue();
if (!isset($values[$shortname])) {
$values[$shortname] = [];
}
if ($value == '') {
continue;
}
if ($this->isValid()) {
$values[$shortname][$value] = $value;
}
}
unset($attribute);
if ($this->isValid()) {
$domains = array_column($this->getConfigAppDomains(), 0, 1);
$domain = $this->attributes[2]->getValue();
$id = $this->attributes[3]->getValue();
$supannCMSAppIdDomaine = $id.'@'.$domain;
$supannCMSAppId = $domains[$domain].';'.$id;
$values['supannCMSAppIdDomaine'][$supannCMSAppIdDomaine] = $supannCMSAppIdDomaine;
$values['supannCMSAppId'][$supannCMSAppId] = $supannCMSAppId;
} else {
if (!isset($values['supannCMSAppIdDomaine'])) {
$values['supannCMSAppIdDomaine'] = [];
}
if (!isset($values['supannCMSAppId'])) {
$values['supannCMSAppId'] = [];
}
}
}
}
......@@ -22,7 +22,7 @@
class SupannOrderedArrayAttribute extends OrderedArrayAttribute
{
function supannPrepareSave ()
public function supannPrepareSave (bool $append = FALSE)
{
$values = [];
foreach ($this->value as $value) {
......@@ -33,7 +33,12 @@ class SupannOrderedArrayAttribute extends OrderedArrayAttribute
if ($this->plugin->attributesAccess[$ldapName]->isVisible()) {
continue;
}
$this->plugin->attributesAccess[$ldapName]->setValue(array_values($array));
if ($append) {
$newValues = array_unique(array_merge($this->plugin->attributesAccess[$ldapName]->getValue(), array_values($array)));
} else {
$newValues = array_values($array);
}
$this->plugin->attributesAccess[$ldapName]->setValue($newValues);
}
}
}
......@@ -42,7 +42,7 @@ class supannCMS extends simplePlugin
static function getAttributesInfo (): array
{
return [
'status' => [
'cards' => [
'name' => _('Cards'),
'class' => ['fullwidth'],
'attrs' => [
......@@ -64,6 +64,25 @@ class supannCMS extends simplePlugin
),
]
],
'apps' => [
'name' => _('Applications'),
'class' => ['fullwidth'],
'attrs' => [
new TaggedAttribute(new StringAttribute('', '', 'supannCMSAppId', FALSE)),
new HiddenArrayAttribute('supannCMSAppIdDomaine', FALSE, []),
new SupannOrderedArrayAttribute(
new SupannCMSAppAffectationAttribute(
_('Applications'), _('SupAnn CMS Application Affectation'),
'supannCMSAppAffectation'
),
// no order
FALSE,
[],
// edit button
TRUE
),
]
],
];
}
......@@ -74,6 +93,7 @@ class supannCMS extends simplePlugin
parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['supannCMSId']->setVisible(FALSE);
$this->attributesAccess['supannCMSAppId']->setVisible(FALSE);
$this->attributesAccess['supannCMSAffectation']->setLinearRendering(FALSE);
$this->attributesAccess['supannCMSAffectation']->setHeaders([
_('Type'),
......@@ -84,11 +104,26 @@ class supannCMS extends simplePlugin
_('End date'),
''
]);
$this->attributesAccess['supannCMSAppAffectation']->setLinearRendering(FALSE);
$this->attributesAccess['supannCMSAppAffectation']->setHeaders([
_('Type'),
_('Source'),
_('Domain'),
_('Id'),
_('Valid'),
_('End date'),
''
]);
}
protected function prepare_save (): array
{
$this->attributesAccess['supannCMSAffectation']->supannPrepareSave();
/* Both composite use common attributes, so we use append mode of supannPrepareSave,
* but we need to empty application specific fields first */
$this->supannCMSAppId = [];
$this->supannCMSAppIdDomaine = [];
$this->attributesAccess['supannCMSAppAffectation']->supannPrepareSave(TRUE);
return parent::prepare_save();
}
}
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