Skip to content

Commit

Permalink
Security: Add action for removing roles
Browse files Browse the repository at this point in the history
refs #5647
  • Loading branch information
lippserd committed Nov 19, 2014
1 parent 1d34d88 commit f707681
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions application/controllers/SecurityController.php
Expand Up @@ -89,19 +89,19 @@ public function updateRoleAction()
$this->view->form = $role;
}

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

0 comments on commit f707681

Please sign in to comment.