GroupController: Add addmemberAction()

refs #8826
This commit is contained in:
Johannes Meyer 2015-05-26 14:32:14 +02:00
parent 86146b8048
commit 899a00e983
1 changed files with 45 additions and 0 deletions

View File

@ -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;
@ -222,6 +224,32 @@ class GroupController extends AuthBackendController
$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
*/
@ -271,6 +299,23 @@ class GroupController extends AuthBackendController
$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
*