From c3731fa79ec140ab739a7083e975d5000a522792 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 24 Jul 2014 16:17:30 +0200 Subject: [PATCH] Adjust removeresource-action to suit the new resource form interface refs #5525 --- application/controllers/ConfigController.php | 54 ++++++++++--------- .../scripts/config/resource/remove.phtml | 13 ++--- .../Web/Controller/BaseConfigController.php | 14 +++++ 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 4e6bc9bd7..ee91f729f 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -447,44 +447,50 @@ class ConfigController extends BaseConfigController $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'); + } + + // Check if selected resource is currently used for authentication + $authConfig = IcingaConfig::app('authentication')->toArray(); + foreach ($authConfig as $backendName => $config) { + 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 + ) + ); + } } $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(); - 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 ($form->isSubmittedAndValid()) { + $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'); } diff --git a/application/views/scripts/config/resource/remove.phtml b/application/views/scripts/config/resource/remove.phtml index 3b5ffbfc1..fba6b081b 100644 --- a/application/views/scripts/config/resource/remove.phtml +++ b/application/views/scripts/config/resource/remove.phtml @@ -1,10 +1,3 @@ -

- - Remove Resource "escape($this->name); ?>" -

- -messageBox)): ?> - messageBox->render() ?> - - -form ?> +

translate('Remove Existing Resource'); ?>

+ + \ No newline at end of file diff --git a/library/Icinga/Web/Controller/BaseConfigController.php b/library/Icinga/Web/Controller/BaseConfigController.php index 98941686e..b4c90f3e2 100644 --- a/library/Icinga/Web/Controller/BaseConfigController.php +++ b/library/Icinga/Web/Controller/BaseConfigController.php @@ -47,6 +47,20 @@ class BaseConfigController extends ActionController 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. *