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,16 +462,20 @@ class AuthComponent extends Component {
*/ */
public function deny($action = null) { public function deny($action = null) {
$args = func_get_args(); $args = func_get_args();
if (isset($args[0]) && is_array($args[0])) { if(empty($args)){
$args = $args[0]; $this->allowedActions = array();
} }else{
foreach ($args as $arg) { if (isset($args[0]) && is_array($args[0])) {
$i = array_search($arg, $this->allowedActions); $args = $args[0];
if (is_int($i)) {
unset($this->allowedActions[$i]);
} }
foreach ($args as $arg) {
$i = array_search($arg, $this->allowedActions);
if (is_int($i)) {
unset($this->allowedActions[$i]);
}
}
$this->allowedActions = array_values($this->allowedActions);
} }
$this->allowedActions = array_values($this->allowedActions);
} }
/** /**

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));
} }
/** /**