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

Merge branch '5980-management-should-be-a-bit-more-flexible' into '1.4-dev'

Resolve "Management should be a bit more flexible"

See merge request fusiondirectory/fd!571
parents 05886b46 fbe8a885
......@@ -176,7 +176,7 @@ class Action
return;
}
if (!$this->hasPermission($this->parent->listing->getBase())) {
if (!$this->hasPermission()) {
return;
}
......@@ -204,7 +204,7 @@ class Action
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($entry->dn, $entry->getTemplatedType(), $entry->isTemplate())) {
if (!$this->hasPermission($entry)) {
return '<img src="images/empty.png" alt=" " class="optional"/>';
}
......@@ -226,14 +226,18 @@ class Action
return TRUE;
}
function hasPermission (string $dn, string $type = NULL, bool $template = FALSE): bool
function hasPermission (ListingEntry $entry = NULL): bool
{
global $ui;
if ($type === NULL) {
$types = $this->parent->objectTypes;
if ($entry === NULL) {
$dn = $this->parent->listing->getBase();
$types = $this->parent->objectTypes;
$template = FALSE;
} else {
$types = [$type];
$dn = $entry->dn;
$types = [$entry->getTemplatedType()];
$template = $entry->isTemplate();
}
/*
* if category is missing it’s deducted from type (all types are tested for menu actions)
......
......@@ -70,6 +70,9 @@ class management
public static $skipTemplates = TRUE;
/* Disable and hide configuration system */
protected $skipConfiguration = FALSE;
/* Default columns */
public static $columns = [
['ObjectTypeColumn', []],
......@@ -317,7 +320,9 @@ class management
$this->registerAction(new HiddenAction('cancel', 'cancelEdit'));
$this->registerAction(new HiddenAction('cancelDelete', 'cancelEdit'));
$this->registerAction(new HiddenAction('removeConfirmed', 'removeConfirmed'));
$this->registerAction(new HiddenAction('configure', 'configureDialog'));
if (!$this->skipConfiguration) {
$this->registerAction(new HiddenAction('configure', 'configureDialog'));
}
}
/*!
......@@ -491,7 +496,7 @@ class management
$smarty->assign('FILTER', $filterRender);
$smarty->assign('ACTIONS', $actionMenu);
$smarty->assign('SIZELIMIT', $ui->getSizeLimitHandler()->renderWarning());
$smarty->assign('NAVIGATION', $this->listing->renderNavigation());
$smarty->assign('NAVIGATION', $this->listing->renderNavigation($this->skipConfiguration));
$smarty->assign('BASE', $this->listing->renderBase());
$smarty->assign('HEADLINE', $this->headline);
......@@ -787,9 +792,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)
{
......@@ -986,7 +991,9 @@ class management
function configureDialog (array $action)
{
$this->dialogObject = new ManagementConfigurationDialog($this);
if (!$this->skipConfiguration) {
$this->dialogObject = new ManagementConfigurationDialog($this);
}
}
/*! \brief This method is used to queue and process copy&paste actions.
......
......@@ -359,28 +359,28 @@ class managementListing
return $this->baseSelector->render();
}
function renderNavigation (): array
function renderNavigation (bool $skipConfiguration = FALSE): array
{
$enableBack = TRUE;
$enableRoot = TRUE;
$enableHome = TRUE;
global $ui;
$ui = get_userinfo();
if ($this->baseMode) {
$enableBack = TRUE;
$enableRoot = TRUE;
$enableHome = TRUE;
/* Check if base = first available base */
$deps = array_keys($this->bases);
/* Check if base = first available base */
$deps = array_keys($this->bases);
if (!count($deps) || $deps[0] == $this->base) {
$enableBack = FALSE;
$enableRoot = FALSE;
}
if (!count($deps) || $deps[0] == $this->base) {
$enableBack = FALSE;
$enableRoot = FALSE;
}
/* Check if we are in users home department */
if (!count($deps) || ($this->base == $ui->getBase()) || !in_array_ics($ui->getBase(), $deps)) {
$enableHome = FALSE;
}
/* Check if we are in users home department */
if (!count($deps) || ($this->base == $ui->getBase()) || !in_array_ics($ui->getBase(), $deps)) {
$enableHome = FALSE;
}
if ($this->baseMode) {
$actions = [
[
'id' => 'ROOT',
......@@ -410,6 +410,7 @@ class managementListing
} else {
$actions = [];
}
$actions[] = [
'id' => 'REFRESH',
'desc' => _('Reload list'),
......@@ -418,14 +419,17 @@ class managementListing
'enabled' => TRUE,
'class' => 'optional',
];
$actions[] = [
'id' => 'listing_configure',
'desc' => _('Configure this management list'),
'name' => _('Configure'),
'icon' => 'geticon.php?context=categories&icon=settings&size=16',
'enabled' => TRUE,
'class' => '',
];
if (!$skipConfiguration) {
$actions[] = [
'id' => 'listing_configure',
'desc' => _('Configure this management list'),
'name' => _('Configure'),
'icon' => 'geticon.php?context=categories&icon=settings&size=16',
'enabled' => TRUE,
'class' => '',
];
}
return $actions;
}
......
......@@ -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
{
/*
* 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;
}
......@@ -49,7 +49,7 @@ class LockAction extends Action
return;
}
if (!$this->hasPermission($this->parent->listing->getBase())) {
if (!$this->hasPermission()) {
return;
}
......@@ -84,7 +84,7 @@ class LockAction extends Action
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($entry->dn, $entry->getTemplatedType(), $entry->isTemplate())) {
if (!$this->hasPermission($entry)) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
}
......
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