Security: Add action for creating a new role

refs #5647
This commit is contained in:
Eric Lippmann 2014-11-19 14:26:21 +01:00
parent f556fc43e9
commit 7fcfc01464
1 changed files with 29 additions and 2 deletions

View File

@ -6,6 +6,7 @@ use Icinga\Application\Config;
use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Forms\Security\PermissionForm;
use Icinga\Forms\Security\RestrictionForm;
use Icinga\Forms\Security\RoleForm;
use Icinga\Web\Controller\ActionController;
use Icinga\Web\Notification;
use Icinga\Web\Request;
@ -14,8 +15,34 @@ class SecurityController extends ActionController
{
public function indexAction()
{
$this->view->permissions = Config::app('permissions', true);
$this->view->restrictions = Config::app('restrictions', true);
$this->view->roles = Config::app('roles', true);
}
public function newRoleAction()
{
$role = new RoleForm(array(
'onSuccess' => function (RoleForm $role) {
$name = $role->getElement('name')->getValue();
$values = $role->getValues();
try {
$role->add($name, $values);
} catch (InvalidArgumentException $e) {
$role->addError($e->getMessage());
return false;
}
if ($role->save()) {
Notification::success(t('Role created'));
return true;
}
return false;
}
));
$role
->setSubmitLabel($this->translate('Create Role'))
->setIniConfig(Config::app('roles', true))
->setRedirectUrl('security')
->handleRequest();
$this->view->form = $role;
}
public function newPermissionAction()