mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 02:52:41 +00:00
Updating AclShell to use new formatting and removing methods that are no longer needed.
This commit is contained in:
parent
0fd8d2b8e4
commit
43646b9372
2 changed files with 21 additions and 44 deletions
|
@ -84,7 +84,7 @@ class AclShell extends Shell {
|
|||
$this->_stop();
|
||||
}
|
||||
|
||||
if ($this->command && !in_array($this->command, array('help'))) {
|
||||
if ($this->command) {
|
||||
if (!config('database')) {
|
||||
$this->out(__('Your database configuration was not found. Take a moment to create one.'), true);
|
||||
$this->args = null;
|
||||
|
@ -162,8 +162,6 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function setParent() {
|
||||
$this->_checkArgs(3, 'setParent');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
$target = $this->parseIdentifier($this->args[1]);
|
||||
$parent = $this->parseIdentifier($this->args[2]);
|
||||
|
@ -187,8 +185,6 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function getPath() {
|
||||
$this->_checkArgs(2, 'getPath');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
$identifier = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
|
@ -231,13 +227,12 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function check() {
|
||||
$this->_checkArgs(3, 'check');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->check($aro, $aco, $action)) {
|
||||
$this->out(sprintf(__('%s is allowed.'), $aroName), true);
|
||||
$this->out(sprintf(__('%s is <success>allowed</success>.'), $aroName), true);
|
||||
} else {
|
||||
$this->out(sprintf(__('%s is not allowed.'), $aroName), true);
|
||||
$this->out(sprintf(__('%s is <error>not allowed</error>.'), $aroName), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,13 +241,12 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function grant() {
|
||||
$this->_checkArgs(3, 'grant');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->allow($aro, $aco, $action)) {
|
||||
$this->out(__('Permission granted.'), true);
|
||||
$this->out(__('Permission <success>granted</success>.'), true);
|
||||
} else {
|
||||
$this->out(__('Permission was not granted.'), true);
|
||||
$this->out(__('Permission was <error>not granted</error>.'), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,7 +255,6 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function deny() {
|
||||
$this->_checkArgs(3, 'deny');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->deny($aro, $aco, $action)) {
|
||||
|
@ -276,7 +269,6 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function inherit() {
|
||||
$this->_checkArgs(3, 'inherit');
|
||||
extract($this->__getParams());
|
||||
|
||||
if ($this->Acl->inherit($aro, $aco, $action)) {
|
||||
|
@ -291,8 +283,6 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
public function view() {
|
||||
$this->_checkArgs(1, 'view');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
|
||||
if (isset($this->args[1])) {
|
||||
|
@ -442,7 +432,7 @@ class AclShell extends Shell {
|
|||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to check.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to check.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to check'))
|
||||
'action' => array('help' => __('Action to check'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('grant', array(
|
||||
|
@ -456,7 +446,7 @@ class AclShell extends Shell {
|
|||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to grant permission to.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to grant access to.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to grant'))
|
||||
'action' => array('help' => __('Action to grant'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('deny', array(
|
||||
|
@ -470,7 +460,7 @@ class AclShell extends Shell {
|
|||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to deny.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to deny.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to deny'))
|
||||
'action' => array('help' => __('Action to deny'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('inherit', array(
|
||||
|
@ -483,7 +473,7 @@ class AclShell extends Shell {
|
|||
'arguments' => array(
|
||||
'aro' => array('help' => __('ARO to have permisssions inherit.'), 'required' => true),
|
||||
'aco' => array('help' => __('ACO to inherit permissions on.'), 'required' => true),
|
||||
'action' => array('help' => __('Action to inherit'))
|
||||
'action' => array('help' => __('Action to inherit'), 'default' => 'all')
|
||||
)
|
||||
)
|
||||
))->addSubcommand('view', array(
|
||||
|
@ -517,19 +507,6 @@ class AclShell extends Shell {
|
|||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that first argument specifies a valid Node type (ARO/ACO)
|
||||
*
|
||||
*/
|
||||
public function checkNodeType() {
|
||||
if (!isset($this->args[0])) {
|
||||
return false;
|
||||
}
|
||||
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
|
||||
$this->error(sprintf(__("Missing/Unknown node type: '%s'"), $this->args[0]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that given node exists
|
||||
*
|
||||
|
@ -538,7 +515,7 @@ class AclShell extends Shell {
|
|||
* @return boolean Success
|
||||
*/
|
||||
public function nodeExists() {
|
||||
if (!$this->checkNodeType() && !isset($this->args[1])) {
|
||||
if (!isset($this->args[0]) || !isset($this->args[1])) {
|
||||
return false;
|
||||
}
|
||||
extract($this->__dataVars($this->args[0]));
|
||||
|
|
|
@ -136,9 +136,9 @@ class AclShellTest extends CakeTestCase {
|
|||
*/
|
||||
public function testCreate() {
|
||||
$this->Task->args = array('aro', 'root', 'User.1');
|
||||
$this->Task->expects($this->at(0))->method('out')->with("New Aro 'User.1' created.\n", true);
|
||||
$this->Task->expects($this->at(1))->method('out')->with("New Aro 'User.3' created.\n", true);
|
||||
$this->Task->expects($this->at(2))->method('out')->with("New Aro 'somealias' created.\n", true);
|
||||
$this->Task->expects($this->at(0))->method('out')->with("<success>New Aro</success> 'User.1' created.", 2);
|
||||
$this->Task->expects($this->at(1))->method('out')->with("<success>New Aro</success> 'User.3' created.", 2);
|
||||
$this->Task->expects($this->at(2))->method('out')->with("<success>New Aro</success> 'somealias' created.", 2);
|
||||
|
||||
$this->Task->create();
|
||||
|
||||
|
@ -178,7 +178,7 @@ class AclShellTest extends CakeTestCase {
|
|||
public function testDelete() {
|
||||
$this->Task->args = array('aro', 'AuthUser.1');
|
||||
$this->Task->expects($this->at(0))->method('out')
|
||||
->with("Aro deleted.\n", true);
|
||||
->with("<success>Aro deleted.</success>", 2);
|
||||
$this->Task->delete();
|
||||
|
||||
$Aro = ClassRegistry::init('Aro');
|
||||
|
@ -208,7 +208,7 @@ class AclShellTest extends CakeTestCase {
|
|||
public function testGrant() {
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expects($this->at(0))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||
->with($this->matchesRegularExpression('/granted/'), true);
|
||||
$this->Task->grant();
|
||||
|
||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||
|
@ -240,13 +240,13 @@ class AclShellTest extends CakeTestCase {
|
|||
*/
|
||||
public function testCheck() {
|
||||
$this->Task->expects($this->at(0))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/not allowed/'), true);
|
||||
->with($this->matchesRegularExpression('/not allowed/'), true);
|
||||
$this->Task->expects($this->at(1))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||
->with($this->matchesRegularExpression('/granted/'), true);
|
||||
$this->Task->expects($this->at(2))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/is allowed/'), true);
|
||||
->with($this->matchesRegularExpression('/is.*allowed/'), true);
|
||||
$this->Task->expects($this->at(3))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/not allowed/'), true);
|
||||
->with($this->matchesRegularExpression('/not.*allowed/'), true);
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
||||
$this->Task->check();
|
||||
|
@ -268,9 +268,9 @@ class AclShellTest extends CakeTestCase {
|
|||
*/
|
||||
public function testInherit() {
|
||||
$this->Task->expects($this->at(0))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||
->with($this->matchesRegularExpression('/Permission .*granted/'), true);
|
||||
$this->Task->expects($this->at(1))->method('out')
|
||||
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission inherited/'), true);
|
||||
->with($this->matchesRegularExpression('/Permission .*inherited/'), true);
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->grant();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue