Adjust removeresource-action to suit the new resource form interface
refs #5525
This commit is contained in:
parent
0964316df4
commit
c3731fa79e
|
@ -447,44 +447,50 @@ class ConfigController extends BaseConfigController
|
||||||
$this->render('resource/modify');
|
$this->render('resource/modify');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a confirmation form to remove a resource
|
||||||
|
*/
|
||||||
public function removeresourceAction()
|
public function removeresourceAction()
|
||||||
{
|
{
|
||||||
$this->view->messageBox = new AlertMessageBox(true);
|
$this->view->messageBox = new AlertMessageBox(true);
|
||||||
|
|
||||||
$resources = ResourceFactory::getResourceConfigs()->toArray();
|
// Fetch the resource to be removed
|
||||||
|
$resources = IcingaConfig::app('resources')->toArray();
|
||||||
$name = $this->getParam('resource');
|
$name = $this->getParam('resource');
|
||||||
if (!isset($resources[$name])) {
|
if (false === array_key_exists($name, $resources)) {
|
||||||
$this->addSuccessMessage('Can\'t remove: Unknown resource provided');
|
$this->addErrorMessage(sprintf($this->translate('Cannot remove "%s". Resource not found.'), $name));
|
||||||
$this->render('resource/remove');
|
$this->redirectNow('config/configurationerror');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new ConfirmRemovalForm();
|
|
||||||
$form->setRequest($this->getRequest());
|
|
||||||
$form->setRemoveTarget('resource', $name);
|
|
||||||
|
|
||||||
// Check if selected resource is currently used for authentication
|
// Check if selected resource is currently used for authentication
|
||||||
$authConfig = IcingaConfig::app('authentication', true)->toArray();
|
$authConfig = IcingaConfig::app('authentication')->toArray();
|
||||||
foreach ($authConfig as $backendName => $config) {
|
foreach ($authConfig as $backendName => $config) {
|
||||||
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
||||||
$this->addErrorMessage(
|
$this->addWarningMessage(
|
||||||
'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' .
|
sprintf(
|
||||||
' Deleting it could eventally make login impossible.'
|
$this->translate(
|
||||||
|
'The resource "%s" is currently in use by the authentication backend "%s". ' .
|
||||||
|
'Removing the resource can result in noone being able to log in any longer.'
|
||||||
|
),
|
||||||
|
$name,
|
||||||
|
$backendName
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($form->isSubmittedAndValid()) {
|
$form = new ConfirmRemovalForm();
|
||||||
|
$request = $this->getRequest();
|
||||||
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||||
unset($resources[$name]);
|
unset($resources[$name]);
|
||||||
if ($this->writeConfigFile($resources, 'resources')) {
|
if ($this->writeConfigFile($resources, 'resources')) {
|
||||||
$this->addSuccessMessage('Resource "' . $name . '" removed.');
|
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully removed.'), $name));
|
||||||
$this->redirectNow('config/resource');
|
$this->redirectNow('config/resource');
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->name = $name;
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
|
$this->view->messageBox->addForm($form);
|
||||||
$this->render('resource/remove');
|
$this->render('resource/remove');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
<h4>
|
<h4><?= $this->translate('Remove Existing Resource'); ?></h4>
|
||||||
<i class="icinga-icon-remove"></i>
|
<?= $messageBox; ?>
|
||||||
Remove Resource "<?= $this->escape($this->name); ?>"
|
<?= $form; ?>
|
||||||
</h4>
|
|
||||||
|
|
||||||
<?php if (isset($this->messageBox)): ?>
|
|
||||||
<?= $this->messageBox->render() ?>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<?= $this->form ?>
|
|
|
@ -47,6 +47,20 @@ class BaseConfigController extends ActionController
|
||||||
Session::getSession()->write();
|
Session::getSession()->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message with the logging level Zend_Log::WARN to the current user and
|
||||||
|
* commit the changes to the underlying session.
|
||||||
|
*
|
||||||
|
* @param $msg The message content
|
||||||
|
*/
|
||||||
|
protected function addWarningMessage($msg)
|
||||||
|
{
|
||||||
|
AuthenticationManager::getInstance()->getUser()->addMessage(
|
||||||
|
new Message($msg, Zend_Log::WARN)
|
||||||
|
);
|
||||||
|
Session::getSession()->write();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return an array of tabs provided by this configuration controller.
|
* Return an array of tabs provided by this configuration controller.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue