mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 17:24:16 +02:00
Don't throw exceptions manually in the RoleController
This commit is contained in:
parent
8af77e49e9
commit
5c883d902e
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
namespace Icinga\Controllers;
|
namespace Icinga\Controllers;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Zend_Controller_Action_Exception;
|
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Exception\AlreadyExistsException;
|
||||||
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
use Icinga\Forms\Security\RoleForm;
|
use Icinga\Forms\Security\RoleForm;
|
||||||
use Icinga\Web\Controller\AuthBackendController;
|
use Icinga\Web\Controller\AuthBackendController;
|
||||||
@ -40,7 +40,7 @@ class RoleController extends AuthBackendController
|
|||||||
$values = $role->getValues();
|
$values = $role->getValues();
|
||||||
try {
|
try {
|
||||||
$role->add($name, $values);
|
$role->add($name, $values);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (AlreadyExistsException $e) {
|
||||||
$role->addError($e->getMessage());
|
$role->addError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -63,8 +63,6 @@ class RoleController extends AuthBackendController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a role
|
* Update a role
|
||||||
*
|
|
||||||
* @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist
|
|
||||||
*/
|
*/
|
||||||
public function editAction()
|
public function editAction()
|
||||||
{
|
{
|
||||||
@ -77,11 +75,8 @@ class RoleController extends AuthBackendController
|
|||||||
$role
|
$role
|
||||||
->setIniConfig(Config::app('roles', true))
|
->setIniConfig(Config::app('roles', true))
|
||||||
->load($name);
|
->load($name);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (NotFoundError $e) {
|
||||||
throw new Zend_Controller_Action_Exception(
|
$this->httpNotFound($e->getMessage());
|
||||||
$e->getMessage(),
|
|
||||||
400
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$role
|
$role
|
||||||
->setOnSuccess(function (RoleForm $role) use ($name) {
|
->setOnSuccess(function (RoleForm $role) use ($name) {
|
||||||
@ -90,7 +85,7 @@ class RoleController extends AuthBackendController
|
|||||||
$values = $role->getValues();
|
$values = $role->getValues();
|
||||||
try {
|
try {
|
||||||
$role->update($name, $values, $oldName);
|
$role->update($name, $values, $oldName);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (NotFoundError $e) {
|
||||||
$role->addError($e->getMessage());
|
$role->addError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -108,8 +103,6 @@ class RoleController extends AuthBackendController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a role
|
* Remove a role
|
||||||
*
|
|
||||||
* @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist
|
|
||||||
*/
|
*/
|
||||||
public function removeAction()
|
public function removeAction()
|
||||||
{
|
{
|
||||||
@ -120,17 +113,14 @@ class RoleController extends AuthBackendController
|
|||||||
$role
|
$role
|
||||||
->setIniConfig(Config::app('roles', true))
|
->setIniConfig(Config::app('roles', true))
|
||||||
->load($name);
|
->load($name);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (NotFoundError $e) {
|
||||||
throw new Zend_Controller_Action_Exception(
|
$this->httpNotFound($e->getMessage());
|
||||||
$e->getMessage(),
|
|
||||||
400
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$confirmation = new ConfirmRemovalForm(array(
|
$confirmation = new ConfirmRemovalForm(array(
|
||||||
'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($name, $role) {
|
'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($name, $role) {
|
||||||
try {
|
try {
|
||||||
$role->remove($name);
|
$role->remove($name);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (NotFoundError $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user