mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding ACL node locator fix for AclNode::node() (Ticket #2976)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5588 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ce51d009ac
commit
3723885be3
3 changed files with 20 additions and 17 deletions
|
@ -82,21 +82,24 @@ class AclNode extends AppModel {
|
||||||
return null;
|
return null;
|
||||||
} elseif (is_string($ref)) {
|
} elseif (is_string($ref)) {
|
||||||
$path = explode('/', $ref);
|
$path = explode('/', $ref);
|
||||||
$start = $path[count($path) - 1];
|
$start = $path[0];
|
||||||
unset($path[count($path) - 1]);
|
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 = "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 .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}0 ";
|
||||||
$query .= "ON {$type}0.alias = " . $db->value($start) . " ";
|
$query .= "ON {$type}0.alias = " . $db->value($start) . " ";
|
||||||
|
|
||||||
foreach ($path as $i => $alias) {
|
foreach ($path as $i => $alias) {
|
||||||
$j = $i - 1;
|
$j = $i - 1;
|
||||||
$k = $i + 1;
|
$cond .="OR ";
|
||||||
$query .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}{$k} ";
|
$query .= "LEFT JOIN {$prefix}{$table} {$db->alias} {$type}{$i} ";
|
||||||
$query .= "ON {$type}{$k}.lft > {$type}{$i}.lft AND {$type}{$k}.rght < {$type}{$i}.rght ";
|
$query .= "ON {$type}{$i}.lft > {$type}{$j}.lft AND {$type}{$i}.rght < {$type}{$j}.rght ";
|
||||||
$query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " ";
|
$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')) {
|
} elseif (is_object($ref) && is_a($ref, 'Model')) {
|
||||||
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
|
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
|
||||||
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
|
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
|
||||||
|
|
|
@ -127,7 +127,7 @@ if(!class_exists('db_acl_test')) {
|
||||||
* @subpackage cake.tests.cases.libs.controller.components.dbacl.models
|
* @subpackage cake.tests.cases.libs.controller.components.dbacl.models
|
||||||
*/
|
*/
|
||||||
class AclNodeTest extends CakeTestCase {
|
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() {
|
function testNodeNesting() {
|
||||||
}
|
}
|
||||||
|
|
18
cake/tests/fixtures/aco_fixture.php
vendored
18
cake/tests/fixtures/aco_fixture.php
vendored
|
@ -44,15 +44,15 @@ class AcoFixture extends CakeTestFixture {
|
||||||
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
||||||
);
|
);
|
||||||
var $records = array(
|
var $records = array(
|
||||||
array ('id' => 1, 'parent_id' => null, 'model' => '', 'foreign_key' => '', 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
|
array ('id' => 1, 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
|
||||||
array ('id' => 2, 'parent_id' => 1, 'model' => '', 'foreign_key' => '', 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
|
array ('id' => 2, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
|
||||||
array ('id' => 3, 'parent_id' => 2, 'model' => '', 'foreign_key' => '', 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
|
array ('id' => 3, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
|
||||||
array ('id' => 4, 'parent_id' => 3, 'model' => '', 'foreign_key' => '', 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
|
array ('id' => 4, 'parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
|
||||||
array ('id' => 5, 'parent_id' => 2, 'model' => '', 'foreign_key' => '', 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
|
array ('id' => 5, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
|
||||||
array ('id' => 6, 'parent_id' => 1, 'model' => '', 'foreign_key' => '', 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17),
|
array ('id' => 6, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17),
|
||||||
array ('id' => 7, 'parent_id' => 6, 'model' => '', 'foreign_key' => '', 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
|
array ('id' => 7, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
|
||||||
array ('id' => 8, 'parent_id' => 7, 'model' => '', 'foreign_key' => '', 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
|
array ('id' => 8, 'parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
|
||||||
array ('id' => 9, 'parent_id' => 6, 'model' => '', 'foreign_key' => '', 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
array ('id' => 9, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue