Security: Add action for removing roles

refs #5647
This commit is contained in:
Eric Lippmann 2014-11-19 14:40:49 +01:00
parent 1d34d88a01
commit f7076816eb
1 changed files with 11 additions and 10 deletions

View File

@ -89,19 +89,19 @@ class SecurityController extends ActionController
$this->view->form = $role; $this->view->form = $role;
} }
public function removePermissionAction() public function removeRoleAction()
{ {
$name = $this->_request->getParam('permission'); $name = $this->_request->getParam('role');
if (empty($name)) { if (empty($name)) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
sprintf($this->translate('Required parameter \'%s\' missing'), 'permission'), sprintf($this->translate('Required parameter \'%s\' missing'), 'role'),
400 400
); );
} }
$permission = new PermissionForm(); $role = new RoleForm();
try { try {
$permission $role
->setIniConfig(Config::app('permissions', true)) ->setIniConfig(Config::app('roles', true))
->load($name); ->load($name);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
@ -110,21 +110,22 @@ class SecurityController extends ActionController
); );
} }
$confirmation = new ConfirmRemovalForm(array( $confirmation = new ConfirmRemovalForm(array(
'onSuccess' => function (Request $request, ConfirmRemovalForm $confirmation) use ($name, $permission) { 'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($name, $role) {
try { try {
$permission->remove($name); $role->remove($name);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Notification::error($e->getMessage()); Notification::error($e->getMessage());
return false; return false;
} }
if ($permission->save()) { if ($role->save()) {
Notification::success(sprintf(t('Permission \'%s\' has been successfully removed'), $name)); Notification::success(t('Role removed'));
return true; return true;
} }
return false; return false;
} }
)); ));
$confirmation $confirmation
->setSubmitLabel($this->translate('Remove Role'))
->setRedirectUrl('security') ->setRedirectUrl('security')
->handleRequest(); ->handleRequest();
$this->view->name = $name; $this->view->name = $name;