Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing AclNode::node() so that node expressions that could match deep…

…er elements are contained to their parent elements. Test added.
  • Loading branch information...
commit 068631ebe227cf79fcd8fe660e79e1d80ce84731 1 parent 46348e9
@markstory markstory authored
View
3  cake/libs/model/db_acl.php
@@ -111,7 +111,8 @@ function node($ref = null) {
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
- $db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string')
+ $db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string'),
+ $db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id")
)
);
View
16 cake/tests/cases/libs/model/db_acl.test.php
@@ -283,7 +283,7 @@ function setUp() {
* @return void
*/
function testNode() {
- $Aco = new DbAcoTest();
+ $Aco =& new DbAcoTest();
$result = Set::extract($Aco->node('Controller1'), '{n}.DbAcoTest.id');
$expected = array(2, 1);
$this->assertEqual($result, $expected);
@@ -317,7 +317,19 @@ function testNode() {
$result = $Aco->node('');
$this->assertEqual($result, null);
}
- /**
+
+/**
+ * test that node() doesn't dig deeper than it should.
+ *
+ * @return void
+ */
+ function testNodeWithDuplicatePathSegments() {
+ $Aco =& new DbAcoTest();
+ $nodes = $Aco->node('ROOT/Users');
+ $this->assertEqual($nodes[0]['DbAcoTest']['parent_id'], 1, 'Parent id does not point at ROOT. %s');
+ }
+
+/**
* testNodeArrayFind method
*
* @access public
View
5 cake/tests/fixtures/aco_fixture.php
@@ -57,7 +57,7 @@ class AcoFixture extends CakeTestFixture {
* @access public
*/
var $records = array(
- array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
+ array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 24),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
@@ -66,6 +66,9 @@ class AcoFixture extends CakeTestFixture {
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
+ array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 18, 'rght' => 23),
+ array('parent_id' => 9, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 19, 'rght' => 22),
+ array('parent_id' => 10, 'model' => null, 'foreign_key' => null, 'alias' => 'view', 'lft' => 20, 'rght' => 21),
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.