Skip to content

Commit

Permalink
GroupController: Add addmemberAction()
Browse files Browse the repository at this point in the history
refs #8826
  • Loading branch information
Johannes Meyer committed May 26, 2015
1 parent 86146b8 commit 899a00e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions application/controllers/GroupController.php
Expand Up @@ -3,8 +3,10 @@

use \Exception;
use Icinga\Application\Logger;
use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\Data\Reducible;
use Icinga\Data\Filter\Filter;
use Icinga\Forms\Config\UserGroup\AddMemberForm;
use Icinga\Forms\Config\UserGroup\UserGroupForm;
use Icinga\Web\Controller\AuthBackendController;
use Icinga\Web\Form;
Expand Down Expand Up @@ -222,6 +224,32 @@ public function removeAction()
$this->render('form');
}

/**
* Add a group member
*/
public function addmemberAction()
{
$groupName = $this->params->getRequired('group');
$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->setDataSource($this->fetchUsers())
->setBackend($backend)
->setGroupName($groupName)
->setRedirectUrl(
Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName))
)
->setUidDisabled()
->handleRequest();

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

/**
* Remove a group member
*/
Expand Down Expand Up @@ -271,6 +299,23 @@ public function removememberAction()
$form->handleRequest();
}

/**
* Fetch and return all users from all user backends
*
* @return ArrayDatasource
*/
protected function fetchUsers()
{
$users = array();
foreach ($this->loadUserBackends('Icinga\Data\Selectable') as $backend) {
foreach ($backend->select(array('user_name')) as $row) {
$users[] = $row;
}
}

return new ArrayDatasource($users);
}

/**
* Create the tabs to display when showing a group
*
Expand Down

0 comments on commit 899a00e

Please sign in to comment.