diff --git a/include/simpleplugin/class_multiPlugin.inc b/include/simpleplugin/class_multiPlugin.inc index 42587b1f29dbbb60bf7faa7a772f667e81690fc1..1fb9512cf4043b2482487b2058f9f9fc035e6475 100644 --- a/include/simpleplugin/class_multiPlugin.inc +++ b/include/simpleplugin/class_multiPlugin.inc @@ -2,7 +2,7 @@ /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) Copyright (C) 2003-2010 Cajus Pollmeier - Copyright (C) 2011-2016 FusionDirectory + Copyright (C) 2011-2021 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 @@ -19,207 +19,50 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -/*! \brief multiPlugin - This class provides the functionality to have multiple plugins in a single tab +/** + * This class allows to have a simplePlugin instance which sections are dynamically loaded from other classes + * + * It is used for configuration plugins tab */ - class multiPlugin extends simplePlugin { - /* attribute list for save action */ - var $objectclasses = []; protected $ignore_account = TRUE; - var $plugin = []; - var $tabClass = ''; + protected static $tabClass = ''; static function getAttributesInfo (): array { return []; } - function __construct ($dn = NULL, $object = NULL, $parent = NULL) + function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE) { global $config; - parent::__construct($dn, $object, $parent, FALSE); - $plInfos = pluglist::pluginInfos(get_class($this)); + $attributesInfo = []; - /* Load accounts */ - foreach ($config->data['TABS'][$this->tabClass] as $plug) { + /* Load sections */ + foreach ($config->data['TABS'][static::$tabClass] as $plug) { if (!plugin_available($plug['CLASS'])) { continue; } - $name = $plug['CLASS']; - $this->plugin[$name] = new $name($dn, $object, $parent); + $plInfos = pluglist::pluginInfos($plug['CLASS']); - /* Acl base && category configuration, - these settings will be overloaded in main.inc, - if we are editing ourself */ - $this->plugin[$name]->set_acl_category($plInfos['plCategory'][0]); - } - } - - function aclHasPermissions (): bool - { - foreach ($this->plugin as $plug) { - if (!$plug->aclHasPermissions()) { - /* If one of our plugins has no permission handling (always shown), we do not either */ - return FALSE; + if (isset($plInfos['plObjectClass'])) { + $this->objectclasses = array_merge_unique($this->objectclasses, $plInfos['plObjectClass']); } - } - - return TRUE; - } - function aclGetPermissions ($attribute = '0', string $base = NULL, bool $skipWrite = FALSE): string - { - if (isset($this->parent) && isset($this->parent->ignoreAcls) && $this->parent->ignoreAcls) { - return 'cdmr'.($skipWrite ? '' : 'w'); + $attributesInfo = array_merge($attributesInfo, $plug['CLASS']::getAttributesInfo()); } - $skipWrite |= $this->readOnly(); - if ($base === NULL) { - $base = $this->getAclBase(); - } - - $acl = ''; - foreach ($this->plugin as $plug) { - $acl .= $plug->aclGetPermissions($attribute, $base, $skipWrite); - } - - return implode('', array_unique(str_split($acl))); - } - - public function readPost () - { - foreach ($this->plugin as $plug) { - $plug->readPost(); - } - } - - public function update (): bool - { - foreach ($this->plugin as $plug) { - $plug->update(); - } - return TRUE; - } - - public function render (): string - { - $display = ''; - - /* Do we represent a valid account? */ - if ($this->parent === NULL) { - $enabled = FALSE; - foreach ($this->plugin as $plug) { - if ($plug->is_account) { - $enabled = TRUE; - break; - } - } - if (!$enabled) { - $display = '<img alt="'._('Error').'" src="geticon.php?context=status&icon=dialog-error&size=16" align="middle"/> <b>'. - msgPool::noValidExtension('').'</b>'; - return $display; - } - } - - /* Display plugins */ - $readOnly = $this->readOnly(); - - foreach ($this->plugin as $plug) { - $plug->read_only = $readOnly; - $display .= $plug->render(); - } - - return $display; - } + parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo); - function check (): array - { - $errors = parent::check(); - - foreach ($this->plugin as &$plug) { - if ($plug->isActive()) { - $tmp = $plug->check(); - $errors = array_merge($errors, $tmp); - } - } - unset($plug); - - return $errors; - } - - function set_acl_category (string $cat) - { - parent::set_acl_category($cat); - foreach ($this->plugin as &$plug) { - $plug->set_acl_category($cat); - } - unset($plug); - } - - public function setNeedEditMode (bool $bool) - { - parent::setNeedEditMode($bool); - foreach ($this->plugin as &$plug) { - $plug->setNeedEditMode($bool); - } - unset($plug); - } - - /* Save to LDAP */ - function save (): array - { - $errors = []; - /* Save objects */ - foreach ($this->plugin as &$plug) { - $plug->dn = $this->dn; - if ($plug->isActive()) { - $result = $plug->save(); - } else { - $result = $plug->remove(FALSE); - } - if (!empty($result)) { - $errors = array_merge($errors, $result); - } - } - unset($plug); - return $errors; - } - - function remove (bool $fulldelete = FALSE): array - { - $errors = []; - /* Remove objects */ - foreach ($this->plugin as &$plug) { - $plug->dn = $this->dn; - $result = $plug->remove($fulldelete); - if (!empty($result)) { - $errors = array_merge($errors, $result); + /* Load sections */ + foreach ($config->data['TABS'][static::$tabClass] as $plug) { + if (!plugin_available($plug['CLASS'])) { + continue; } + $plug['CLASS']::fixAttributesOnLoad($this); } - unset($plug); - return $errors; - } - - function adapt_from_template (array $attrs, array $skip = []) - { - /* Adapt objects */ - foreach ($this->plugin as &$plug) { - $plug->dn = $this->dn; - $plug->adapt_from_template($attrs, $skip); - } - unset($plug); - } - - function resetCopyInfos () - { - $this->dn = 'new'; - foreach ($this->plugin as &$plug) { - $plug->resetCopyInfos(); - } - unset($plug); } } diff --git a/include/simpleplugin/class_multiPluginSection.inc b/include/simpleplugin/class_multiPluginSection.inc new file mode 100644 index 0000000000000000000000000000000000000000..eceb5274364665361f429c6af0694e7764aa74c9 --- /dev/null +++ b/include/simpleplugin/class_multiPluginSection.inc @@ -0,0 +1,44 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2021-2021 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. +*/ + +/** + * Base class for multiPlugin sections + */ +abstract class multiPluginSection +{ + static function plInfo (): array + { + return []; + } + + static abstract function getAttributesInfo (): array; + + static function generatePlProvidedAcls (array $attributesInfo, bool $operationalAttributes = NULL): array + { + return simplePlugin::generatePlProvidedAcls($attributesInfo, $operationalAttributes); + } + + /** + * If the section needs to initialize something after LDAP load + */ + static function fixAttributesOnLoad (multiPlugin $multiPlugin) + { + } +} diff --git a/plugins/config/class_dashBoardConfig.inc b/plugins/config/class_dashBoardConfig.inc index 3290ddce4d3b9cbaba43092bb802b5288567d778..a74e23110d4b40e2c97456919815073c0e6970fa 100644 --- a/plugins/config/class_dashBoardConfig.inc +++ b/plugins/config/class_dashBoardConfig.inc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class dashboardConfig extends simplePlugin +class dashboardConfig extends multiPluginSection { static function plInfo (): array { diff --git a/plugins/config/class_mainPluginsConfig.inc b/plugins/config/class_mainPluginsConfig.inc index f55a85ec925f2615e84d6d187be8f6d54c828061..6bfd4c6eca15d3569e6c2ff8ae1d65f22880baba 100644 --- a/plugins/config/class_mainPluginsConfig.inc +++ b/plugins/config/class_mainPluginsConfig.inc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class mainPluginsConfig extends simplePlugin +class mainPluginsConfig extends multiPluginSection { static function plInfo (): array { diff --git a/plugins/config/class_pluginsConfigInLdap.inc b/plugins/config/class_pluginsConfigInLdap.inc index da098e04c57b0412e491b62cf61f3977f32371fa..1fb9ea1f9b9f51225a53365ed8f52ffaaee32b40 100644 --- a/plugins/config/class_pluginsConfigInLdap.inc +++ b/plugins/config/class_pluginsConfigInLdap.inc @@ -20,7 +20,7 @@ class pluginsConfigInLdap extends multiPlugin { - var $tabClass = 'SMALLCONFIGTABS'; + protected static $tabClass = 'SMALLCONFIGTABS'; static function plInfo (): array { @@ -31,6 +31,9 @@ class pluginsConfigInLdap extends multiPlugin 'plObjectType' => ['configuration'], 'plSubTabs' => 'SMALLCONFIGTABS', + /* This is incomplete because of dynamic loading, but is enough to generate a filter for this tab */ + 'plObjectClass' => ['fusionDirectoryPluginsConf'], + 'plProvidedAcls' => [] ]; }