GroupController: Properly handle 404's when handling group members
refs #8826
This commit is contained in:
parent
c8e8a39f5a
commit
cb4d6f013a
|
@ -232,10 +232,6 @@ class GroupController extends AuthBackendController
|
||||||
$groupName = $this->params->getRequired('group');
|
$groupName = $this->params->getRequired('group');
|
||||||
$backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible');
|
$backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible');
|
||||||
|
|
||||||
if ($backend->select()->where('group_name', $groupName)->count() === 0) {
|
|
||||||
$this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = new AddMemberForm();
|
$form = new AddMemberForm();
|
||||||
$form->setDataSource($this->fetchUsers())
|
$form->setDataSource($this->fetchUsers())
|
||||||
->setBackend($backend)
|
->setBackend($backend)
|
||||||
|
@ -243,8 +239,13 @@ class GroupController extends AuthBackendController
|
||||||
->setRedirectUrl(
|
->setRedirectUrl(
|
||||||
Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName))
|
Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName))
|
||||||
)
|
)
|
||||||
->setUidDisabled()
|
->setUidDisabled();
|
||||||
->handleRequest();
|
|
||||||
|
try {
|
||||||
|
$form->handleRequest();
|
||||||
|
} catch (NotFoundError $_) {
|
||||||
|
$this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
|
||||||
|
}
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->render('form');
|
$this->render('form');
|
||||||
|
@ -260,10 +261,6 @@ class GroupController extends AuthBackendController
|
||||||
$groupName = $this->params->getRequired('group');
|
$groupName = $this->params->getRequired('group');
|
||||||
$backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible');
|
$backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible');
|
||||||
|
|
||||||
if ($backend->select()->where('group_name', $groupName)->count() === 0) {
|
|
||||||
$this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = new Form(array(
|
$form = new Form(array(
|
||||||
'onSuccess' => function ($form) use ($groupName, $backend) {
|
'onSuccess' => function ($form) use ($groupName, $backend) {
|
||||||
foreach ($form->getValue('user_name') as $userName) {
|
foreach ($form->getValue('user_name') as $userName) {
|
||||||
|
@ -280,6 +277,8 @@ class GroupController extends AuthBackendController
|
||||||
$userName,
|
$userName,
|
||||||
$groupName
|
$groupName
|
||||||
));
|
));
|
||||||
|
} catch (NotFoundError $e) {
|
||||||
|
throw $e;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -297,7 +296,12 @@ class GroupController extends AuthBackendController
|
||||||
$form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called
|
$form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called
|
||||||
$form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true));
|
$form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true));
|
||||||
$form->addElement('hidden', 'redirect');
|
$form->addElement('hidden', 'redirect');
|
||||||
|
|
||||||
|
try {
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
} catch (NotFoundError $_) {
|
||||||
|
$this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Exception;
|
||||||
use Icinga\Data\Extensible;
|
use Icinga\Data\Extensible;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Data\Selectable;
|
use Icinga\Data\Selectable;
|
||||||
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
|
@ -155,6 +156,8 @@ class AddMemberForm extends Form
|
||||||
'user_name' => $userName
|
'user_name' => $userName
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} catch (NotFoundError $e) {
|
||||||
|
throw $e; // Trigger 404, the group name is initially accessed as GET parameter
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Notification::error(sprintf(
|
Notification::error(sprintf(
|
||||||
$this->translate('Failed to add "%s" as group member for "%s"'),
|
$this->translate('Failed to add "%s" as group member for "%s"'),
|
||||||
|
|
Loading…
Reference in New Issue