diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 1b31ac5d315..f6ab50e1d08 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -1,10 +1,6 @@ _checkArgs(2, 'getPath'); $this->checkNodeType(); extract($this->__dataVars()); - $id = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]); + $identifier = $this->parseIdentifier($this->args[1]); + + $id = $this->_getNodeId($class, $identifier); $nodes = $this->Acl->{$class}->getPath($id); + if (empty($nodes)) { - $this->error(sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true)); + $this->error( + sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), + __("No tree returned.", true) + ); } for ($i = 0; $i < count($nodes); $i++) { - $this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n"); + $this->_outputNode($class, $nodes[$i], $i); + } + } + +/** + * Outputs a single node, Either using the alias or Model.key + * + * @param string $class Class name that is being used. + * @param array $node Array of node information. + * @param integer $indent indent level. + * @return void + * @access protected + **/ + function _outputNode($class, $node, $indent) { + $indent = str_repeat(' ', $indent); + $data = $node[$class]; + if ($data['alias']) { + $this->out($indent . "[" . $data['id'] . "] " . $data['alias']); + } else { + $this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']); } } diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 095895562c0..5d7ccfc1577 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -1,6 +1,4 @@ Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true)); $this->Task->check(); } + +/** + * test inherit and that it 0's the permission fields. + * + * @return void + **/ + function testInherit() { + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create'); + $this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true)); + $this->Task->grant(); + + $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all'); + $this->Task->expectAt(1, 'out', array(new PatternExpectation('/permission inherited/i'), true)); + $this->Task->inherit(); + + $node = $this->Task->Acl->Aro->read(null, 4); + $this->assertFalse(empty($node['Aco'][0])); + $this->assertEqual($node['Aco'][0]['Permission']['_create'], 0); + } + +/** + * test getting the path for an aro/aco + * + * @return void + **/ + function testGetPath() { + $this->Task->args = array('aro', 'AuthUser.2'); + $this->Task->expectAt(0, 'out', array('[1] ROOT')); + $this->Task->expectAt(1, 'out', array(' [2] admins')); + $this->Task->expectAt(2, 'out', array(' [4] Elrond')); + $this->Task->getPath(); + } } ?> \ No newline at end of file