diff --git a/cake/libs/model/db_acl.php b/cake/libs/model/db_acl.php index b8092050e..2b1585c57 100644 --- a/cake/libs/model/db_acl.php +++ b/cake/libs/model/db_acl.php @@ -82,21 +82,24 @@ class AclNode extends AppModel { return null; } elseif (is_string($ref)) { $path = explode('/', $ref); - $start = $path[count($path) - 1]; - unset($path[count($path) - 1]); + $start = $path[0]; + unset($path[0]); + $i = 0; + $cond = "WHERE ({$type}.lft <= {$type}{$i}.lft AND {$type}.rght >= {$type}{$i}.rght) "; $query = "SELECT {$type}.id, {$type}.parent_id, {$type}.model, {$type}.foreign_key, {$type}.alias FROM {$prefix}{$table} {$db->alias} {$type} "; $query .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}0 "; $query .= "ON {$type}0.alias = " . $db->value($start) . " "; foreach ($path as $i => $alias) { $j = $i - 1; - $k = $i + 1; - $query .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}{$k} "; - $query .= "ON {$type}{$k}.lft > {$type}{$i}.lft AND {$type}{$k}.rght < {$type}{$i}.rght "; - $query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " "; + $cond .="OR "; + $query .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}{$i} "; + $query .= "ON {$type}{$i}.lft > {$type}{$j}.lft AND {$type}{$i}.rght < {$type}{$j}.rght "; + $query .= "AND {$type}{$i}.alias = " . $db->value($alias) . " "; + $cond .="({$type}.lft <= {$type}{$i}.lft AND {$type}.rght >= {$type}{$i}.rght ) "; } - $result = $this->query("{$query} WHERE {$type}.lft <= {$type}0.lft AND {$type}.rght >= {$type}0.rght ORDER BY {$type}.lft DESC", $this->cacheQueries); + $result = $this->query("{$query} {$cond} ORDER BY {$type}.lft DESC", $this->cacheQueries); } elseif (is_object($ref) && is_a($ref, 'Model')) { $ref = array('model' => $ref->name, 'foreign_key' => $ref->id); } elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) { diff --git a/cake/tests/cases/libs/model/db_acl.test.php b/cake/tests/cases/libs/model/db_acl.test.php index 9bc87b35b..3dec0a18d 100644 --- a/cake/tests/cases/libs/model/db_acl.test.php +++ b/cake/tests/cases/libs/model/db_acl.test.php @@ -127,7 +127,7 @@ if(!class_exists('db_acl_test')) { * @subpackage cake.tests.cases.libs.controller.components.dbacl.models */ class AclNodeTest extends CakeTestCase { - var $fixtures = array( 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action'); + var $fixtures = array('core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action'); function testNodeNesting() { } diff --git a/cake/tests/fixtures/aco_fixture.php b/cake/tests/fixtures/aco_fixture.php index 38e4e3d34..d4592c3cf 100644 --- a/cake/tests/fixtures/aco_fixture.php +++ b/cake/tests/fixtures/aco_fixture.php @@ -44,15 +44,15 @@ class AcoFixture extends CakeTestFixture { 'rght' => array('type' => 'integer', 'length' => 10, 'null' => true) ); var $records = array( - array ('id' => 1, 'parent_id' => null, 'model' => '', 'foreign_key' => '', 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18), - array ('id' => 2, 'parent_id' => 1, 'model' => '', 'foreign_key' => '', 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), - array ('id' => 3, 'parent_id' => 2, 'model' => '', 'foreign_key' => '', 'alias' => 'action1', 'lft' => 3, 'rght' => 6), - array ('id' => 4, 'parent_id' => 3, 'model' => '', 'foreign_key' => '', 'alias' => 'record1', 'lft' => 4, 'rght' => 5), - array ('id' => 5, 'parent_id' => 2, 'model' => '', 'foreign_key' => '', 'alias' => 'action2', 'lft' => 7, 'rght' => 8), - array ('id' => 6, 'parent_id' => 1, 'model' => '', 'foreign_key' => '', 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17), - array ('id' => 7, 'parent_id' => 6, 'model' => '', 'foreign_key' => '', 'alias' => 'action1', 'lft' => 11, 'rght' => 14), - array ('id' => 8, 'parent_id' => 7, 'model' => '', 'foreign_key' => '', 'alias' => 'record1', 'lft' => 12, 'rght' => 13), - array ('id' => 9, 'parent_id' => 6, 'model' => '', 'foreign_key' => '', 'alias' => 'action2', 'lft' => 15, 'rght' => 16), + array ('id' => 1, 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18), + array ('id' => 2, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), + array ('id' => 3, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6), + array ('id' => 4, 'parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5), + array ('id' => 5, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8), + array ('id' => 6, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17), + array ('id' => 7, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14), + array ('id' => 8, 'parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13), + array ('id' => 9, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16), ); }