Skip to content

Commit

Permalink
Adjust removeresource-action to suit the new resource form interface
Browse files Browse the repository at this point in the history
refs #5525
  • Loading branch information
Johannes Meyer committed Jul 24, 2014
1 parent 0964316 commit c3731fa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
48 changes: 27 additions & 21 deletions application/controllers/ConfigController.php
Expand Up @@ -447,44 +447,50 @@ public function editresourceAction()
$this->render('resource/modify');
}

/**
* Display a confirmation form to remove a resource
*/
public function removeresourceAction()
{
$this->view->messageBox = new AlertMessageBox(true);

$resources = ResourceFactory::getResourceConfigs()->toArray();
$name = $this->getParam('resource');
if (!isset($resources[$name])) {
$this->addSuccessMessage('Can\'t remove: Unknown resource provided');
$this->render('resource/remove');
return;
// Fetch the resource to be removed
$resources = IcingaConfig::app('resources')->toArray();
$name = $this->getParam('resource');
if (false === array_key_exists($name, $resources)) {
$this->addErrorMessage(sprintf($this->translate('Cannot remove "%s". Resource not found.'), $name));
$this->redirectNow('config/configurationerror');
}

$form = new ConfirmRemovalForm();
$form->setRequest($this->getRequest());
$form->setRemoveTarget('resource', $name);

// 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) {
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
$this->addErrorMessage(
'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' .
' Deleting it could eventally make login impossible.'
);
}
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
$this->addWarningMessage(
sprintf(
$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]);
if ($this->writeConfigFile($resources, 'resources')) {
$this->addSuccessMessage('Resource "' . $name . '" removed.');
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully removed.'), $name));
$this->redirectNow('config/resource');
}
return;
}

$this->view->name = $name;
$this->view->form = $form;
$this->view->messageBox->addForm($form);
$this->render('resource/remove');
}

Expand Down
13 changes: 3 additions & 10 deletions application/views/scripts/config/resource/remove.phtml
@@ -1,10 +1,3 @@
<h4>
<i class="icinga-icon-remove"></i>
Remove Resource "<?= $this->escape($this->name); ?>"
</h4>

<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>

<?= $this->form ?>
<h4><?= $this->translate('Remove Existing Resource'); ?></h4>
<?= $messageBox; ?>
<?= $form; ?>
14 changes: 14 additions & 0 deletions library/Icinga/Web/Controller/BaseConfigController.php
Expand Up @@ -47,6 +47,20 @@ protected function addErrorMessage($msg)
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.
*
Expand Down

0 comments on commit c3731fa

Please sign in to comment.