Merge pull request #278 from Danielpk/enhancement_auth_deny

Added enhancement to AuthComponent::deny().
This commit is contained in:
José Lorenzo Rodríguez 2011-10-30 15:38:21 -07:00
commit f51be0a82c
2 changed files with 32 additions and 9 deletions

View file

@ -452,7 +452,8 @@ class AuthComponent extends Component {
* You can use deny with either an array, or var args. * You can use deny with either an array, or var args.
* *
* `$this->Auth->deny(array('edit', 'add'));` or * `$this->Auth->deny(array('edit', 'add'));` or
* `$this->Auth->deny('edit', 'add');` * `$this->Auth->deny('edit', 'add');` or
* `$this->Auth->deny();` to remove all items from the allowed list
* *
* @param mixed $action,... Controller action name or array of actions * @param mixed $action,... Controller action name or array of actions
* @return void * @return void
@ -461,6 +462,9 @@ class AuthComponent extends Component {
*/ */
public function deny($action = null) { public function deny($action = null) {
$args = func_get_args(); $args = func_get_args();
if(empty($args)){
$this->allowedActions = array();
}else{
if (isset($args[0]) && is_array($args[0])) { if (isset($args[0]) && is_array($args[0])) {
$args = $args[0]; $args = $args[0];
} }
@ -472,6 +476,7 @@ class AuthComponent extends Component {
} }
$this->allowedActions = array_values($this->allowedActions); $this->allowedActions = array_values($this->allowedActions);
} }
}
/** /**
* Maps action names to CRUD operations. Used for controller-based authentication. Make sure * Maps action names to CRUD operations. Used for controller-based authentication. Make sure

View file

@ -636,6 +636,24 @@ class AuthComponentTest extends CakeTestCase {
$this->Controller->request['action'] = 'camelCase'; $this->Controller->request['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller)); $this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->Auth->allow('*');
$this->Controller->Auth->deny();
$this->Controller->request['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->request['action'] = 'add';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->Auth->allow('camelCase');
$this->Controller->Auth->deny();
$this->Controller->request['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->request['action'] = 'login';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
} }
/** /**