Skip to content

Commit

Permalink
GroupController: Introduce addAction, editAction and removeAction
Browse files Browse the repository at this point in the history
refs #8826
  • Loading branch information
Johannes Meyer committed May 20, 2015
1 parent 9c6a889 commit 539b824
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
57 changes: 57 additions & 0 deletions application/controllers/GroupController.php
Expand Up @@ -7,6 +7,7 @@
use Icinga\Application\Logger;
use Icinga\Authentication\UserGroup\UserGroupBackend;
use Icinga\Authentication\UserGroup\UserGroupBackendInterface;
use Icinga\Forms\Config\UserGroupForm;
use Icinga\Web\Controller;
use Icinga\Web\Form;
use Icinga\Web\Notification;
Expand Down Expand Up @@ -100,6 +101,62 @@ function ($b) { return $b->getName(); },
);
}

/**
* Add a group
*/
public function addAction()
{
$form = new UserGroupForm();
$form->setRepository(
$this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible')
);
$form->add()->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Edit a group
*/
public function editAction()
{
$groupName = $this->params->getRequired('group');
$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->setRepository($backend);
$form->edit($groupName, get_object_vars($row))->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Remove a group
*/
public function removeAction()
{
$groupName = $this->params->getRequired('group');
$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->setRepository($backend);
$form->remove($groupName)->handleRequest();

$this->view->form = $form;
$this->render('form');
}

/**
* Return all user group backends implementing the given interface
*
Expand Down
6 changes: 6 additions & 0 deletions application/views/scripts/group/form.phtml
@@ -0,0 +1,6 @@
<div class="controls">
<?= $tabs->showOnlyCloseButton(); ?>
</div>
<div class="content">
<?= $form; ?>
</div>

0 comments on commit 539b824

Please sign in to comment.