Skip to content

Commit

Permalink
Updating AclShell to use new formatting and removing methods that are…
Browse files Browse the repository at this point in the history
… no longer needed.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 0fd8d2b commit 43646b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
43 changes: 10 additions & 33 deletions cake/console/libs/acl.php
Expand Up @@ -84,7 +84,7 @@ public function startup() {
$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;
Expand Down Expand Up @@ -162,8 +162,6 @@ public function delete() {
*
*/
public function setParent() {
$this->_checkArgs(3, 'setParent');
$this->checkNodeType();
extract($this->__dataVars());
$target = $this->parseIdentifier($this->args[1]);
$parent = $this->parseIdentifier($this->args[2]);
Expand All @@ -187,8 +185,6 @@ public function setParent() {
*
*/
public function getPath() {
$this->_checkArgs(2, 'getPath');
$this->checkNodeType();
extract($this->__dataVars());
$identifier = $this->parseIdentifier($this->args[1]);

Expand Down Expand Up @@ -231,13 +227,12 @@ protected function _outputNode($class, $node, $indent) {
*
*/
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);
}
}

Expand All @@ -246,13 +241,12 @@ public function check() {
*
*/
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);
}
}

Expand All @@ -261,7 +255,6 @@ public function grant() {
*
*/
public function deny() {
$this->_checkArgs(3, 'deny');
extract($this->__getParams());

if ($this->Acl->deny($aro, $aco, $action)) {
Expand All @@ -276,7 +269,6 @@ public function deny() {
*
*/
public function inherit() {
$this->_checkArgs(3, 'inherit');
extract($this->__getParams());

if ($this->Acl->inherit($aro, $aco, $action)) {
Expand All @@ -291,8 +283,6 @@ public function inherit() {
*
*/
public function view() {
$this->_checkArgs(1, 'view');
$this->checkNodeType();
extract($this->__dataVars());

if (isset($this->args[1])) {
Expand Down Expand Up @@ -442,7 +432,7 @@ public function getOptionParser() {
'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(
Expand All @@ -456,7 +446,7 @@ public function getOptionParser() {
'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(
Expand All @@ -470,7 +460,7 @@ public function getOptionParser() {
'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(
Expand All @@ -483,7 +473,7 @@ public function getOptionParser() {
'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(
Expand Down Expand Up @@ -517,19 +507,6 @@ public function getOptionParser() {
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
*
Expand All @@ -538,7 +515,7 @@ public function checkNodeType() {
* @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]));
Expand Down
22 changes: 11 additions & 11 deletions cake/tests/cases/console/libs/acl.test.php
Expand Up @@ -136,9 +136,9 @@ public function testParsingModelAndForeignKey() {
*/
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();

Expand Down Expand Up @@ -178,7 +178,7 @@ public function testCreate() {
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');
Expand Down Expand Up @@ -208,7 +208,7 @@ public function testSetParent() {
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);
Expand Down Expand Up @@ -240,13 +240,13 @@ public function testDeny() {
*/
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();
Expand All @@ -268,9 +268,9 @@ public function testCheck() {
*/
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();
Expand Down

0 comments on commit 43646b9

Please sign in to comment.