Commit 05886b46 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!570
parents e0a60824 07f2f500
......@@ -29,7 +29,7 @@ class ManagementColumnAttribute extends CompositeAttribute
/*!
* \brief Management configuration dialog
*/
class ManagementConfigurationDialog extends simplePlugin
class ManagementConfigurationDialog extends ManagementDialog
{
static function plInfo (): array
{
......@@ -93,10 +93,10 @@ class ManagementConfigurationDialog extends simplePlugin
];
}
function __construct ($parent)
function __construct (management $parent)
{
parent::__construct();
$this->parent = $parent;
parent::__construct(NULL, NULL, $parent);
$this->attributesAccess['saveInLdap']->setInLdap(FALSE);
if (!$this->attrIsWriteable('saveInLdap')) {
$this->attributesAccess['saveInLdap']->setVisible(FALSE);
......@@ -133,40 +133,6 @@ class ManagementConfigurationDialog extends simplePlugin
}
}
function save_object ()
{
parent::save_object();
if (isset($_POST['edit_cancel'])) {
$this->handle_cancel();
} elseif (isset($_POST['edit_finish'])) {
$this->handle_finish();
}
}
protected function handle_finish ()
{
$msgs = $this->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return;
} else {
$errors = $this->save();
if (count($errors)) {
msg_dialog::displayChecks($errors);
return;
} else {
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
}
}
protected function handle_cancel ()
{
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
function execute (): string
{
global $config, $ui;
......@@ -174,14 +140,7 @@ class ManagementConfigurationDialog extends simplePlugin
$smarty = get_smarty();
$smarty->assign('ManagementConfigurationACL', 'rw');
$smarty->assign('fdManagementConfigACL', $ui->get_permissions(CONFIGRDN.$config->current['BASE'], 'configuration/configInLdap', 'fdManagementConfig', $this->readOnly()));
$str = parent::execute();
$str .= '<p class="plugbottom">'.
' <input type="submit" name="edit_finish" value="'.msgPool::saveButton().'"/>&nbsp;'.
' <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'.
'</p>';
return $str;
return parent::execute();
}
function save (): array
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-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.
*/
/*!
* \brief Management dialog
*/
class ManagementDialog extends simplePlugin
{
protected $post_cancel = 'edit_cancel';
protected $post_finish = 'edit_finish';
function __construct (string $dn = NULL, $object = NULL, management $parent = NULL, bool $mainTab = FALSE, array $attributesInfo = NULL)
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
}
function save_object ()
{
parent::save_object();
if (isset($_POST[$this->post_cancel])) {
$this->handle_cancel();
} elseif (isset($_POST[$this->post_finish])) {
$this->handle_finish();
}
}
protected function handle_finish ()
{
$msgs = $this->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return;
} else {
$errors = $this->save();
if (count($errors)) {
msg_dialog::displayChecks($errors);
return;
} else {
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
}
}
protected function handle_cancel ()
{
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
function execute (): string
{
return parent::execute().$this->getFooter();
}
/*! \brief Returns the plugin footer (save cancel), displayed in the template.
@return String HTML footer part.
*/
protected function getFooter (): string
{
if (!$this->displayPlugin) {
return '';
}
return '<p class="plugbottom">'.
' <input type="submit" name="'.$this->post_finish.'" value="'.msgPool::saveButton().'"/>'.
' <input type="submit" formnovalidate="formnovalidate" name="'.$this->post_cancel.'" value="'.msgPool::cancelButton().'"/>'.
'</p>';
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-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.
*/
/*!
* \brief Attribute which list the snapshots
*/
class SnapshotsAttribute extends OrderedArrayAttribute
{
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{
Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->edit_enabled = FALSE;
$this->order = FALSE;
$this->attribute = FALSE;
$this->setInLdap(FALSE);
}
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
if (is_object($this->plugin)) {
if ($this->plugin->global) {
$this->setHeaders([
_('DN'),
_('Date'),
_('Description'),
''
]);
} else {
$this->setHeaders([
_('Date'),
_('Description'),
''
]);
}
}
}
function loadPostValue ()
{
if ($this->isVisible()) {
parent::loadPostValue();
parent::applyPostValue();
}
}
protected function handleEdit ($key)
{
}
function applyPostValue ()
{
}
function addValue ($value)
{
$this->value[] = $value;
$this->reIndexValues();
}
function renderButtons ()
{
return '';
}
protected function getAttributeArrayValue ($key, $value)
{
$values = [
date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])),
$value['description'][0]
];
if ($this->plugin->global) {
array_unshift($values, $value['gosaSnapshotDN'][0]);
}
return $values;
}
protected function genRowIcons ($key, $value)
{
$id = $this->getHtmlId();
list ($img, $nbicons) = parent::genRowIcons($key, $value);
$img = $this->renderInputField(
'image', $id.'_restore_'.$key,
[
'src' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
'title' => _('Restore'),
'alt' => _('Restore'),
'class' => 'center'
]
).$img;
$nbicons++;
return [$img, $nbicons];
}
protected function handlePostValueActions ($id, $postValue)
{
if (parent::handlePostValueActions($id, $postValue)) {
return TRUE;
}
if (preg_match('/^'.$id.'_restore_/', $postValue)) {
$key = preg_replace('/^'.$id.'_restore_/', '', $postValue);
$key = preg_replace('/_[xy]$/', '', $key);
$this->plugin->triggerRestore($this->value[$key]['dn']);
return TRUE;
}
return FALSE;
}
function delPostValue ($key)
{
$this->plugin->triggerDelete($this->value[$key]['dn']);
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-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.
*/
/*!
* \brief Snapshot creation dialog
*/
class SnapshotCreateDialog extends ManagementDialog
{
public $aclCategory;
static function plInfo (): array
{
return [
'plShortName' => 'SnapshotCreateDialog',
];
}
static function getAttributesInfo (): array
{
return [
'main' => [
'name' => _('Creating an object snapshot'),
'attrs' => [
new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE
),
new DisplayAttribute(
_('Timestamp'), _('Timestamp of this snapshot creation'),
'timestamp', FALSE
),
new TextAreaAttribute(
_('Reason'), _('Reason for creating this snapshot'),
'description', TRUE,
'',
'SnapshotHandler'
),
]
],
];
}
function __construct (string $dn, management $parent, string $aclCategory)
{
parent::__construct(NULL, NULL, $parent);
$this->attributesAccess['description']->setInLdap(FALSE);
$this->object_dn = $dn;
$this->aclCategory = $aclCategory;
}
/*! \brief Check if logged in user have enough right to write this attribute value
*
* \param mixed $attr Attribute object or name (in this case it will be fetched from attributesAccess)
*/
function attrIsWriteable ($attr): bool
{
global $ui;
if (!is_object($attr)) {
$attr = $this->attributesAccess[$attr];
}
if ($attr->getLdapName() == 'description') {
return in_array('c', $ui->get_snapshot_permissions($this->acl_base, $this->aclCategory));
} else {
return parent::attrIsWriteable($attr);
}
}
function renderAttributes (bool $readOnly = FALSE)
{
global $ui;
$smarty = get_smarty();
$permissions = $ui->get_snapshot_permissions($this->acl_base, $this->aclCategory);
$acl = '';
if (in_array('c', $permissions)) {
$acl .= 'crw';
}
$smarty->assign('SnapshotHandlerACL', $acl);
return parent::renderAttributes($readOnly);
}
function execute (): string
{
$this->timestamp = date(_('Y-m-d, H:i:s'));
return parent::execute();
}
function save (): array
{
$this->parent->createSnapshot($this->object_dn, $this->description);
return [];
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-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
......@@ -19,224 +20,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Snapshot creation dialog
*/
class SnapshotCreateDialog extends simplePlugin
{
public $aclCategory;
static function plInfo (): array
{
return [
'plShortName' => 'SnapshotCreateDialog',
];
}
static function getAttributesInfo (): array
{
return [
'main' => [
'name' => _('Creating an object snapshot'),
'attrs' => [
new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE
),
new DisplayAttribute(
_('Timestamp'), _('Timestamp of this snapshot creation'),
'timestamp', FALSE
),
new TextAreaAttribute(
_('Reason'), _('Reason for creating this snapshot'),
'description', TRUE,
'',
'SnapshotHandler'
),
]
],
];
}
function __construct ($dn, $parent, $aclCategory)
{
parent::__construct();
$this->attributesAccess['description']->setInLdap(FALSE);
$this->object_dn = $dn;
$this->parent = $parent;
$this->aclCategory = $aclCategory;
}
/*! \brief Check if logged in user have enough right to write this attribute value
*
* \param mixed $attr Attribute object or name (in this case it will be fetched from attributesAccess)
*/
function attrIsWriteable ($attr): bool
{
global $ui;
if (!is_object($attr)) {
$attr = $this->attributesAccess[$attr];
}
if ($attr->getLdapName() == 'description') {
return in_array('c', $ui->get_snapshot_permissions($this->acl_base, $this->aclCategory));
} else {
return parent::attrIsWriteable($attr);
}
}
function renderAttributes (bool $readOnly = FALSE)
{
global $ui;
$smarty = get_smarty();
$permissions = $ui->get_snapshot_permissions($this->acl_base, $this->aclCategory);
$acl = '';
if (in_array('c', $permissions)) {
$acl .= 'crw';
}
$smarty->assign('SnapshotHandlerACL', $acl);
return parent::renderAttributes($readOnly);
}
function execute (): string
{
$this->timestamp = date(_('Y-m-d, H:i:s'));
$str = parent::execute();
$str .= '<p class="plugbottom">'.
' <input type="submit" name="edit_finish" value="'.msgPool::saveButton().'"/>&nbsp;'.
' <input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'.
'</p>';
return $str;
}
function save (): array
{
$this->parent->createSnapshot($this->object_dn, $this->description);
return [];
}
}
/*!
* \brief Attribute which list the snapshots
*/
class SnapshotsAttribute extends OrderedArrayAttribute
{
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{
Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->edit_enabled = FALSE;
$this->order = FALSE;
$this->attribute = FALSE;
$this->setInLdap(FALSE);
}
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
if (is_object($this->plugin)) {
if ($this->plugin->global) {
$this->setHeaders([
_('DN'),
_('Date'),
_('Description'),
''
]);
} else {
$this->setHeaders([
_('Date'),
_('Description'),
''
]);
}
}
}
function loadPostValue ()
{
if ($this->isVisible()) {
parent::loadPostValue();
parent::applyPostValue();
}
}
protected function handleEdit ($key)
{
}
function applyPostValue ()
{
}
function addValue ($value)
{
$this->value[] = $value;
$this->reIndexValues();
}
function renderButtons ()
{
return '';
}
protected function getAttributeArrayValue ($key, $value)
{
$values = [
date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])),
$value['description'][0]
];
if ($this->plugin->global) {
array_unshift($values, $value['gosaSnapshotDN'][0]);
}
return $values;
}
protected function genRowIcons ($key, $value)
{