Changing AuthComponent::deny to accepts same param as AuthComponent::allow, tests added

This commit is contained in:
renan.saddam 2009-08-13 13:08:30 -03:00
parent 2484245c68
commit c84b4cf36d
2 changed files with 15 additions and 3 deletions

View file

@ -591,7 +591,7 @@ class AuthComponent extends Object {
* Takes a list of actions in the current controller for which authentication is not required, or * Takes a list of actions in the current controller for which authentication is not required, or
* no parameters to allow all actions. * no parameters to allow all actions.
* *
* @param string $action Controller action name * @param mixed $action Controller action name or array of actions
* @param string $action Controller action name * @param string $action Controller action name
* @param string ... etc. * @param string ... etc.
* @return void * @return void
@ -612,7 +612,7 @@ class AuthComponent extends Object {
/** /**
* Removes items from the list of allowed actions. * Removes items from the list of allowed actions.
* *
* @param string $action Controller action name * @param mixed $action Controller action name or array of actions
* @param string $action Controller action name * @param string $action Controller action name
* @param string ... etc. * @param string ... etc.
* @return void * @return void
@ -621,6 +621,9 @@ class AuthComponent extends Object {
*/ */
function deny() { function deny() {
$args = func_get_args(); $args = func_get_args();
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
foreach ($args as $arg) { foreach ($args as $arg) {
$i = array_search($arg, $this->allowedActions); $i = array_search($arg, $this->allowedActions);
if (is_int($i)) { if (is_int($i)) {

View file

@ -777,7 +777,7 @@ class AuthTest extends CakeTestCase {
$this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->allow('*'); $this->Controller->Auth->allow('*');
$this->Controller->Auth->deny('add'); $this->Controller->Auth->deny('add', 'camelcase');
$this->Controller->params['action'] = 'delete'; $this->Controller->params['action'] = 'delete';
$this->assertTrue($this->Controller->Auth->startup($this->Controller)); $this->assertTrue($this->Controller->Auth->startup($this->Controller));
@ -787,6 +787,15 @@ class AuthTest extends CakeTestCase {
$this->Controller->params['action'] = 'Add'; $this->Controller->params['action'] = 'Add';
$this->assertFalse($this->Controller->Auth->startup($this->Controller)); $this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->params['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
$this->Controller->Auth->allow('*');
$this->Controller->Auth->deny(array('add', 'camelcase'));
$this->Controller->params['action'] = 'camelCase';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
} }
/** /**