Commit 9c4df519 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5986-add-a-reinitialisation-button-for-the-management-configuration' into '1.4-dev'

Resolve "Add a reinitialisation button for the management configuration"

See merge request fusiondirectory/fd!605
parents d8add249 aaef9aa6
......@@ -537,11 +537,10 @@ class config
/*!
* \brief Update the management config in the LDAP and the cache
*/
public function updateManagementConfig (string $managementClass, array $managementConfig, bool $userConfig = FALSE): array
public function updateManagementConfig (string $managementClass, $managementConfig, bool $userConfig = FALSE): array
{
global $ui;
$managementConfig = json_encode($managementConfig);
$changes = [];
if ($userConfig) {
if (!isset($this->current['MANAGEMENTUSERCONFIG'][$ui->dn])) {
......@@ -558,9 +557,14 @@ class config
$attrib = 'fdManagementConfig';
$prefix = $managementClass;
}
if ($managementConfig !== NULL) {
$managementConfig = json_encode($managementConfig);
}
if (isset($currentConfig[$managementClass])) {
/* If there already was a config for this class, remove it */
if ($currentConfig[$managementClass] == $managementConfig) {
if ($currentConfig[$managementClass] === $managementConfig) {
/* Unless it's the same one and we've got nothing to do */
return [];
}
......@@ -570,21 +574,44 @@ class config
'values' => [$prefix.':'.$currentConfig[$managementClass]],
];
}
/* Add the new one */
$changes[] = [
'attrib' => $attrib,
'modtype' => LDAP_MODIFY_BATCH_ADD,
'values' => [$prefix.':'.$managementConfig],
];
if ($managementConfig !== NULL) {
/* Add the new one, if any */
$changes[] = [
'attrib' => $attrib,
'modtype' => LDAP_MODIFY_BATCH_ADD,
'values' => [$prefix.':'.$managementConfig],
];
}
$ldap = $this->get_ldap_link();
$ldap->cd(CONFIGRDN.$this->current['BASE']);
if (!$ldap->modify_batch($changes)) {
return [$ldap->get_error()];
}
$currentConfig[$managementClass] = $managementConfig;
if ($managementConfig !== NULL) {
$currentConfig[$managementClass] = $managementConfig;
} else {
unset($currentConfig[$managementClass]);
}
return [];
}
/*!
* \brief Test if there is a stored management config
*/
public function hasManagementConfig (string $managementClass, bool $userConfig = FALSE): bool
{
global $ui;
if ($userConfig) {
return isset($this->current['MANAGEMENTUSERCONFIG'][$ui->dn][$managementClass]);
} else {
return isset($this->current['MANAGEMENTCONFIG'][$managementClass]);
}
}
/*!
* \brief Returns the config for a management class, or NULL
*/
......
......@@ -88,12 +88,24 @@ class ManagementConfigurationDialog extends ManagementDialog
FALSE,
'ManagementConfiguration'
),
new ButtonAttribute(
_('Forget my persistent configuration'), _('Delete the persistent configuration for this management page so that the default one is used'),
'resetInLdapUser', _('Forget'),
NULL, '',
'ManagementConfiguration'
),
new BooleanAttribute(
_('Global default'), _('Should this configuration be saved in the LDAP as the default configuration for this management page for all users'),
'saveInLdap', FALSE,
FALSE,
'fdManagementConfig'
),
new ButtonAttribute(
_('Forget global default'), _('Delete the global default configuration for this management page so that the default one is used'),
'resetInLdap', _('Forget'),
NULL, '',
'fdManagementConfig'
),
]
],
];
......@@ -101,12 +113,28 @@ class ManagementConfigurationDialog extends ManagementDialog
function __construct (management $parent)
{
global $config;
parent::__construct(NULL, NULL, $parent);
$this->attributesAccess['saveInLdap']->setInLdap(FALSE);
$this->attributesAccess['saveInLdapUser']->setInLdap(FALSE);
if (!$this->attrIsWriteable('saveInLdap')) {
$this->attributesAccess['saveInLdap']->setVisible(FALSE);
}
$this->attributesAccess['resetInLdap']->setInLdap(FALSE);
$this->attributesAccess['resetInLdapUser']->setInLdap(FALSE);
if (!$this->attrIsWriteable('resetInLdap')) {
$this->attributesAccess['resetInLdap']->setVisible(FALSE);
}
if (!$config->hasManagementConfig(get_class($this->parent), TRUE)) {
$this->attributesAccess['resetInLdapUser']->setVisible(FALSE);
}
if (!$config->hasManagementConfig(get_class($this->parent), FALSE)) {
$this->attributesAccess['resetInLdap']->setVisible(FALSE);
}
$this->attributesAccess['managementColumns']->setInLdap(FALSE);
$this->attributesAccess['managementColumns']->setLinearRendering(FALSE);
$columnInfos = $this->parent->getColumnConfiguration();
......@@ -129,11 +157,12 @@ class ManagementConfigurationDialog extends ManagementDialog
{
global $config, $ui;
$noAclAttrs = ['managementColumns', 'saveInLdapUser'];
$noAclAttrs = ['managementColumns', 'saveInLdapUser', 'resetInLdapUser'];
$configAttrs = ['saveInLdap', 'resetInLdap'];
if ((is_object($attr) && in_array($attr->getLdapName(), $noAclAttrs)) || in_array($attr, $noAclAttrs)) {
return TRUE;
} elseif (($attr === 'saveInLdap') || (is_object($attr) && ($attr->getLdapName() == 'saveInLdap'))) {
} elseif ((is_object($attr) && in_array($attr->getLdapName(), $configAttrs)) || in_array($attr, $configAttrs)) {
$acl = $ui->get_permissions(CONFIGRDN.$config->current['BASE'], 'configuration/configInLdap', 'fdManagementConfig', $this->readOnly());
return (strpos($acl, 'w') !== FALSE);
} else {
......@@ -141,6 +170,26 @@ class ManagementConfigurationDialog extends ManagementDialog
}
}
function handle_resetInLdapUser ()
{
global $config;
$errors = $config->updateManagementConfig(get_class($this->parent), NULL, TRUE);
msg_dialog::displayChecks($errors);
if (empty($errors)) {
$this->attributesAccess['resetInLdapUser']->setVisible(FALSE);
}
}
function handle_resetInLdap ()
{
global $config;
$errors = $config->updateManagementConfig(get_class($this->parent), NULL, FALSE);
msg_dialog::displayChecks($errors);
if (empty($errors)) {
$this->attributesAccess['resetInLdap']->setVisible(FALSE);
}
}
function execute (): string
{
global $config, $ui;
......
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