diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index b24f3b76e..90979a3a7 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -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 * diff --git a/application/views/scripts/user/show.phtml b/application/views/scripts/user/show.phtml index 733d3309a..1049a426a 100644 --- a/application/views/scripts/user/show.phtml +++ b/application/views/scripts/user/show.phtml @@ -75,11 +75,14 @@ if ($backend instanceof Updatable) {
= $this->translate('No memberships found matching the filter'); ?>
+ = $this->qlink($this->translate('Create new membership'), 'user/createmembership', array( - 'user' => $user->user_name + 'backend' => $backend->getName(), + 'user' => $user->user_name ), array( - 'icon' => 'plus', - 'data-base-target' => '_next', - 'class' => 'membership-create' + 'icon' => 'plus', + 'data-base-target' => '_next', + 'class' => 'membership-create' )); ?> + \ No newline at end of file