parent
a75c74eae1
commit
02afa9fd55
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
use \Exception;
|
use \Exception;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Forms\Config\User\CreateMembershipForm;
|
||||||
use Icinga\Forms\Config\User\UserForm;
|
use Icinga\Forms\Config\User\UserForm;
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
|
@ -122,6 +124,9 @@ class UserController extends AuthBackendController
|
||||||
$memberships
|
$memberships
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$extensibleBackends = $this->loadUserGroupBackends('Icinga\Data\Extensible');
|
||||||
|
$this->view->showCreateMembershipLink = ! empty($extensibleBackends);
|
||||||
|
|
||||||
$this->view->user = $user;
|
$this->view->user = $user;
|
||||||
$this->view->backend = $backend;
|
$this->view->backend = $backend;
|
||||||
$this->view->memberships = $memberships;
|
$this->view->memberships = $memberships;
|
||||||
|
@ -211,6 +216,35 @@ class UserController extends AuthBackendController
|
||||||
$this->render('form');
|
$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
|
* Fetch and return the given user's groups from all user group backends
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,11 +75,14 @@ if ($backend instanceof Updatable) {
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<p><?= $this->translate('No memberships found matching the filter'); ?></p>
|
<p><?= $this->translate('No memberships found matching the filter'); ?></p>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
<?php if ($showCreateMembershipLink): ?>
|
||||||
<?= $this->qlink($this->translate('Create new membership'), 'user/createmembership', array(
|
<?= $this->qlink($this->translate('Create new membership'), 'user/createmembership', array(
|
||||||
'user' => $user->user_name
|
'backend' => $backend->getName(),
|
||||||
|
'user' => $user->user_name
|
||||||
), array(
|
), array(
|
||||||
'icon' => 'plus',
|
'icon' => 'plus',
|
||||||
'data-base-target' => '_next',
|
'data-base-target' => '_next',
|
||||||
'class' => 'membership-create'
|
'class' => 'membership-create'
|
||||||
)); ?>
|
)); ?>
|
||||||
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue