GroupController: Let the form validate a group's name

refs #8826
This commit is contained in:
Johannes Meyer 2015-05-28 16:28:59 +02:00
parent ad6b4016f0
commit 2c9af2fb81
1 changed files with 13 additions and 11 deletions

View File

@ -6,6 +6,7 @@ use Icinga\Application\Logger;
use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\Data\Reducible; use Icinga\Data\Reducible;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\NotFoundError;
use Icinga\Forms\Config\UserGroup\AddMemberForm; use Icinga\Forms\Config\UserGroup\AddMemberForm;
use Icinga\Forms\Config\UserGroup\UserGroupForm; use Icinga\Forms\Config\UserGroup\UserGroupForm;
use Icinga\Web\Controller\AuthBackendController; use Icinga\Web\Controller\AuthBackendController;
@ -185,17 +186,17 @@ class GroupController extends AuthBackendController
$groupName = $this->params->getRequired('group'); $groupName = $this->params->getRequired('group');
$backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Updatable'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Updatable');
$row = $backend->select(array('group_name'))->where('group_name', $groupName)->fetchRow();
if ($row === false) {
$this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
}
$form = new UserGroupForm(); $form = new UserGroupForm();
$form->setRedirectUrl( $form->setRedirectUrl(
Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName)) Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName))
); );
$form->setRepository($backend); $form->setRepository($backend);
$form->edit($groupName, get_object_vars($row))->handleRequest();
try {
$form->edit($groupName)->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');
@ -210,14 +211,15 @@ 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 UserGroupForm(); $form = new UserGroupForm();
$form->setRedirectUrl(Url::fromPath('group/list', array('backend' => $backend->getName()))); $form->setRedirectUrl(Url::fromPath('group/list', array('backend' => $backend->getName())));
$form->setRepository($backend); $form->setRepository($backend);
try {
$form->remove($groupName)->handleRequest(); $form->remove($groupName)->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');