UserController: Add createmembershipAction()

refs #8826
This commit is contained in:
Johannes Meyer 2015-05-26 17:03:10 +02:00
parent a75c74eae1
commit 02afa9fd55
2 changed files with 41 additions and 4 deletions

View File

@ -3,6 +3,8 @@
use \Exception;
use Icinga\Application\Logger;
use Icinga\Exception\ConfigurationError;
use Icinga\Forms\Config\User\CreateMembershipForm;
use Icinga\Forms\Config\User\UserForm;
use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\User;
@ -122,6 +124,9 @@ class UserController extends AuthBackendController
$memberships
);
$extensibleBackends = $this->loadUserGroupBackends('Icinga\Data\Extensible');
$this->view->showCreateMembershipLink = ! empty($extensibleBackends);
$this->view->user = $user;
$this->view->backend = $backend;
$this->view->memberships = $memberships;
@ -211,6 +216,35 @@ class UserController extends AuthBackendController
$this->render('form');
}
/**
* Create a membership for a user
*/
public function createmembershipAction()
{
$userName = $this->params->getRequired('user');
$backend = $this->getUserBackend($this->params->getRequired('backend'));
if ($backend->select()->where('user_name', $userName)->count() === 0) {
$this->httpNotFound(sprintf($this->translate('User "%s" not found'), $userName));
}
$backends = $this->loadUserGroupBackends('Icinga\Data\Extensible');
if (empty($backends)) {
throw new ConfigurationError($this->translate(
'You\'ll need to configure at least one user group backend first that allows to create new memberships'
));
}
$form = new CreateMembershipForm();
$form->setBackends($backends)
->setUsername($userName)
->setRedirectUrl(Url::fromPath('user/show', array('backend' => $backend->getName(), 'user' => $userName)))
->handleRequest();
$this->view->form = $form;
$this->render('form');
}
/**
* Fetch and return the given user's groups from all user group backends
*

View File

@ -75,11 +75,14 @@ if ($backend instanceof Updatable) {
<?php else: ?>
<p><?= $this->translate('No memberships found matching the filter'); ?></p>
<?php endif ?>
<?php if ($showCreateMembershipLink): ?>
<?= $this->qlink($this->translate('Create new membership'), 'user/createmembership', array(
'backend' => $backend->getName(),
'user' => $user->user_name
), array(
'icon' => 'plus',
'data-base-target' => '_next',
'class' => 'membership-create'
)); ?>
<?php endif ?>
</div>