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

feat(simpleplugin) Added simpleTab interface to ease servicesManagement implementation

Now all tabs of a simpleTabs instance have to implement the simpleTab
 interface.

issue #5980
parent 05886b46
......@@ -787,9 +787,9 @@ class management
/*!
* \brief This method opens an existing object to be edited.
*
* \param array $action A combination of both 'action' and 'target':
* \param array $action A combination of both 'action' and 'targets':
* action: The name of the action which was the used as trigger.
* target: A list of object dns, which should be affected by this method.
* targets: A list of object dns, which should be affected by this method.
*/
function editEntry (array $action)
{
......
......@@ -134,7 +134,7 @@ class multiPlugin extends simplePlugin
unset($plug);
}
function set_acl_base ($base)
function set_acl_base (string $base)
{
parent::set_acl_base($base);
foreach ($this->plugin as &$plug) {
......@@ -143,7 +143,7 @@ class multiPlugin extends simplePlugin
unset($plug);
}
public function setNeedEditMode ($bool)
public function setNeedEditMode (bool $bool)
{
parent::setNeedEditMode($bool);
foreach ($this->plugin as &$plug) {
......
......@@ -27,7 +27,7 @@
/*! \brief This class is made for easy plugin creation for editing LDAP attributes
*
*/
class simplePlugin
class simplePlugin implements simpleTab
{
/*! \brief This attribute store all information about attributes */
public $attributesInfo;
......@@ -568,7 +568,7 @@ class simplePlugin
*
* \param string $base
*/
function set_acl_base ($base)
function set_acl_base (string $base)
{
$this->acl_base = $base;
}
......@@ -904,7 +904,7 @@ class simplePlugin
$this->dialog = NULL;
}
public function setNeedEditMode ($bool)
public function setNeedEditMode (bool $bool)
{
$this->needEditMode = $bool;
}
......
......@@ -54,14 +54,10 @@ class simpleTabs
/*!
* \brief Tabs classes constructor
* */
function __construct ($type, $dn, $attrs_object = NULL)
function __construct (string $type, $dn, $attrs_object = NULL)
{
global $config;
if (!is_string($type)) {
die('deprecated call to old tabclass constructor');
}
$infos = objects::infos($type);
$data = $config->data['TABS'][$infos['tabGroup']];
$this->acl_category = $infos['aclCategory'];
......@@ -80,6 +76,9 @@ class simpleTabs
if (!plugin_available($tab['CLASS'])) {
continue;
}
if (!is_a($tab['CLASS'], 'simpleTab', TRUE)) {
throw new FusionDirectoryException('Invalid class '.$tab['CLASS'].' found in '.$type.' tab list');
}
$this->by_name[$tab['CLASS']] = $tab['NAME'];
$this->plNotify[$tab['CLASS']] = FALSE;
......@@ -165,10 +164,6 @@ class simpleTabs
if (isset($baseobject->base)) {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $baseobject->base, 'Fixing base');
$baseobject->base = $ui->getCurrentBase();
if (!($baseobject instanceOf simplePlugin) && is_object($baseobject->baseSelector)) {
/* For some plugins not yet migrated to simple plugin. */
$baseobject->baseSelector->setBase($baseobject->base);
}
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $baseobject->base, 'Fixed base');
} else {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, '', 'no base');
......@@ -418,23 +413,19 @@ class simpleTabs
$obj->dn = $this->dn;
if (!($obj instanceof simplePlugin) && !($obj instanceOf simpleManagement)) {
trigger_error('Something went wrong while saving '.$obj->dn.'. Class "'.get_class($obj).'".');
if ($obj->is_account || $obj->ignore_account) {
$result = $obj->save();
} else {
if ($obj->is_account || $obj->ignore_account) {
$result = $obj->save();
} else {
$result = $obj->remove(FALSE);
}
if (!empty($result)) {
if ($creation && $first) {
/* If the save of main tab fails for a creation, cancel the save of other tabs */
$this->dn = $old_dn;
$obj->dn = $this->dn;
return $result;
}
$errors = array_merge($errors, $result);
$result = $obj->remove(FALSE);
}
if (!empty($result)) {
if ($creation && $first) {
/* If the save of main tab fails for a creation, cancel the save of other tabs */
$this->dn = $old_dn;
$obj->dn = $this->dn;
return $result;
}
$errors = array_merge($errors, $result);
}
if ($first) {
$first = FALSE;
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2018-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
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.
*/
/*!
* \file interface_simpleTab.inc
* Source code for the interface simpleTab
*/
/*! \brief This interface is implemented by classes intended to be used as tabs, mainly simplePlugin itself.
*/
interface simpleTab
  • 🔽 Rename this interface name to match the regular expression ^[A-Z][a-zA-Z0-9]*$. 📘

Please register or sign in to reply
{
/*
* Public vars expected as well by classes implementing this interface:
* bool $is_account
* bool $ignore_account
* string $dn
* bool $is_template
* string $_template_cn (only for main tab of templates)
* array $attributesAccess (only for main tab of templates)
* simpleTabs $parent
* string $acl_base
*/
/*
* Public methods needed in some cases:
* compute_dn (): string (only for main tab)
* move (string $src_dn, string $dst_dn): TRUE|string (only for main tab)
*/
public static function plInfo (): array;
/*! \brief This function returns the html code to display for this tab
*/
public function execute (): string;
/*! \brief Save information from POST if needed
*/
public function save_object ();
/*! \brief Checks data and return errors
*/
public function check (): array;
/*! \brief Delete tab data from LDAP and return errors
*/
public function remove (bool $fulldelete = FALSE): array;
/*! \brief Save data to the LDAP and return errors
*/
public function save (): array;
/*! \brief Reset information after a copy/paste
*/
public function resetCopyInfos ();
/*! \brief Forward plugin acls
*/
public function set_acl_base (string $base);
/*! \brief Sets ACL category provided by simpleTabs
*/
public function set_acl_category (string $category);
/*!
* \brief Can we delete the object
*
* Only used on main tab
*
* \param string $base
*/
public function acl_is_removeable (string $base = NULL): bool;
/*!
* \brief Sets whether the opened objet is a template
*
* \param bool $isTemplate
*/
public function setTemplate (bool $isTemplate);
/*!
* \brief Sets whether the opened objet has an edit button
*
* \param bool $needEditMode
*/
public function setNeedEditMode (bool $needEditMode);
/*!
* \brief Is there a modal dialog opened
*/
public function is_modal_dialog (): bool;
/*!
* \brief Returns list of required LDAP attributes
*
* Used by template
*/
public function getRequiredAttributes (): array;
/*!
* \brief Returns TRUE if this attribute should be asked in the creation by template dialog
*/
public function showInTemplate (string $attr, array $templateAttrs): bool;
/*!
* \brief Adapt from template
*/
public function adapt_from_template (array $attrs, array $skip = []);
/*!
* \brief Deserialize values
*/
public function deserializeValues (array $values, bool $checkAcl = TRUE);
/*!
* \brief Get the acl permissions for an attribute or the plugin itself
*/
public function aclGetPermissions ($attribute = '0', string $base = NULL, bool $skipWrite = FALSE): string;
/*!
* \brief Merge in objectClasses needed by this tab
*
* Used by prepare_save and template::apply
*/
public function mergeObjectClasses (array $oc): array;
}
  • SonarQube analysis reported 1 issue

    • 🔽 1 minor

    Watch the comments in this conversation to review them.

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