mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #278 from Danielpk/enhancement_auth_deny
Added enhancement to AuthComponent::deny().
This commit is contained in:
commit
f51be0a82c
2 changed files with 32 additions and 9 deletions
|
@ -452,7 +452,8 @@ class AuthComponent extends Component {
|
|||
* You can use deny with either an array, or var args.
|
||||
*
|
||||
* `$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
|
||||
* @return void
|
||||
|
@ -461,6 +462,9 @@ class AuthComponent extends Component {
|
|||
*/
|
||||
public function deny($action = null) {
|
||||
$args = func_get_args();
|
||||
if(empty($args)){
|
||||
$this->allowedActions = array();
|
||||
}else{
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
|
@ -472,6 +476,7 @@ class AuthComponent extends Component {
|
|||
}
|
||||
$this->allowedActions = array_values($this->allowedActions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps action names to CRUD operations. Used for controller-based authentication. Make sure
|
||||
|
|
|
@ -636,6 +636,24 @@ class AuthComponentTest extends CakeTestCase {
|
|||
|
||||
$this->Controller->request['action'] = 'camelCase';
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue