mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
parent
04835db13e
commit
ea959c2dfd
149
application/controllers/UsergroupbackendController.php
Normal file
149
application/controllers/UsergroupbackendController.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
use \Exception;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Exception\NotFoundError;
|
||||||
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
|
use Icinga\Forms\Config\UserGroup\UserGroupBackendForm;
|
||||||
|
use Icinga\Web\Controller;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller to configure user group backends
|
||||||
|
*/
|
||||||
|
class UsergroupbackendController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Redirect to this controller's list action
|
||||||
|
*/
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
$this->redirectNow('usergroupbackend/list');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a list of all user group backends
|
||||||
|
*/
|
||||||
|
public function listAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('config/application/usergroupbackend/*');
|
||||||
|
$this->view->backendNames = Config::app('groups')->keys();
|
||||||
|
$this->getTabs()->add(
|
||||||
|
'usergroupbackend/list',
|
||||||
|
array(
|
||||||
|
'title' => $this->translate('List all user group backends'),
|
||||||
|
'label' => $this->translate('User group backends'),
|
||||||
|
'url' => 'usergroupbackend/list'
|
||||||
|
)
|
||||||
|
)->activate('usergroupbackend/list');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user group backend
|
||||||
|
*/
|
||||||
|
public function createAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('config/application/usergroupbackend/create');
|
||||||
|
|
||||||
|
$form = new UserGroupBackendForm();
|
||||||
|
$form->setRedirectUrl('usergroupbackend/list');
|
||||||
|
$form->setTitle($this->translate('Create New User Group Backend'));
|
||||||
|
$form->addDescription($this->translate('Create a new backend to associate users and groups with.'));
|
||||||
|
$form->setIniConfig(Config::app('groups'));
|
||||||
|
$form->setOnSuccess(function (UserGroupBackendForm $form) {
|
||||||
|
try {
|
||||||
|
$form->add($form->getValues());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$form->error($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($form->save()) {
|
||||||
|
Notification::success(t('User group backend successfully created'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$form->handleRequest();
|
||||||
|
|
||||||
|
$this->view->form = $form;
|
||||||
|
$this->render('form');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit an user group backend
|
||||||
|
*/
|
||||||
|
public function editAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('config/application/usergroupbackend/edit');
|
||||||
|
$backendName = $this->params->getRequired('backend');
|
||||||
|
|
||||||
|
$form = new UserGroupBackendForm();
|
||||||
|
$form->setAction(Url::fromRequest());
|
||||||
|
$form->setRedirectUrl('usergroupbackend/list');
|
||||||
|
$form->setTitle(sprintf($this->translate('Edit User Group Backend %s'), $backendName));
|
||||||
|
$form->setIniConfig(Config::app('groups'));
|
||||||
|
$form->setOnSuccess(function (UserGroupBackendForm $form) use ($backendName) {
|
||||||
|
try {
|
||||||
|
$form->edit($backendName, $form->getValues());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$form->error($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($form->save()) {
|
||||||
|
Notification::success(sprintf(t('User group backend "%s" successfully updated'), $backendName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form->load($backendName);
|
||||||
|
$form->handleRequest();
|
||||||
|
} catch (NotFoundError $_) {
|
||||||
|
$this->httpNotFound(sprintf($this->translate('User group backend "%s" not found'), $backendName));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->view->form = $form;
|
||||||
|
$this->render('form');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a user group backend
|
||||||
|
*/
|
||||||
|
public function removeAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('config/application/usergroupbackend/remove');
|
||||||
|
$backendName = $this->params->getRequired('backend');
|
||||||
|
|
||||||
|
$backendForm = new UserGroupBackendForm();
|
||||||
|
$backendForm->setIniConfig(Config::app('groups'));
|
||||||
|
$form = new ConfirmRemovalForm();
|
||||||
|
$form->setRedirectUrl('usergroupbackend/list');
|
||||||
|
$form->setTitle(sprintf($this->translate('Remove User Group Backend %s'), $backendName));
|
||||||
|
$form->setOnSuccess(function (ConfirmRemovalForm $form) use ($backendName, $backendForm) {
|
||||||
|
try {
|
||||||
|
$backendForm->delete($backendName);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$form->error($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($backendForm->save()) {
|
||||||
|
Notification::success(sprintf(t('User group backend "%s" successfully removed'), $backendName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$form->handleRequest();
|
||||||
|
|
||||||
|
$this->view->form = $form;
|
||||||
|
$this->render('form');
|
||||||
|
}
|
||||||
|
}
|
@ -21,26 +21,30 @@ class RoleForm extends ConfigForm
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $providedPermissions = array(
|
protected $providedPermissions = array(
|
||||||
'*' => '*',
|
'*' => '*',
|
||||||
'config/*' => 'config/*',
|
'config/*' => 'config/*',
|
||||||
'config/application/*' => 'config/application/*',
|
'config/application/*' => 'config/application/*',
|
||||||
'config/application/general' => 'config/application/general',
|
'config/application/general' => 'config/application/general',
|
||||||
'config/application/authentication' => 'config/application/authentication',
|
'config/application/authentication' => 'config/application/authentication',
|
||||||
'config/application/resources' => 'config/application/resources',
|
'config/application/resources' => 'config/application/resources',
|
||||||
'config/application/roles' => 'config/application/roles',
|
'config/application/roles' => 'config/application/roles',
|
||||||
'config/application/users/*' => 'config/application/users/*',
|
'config/application/users/*' => 'config/application/users/*',
|
||||||
'config/application/users/show' => 'config/application/users/show',
|
'config/application/users/show' => 'config/application/users/show',
|
||||||
'config/application/users/add' => 'config/application/users/add',
|
'config/application/users/add' => 'config/application/users/add',
|
||||||
'config/application/users/edit' => 'config/application/users/edit',
|
'config/application/users/edit' => 'config/application/users/edit',
|
||||||
'config/application/users/remove' => 'config/application/users/remove',
|
'config/application/users/remove' => 'config/application/users/remove',
|
||||||
'config/application/groups/*' => 'config/application/groups/*',
|
'config/application/groups/*' => 'config/application/groups/*',
|
||||||
'config/application/groups/show' => 'config/application/groups/show',
|
'config/application/groups/show' => 'config/application/groups/show',
|
||||||
'config/application/groups/add' => 'config/application/groups/add',
|
'config/application/groups/add' => 'config/application/groups/add',
|
||||||
'config/application/groups/edit' => 'config/application/groups/edit',
|
'config/application/groups/edit' => 'config/application/groups/edit',
|
||||||
'config/application/groups/remove' => 'config/application/groups/remove',
|
'config/application/groups/remove' => 'config/application/groups/remove',
|
||||||
'config/application/groups/member/add' => 'config/application/groups/member/add',
|
'config/application/groups/member/add' => 'config/application/groups/member/add',
|
||||||
'config/application/groups/member/remove' => 'config/application/groups/member/remove',
|
'config/application/groups/member/remove' => 'config/application/groups/member/remove',
|
||||||
'config/modules' => 'config/modules'
|
'config/application/usergroupbackend/*' => 'config/application/usergroupbackend/*',
|
||||||
|
'config/application/usergroupbackend/create' => 'config/application/usergroupbackend/create',
|
||||||
|
'config/application/usergroupbackend/edit' => 'config/application/usergroupbackend/edit',
|
||||||
|
'config/application/usergroupbackend/remove' => 'config/application/usergroupbackend/remove',
|
||||||
|
'config/modules' => 'config/modules'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
6
application/views/scripts/usergroupbackend/form.phtml
Normal file
6
application/views/scripts/usergroupbackend/form.phtml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div class="controls">
|
||||||
|
<?= $tabs->showOnlyCloseButton(); ?>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<?= $form; ?>
|
||||||
|
</div>
|
63
application/views/scripts/usergroupbackend/list.phtml
Normal file
63
application/views/scripts/usergroupbackend/list.phtml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$createPermitted = $this->hasPermission('config/application/usergroupbackend/create');
|
||||||
|
$editPermitted = $this->hasPermission('config/application/usergroupbackend/edit');
|
||||||
|
$removePermitted = $this->hasPermission('config/application/usergroupbackend/remove');
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="controls">
|
||||||
|
<?= $tabs; ?>
|
||||||
|
</div>
|
||||||
|
<div class="content" data-base-target="_next">
|
||||||
|
<?php if ($createPermitted): ?>
|
||||||
|
<?= $this->qlink(
|
||||||
|
$this->translate('Create A New User Group Backend'),
|
||||||
|
'usergroupbackend/create',
|
||||||
|
null,
|
||||||
|
array(
|
||||||
|
'icon' => 'plus'
|
||||||
|
)
|
||||||
|
); ?>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php if (count($backendNames) > 0): ?>
|
||||||
|
<table class="action usergroupbackend-list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="backend-name"><?= $this->translate('Backend'); ?></th>
|
||||||
|
<?php if ($removePermitted): ?>
|
||||||
|
<th class="backend-remove"><?= $this->translate('Remove'); ?></th>
|
||||||
|
<?php endif ?>
|
||||||
|
<tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($backendNames as $backendName): ?>
|
||||||
|
<tr>
|
||||||
|
<td class="backend-name">
|
||||||
|
<?php if ($editPermitted): ?>
|
||||||
|
<?= $this->qlink(
|
||||||
|
$backendName,
|
||||||
|
'usergroupbackend/edit',
|
||||||
|
array('backend' => $backendName),
|
||||||
|
array('title' => sprintf($this->translate('Edit user group backend %s'), $backendName))
|
||||||
|
); ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<?= $this->escape($backendName); ?>
|
||||||
|
<?php endif ?>
|
||||||
|
</td>
|
||||||
|
<?php if ($removePermitted): ?>
|
||||||
|
<td class="backend-remove"><?= $this->qlink(
|
||||||
|
null,
|
||||||
|
'usergroupbackend/remove',
|
||||||
|
array('backend' => $backendName),
|
||||||
|
array(
|
||||||
|
'title' => sprintf($this->translate('Remove user group backend %s'), $backendName),
|
||||||
|
'icon' => 'trash'
|
||||||
|
)
|
||||||
|
); ?></td>
|
||||||
|
<?php endif ?>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php endif ?>
|
||||||
|
</div>
|
@ -356,3 +356,14 @@ form.backend-selection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.usergroupbackend-list {
|
||||||
|
th.backend-remove {
|
||||||
|
width: 8em;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.backend-remove {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user