mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Fixing ACL test, misc ACL lookup optimizations
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5916 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0f6c59ce50
commit
8f12e402df
6 changed files with 84 additions and 45 deletions
|
@ -295,31 +295,37 @@ class DB_ACL extends AclBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
$inherited = array();
|
$inherited = array();
|
||||||
|
$acoIDs = $acoPath->extract('{n}.' . $this->Aco->alias . '.id');
|
||||||
|
|
||||||
for ($i = 0 ; $i < count($aroPath); $i++) {
|
for ($i = 0 ; $i < count($aroPath); $i++) {
|
||||||
|
$permAlias = $this->Aro->Permission->alias;
|
||||||
|
|
||||||
$perms = $this->Aro->Permission->findAll(array(
|
$perms = $this->Aro->Permission->findAll(array(
|
||||||
$this->Aro->Permission->alias . '.aro_id' => $aroPath[$i][$this->Aro->alias]['id'],
|
"{$permAlias}.aro_id" => $aroPath[$i][$this->Aro->alias]['id'],
|
||||||
$this->Aro->Permission->alias . '.aco_id' => $acoPath->extract('{n}.' . $this->Aco->alias . '.id')),
|
"{$permAlias}.aco_id" => $acoIDs),
|
||||||
null, array($this->Aco->alias . '.lft' => 'desc'), null, null, 0);
|
null, array($this->Aco->alias . '.lft' => 'desc'), null, null, 0
|
||||||
|
);
|
||||||
|
|
||||||
if (empty($perms)) {
|
if (empty($perms)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
foreach (Set::extract($perms, '{n}.' . $this->Aro->Permission->alias) as $perm) {
|
$perms = Set::extract($perms, '{n}.' . $this->Aro->Permission->alias);
|
||||||
|
foreach ($perms as $perm) {
|
||||||
if ($action == '*') {
|
if ($action == '*') {
|
||||||
|
|
||||||
foreach ($permKeys as $key) {
|
foreach ($permKeys as $key) {
|
||||||
if (!empty($perm)) {
|
if (!empty($perm)) {
|
||||||
if ($perm[$key] == -1) {
|
if ($perm[$key] === -1) {
|
||||||
return false;
|
return false;
|
||||||
} elseif ($perm[$key] == 1) {
|
} elseif ($perm[$key] == 1) {
|
||||||
$inherited[$key] = 1;
|
$inherited[$key] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($inherited) === count($permKeys)) {
|
if (count($inherited) === count($permKeys)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
switch($perm['_' . $action]) {
|
switch($perm['_' . $action]) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -363,10 +369,7 @@ class DB_ACL extends AclBase {
|
||||||
|
|
||||||
if ($actions == "*") {
|
if ($actions == "*") {
|
||||||
$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());
|
$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());
|
||||||
|
$save = array_combine($permKeys, array_pad(array(), count($permKeys), $value));
|
||||||
foreach ($permKeys as $key) {
|
|
||||||
$save[$key] = $value;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!is_array($actions)) {
|
if (!is_array($actions)) {
|
||||||
$actions = array('_' . $actions);
|
$actions = array('_' . $actions);
|
||||||
|
|
|
@ -773,8 +773,9 @@ class Model extends Overloadable {
|
||||||
$sources = $db->listSources();
|
$sources = $db->listSources();
|
||||||
if (is_array($sources) && !in_array(low($this->tablePrefix . $tableName), array_map('low', $sources))) {
|
if (is_array($sources) && !in_array(low($this->tablePrefix . $tableName), array_map('low', $sources))) {
|
||||||
return $this->cakeError('missingTable', array(array(
|
return $this->cakeError('missingTable', array(array(
|
||||||
'className' => $this->alias,
|
'className' => $this->alias,
|
||||||
'table' => $this->tablePrefix . $tableName)));
|
'table' => $this->tablePrefix . $tableName
|
||||||
|
)));
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->_schema = null;
|
$this->_schema = null;
|
||||||
|
|
|
@ -58,9 +58,7 @@ if(!class_exists('permissiontest')) {
|
||||||
var $name = 'PermissionTest';
|
var $name = 'PermissionTest';
|
||||||
var $useTable = 'aros_acos';
|
var $useTable = 'aros_acos';
|
||||||
var $cacheQueries = false;
|
var $cacheQueries = false;
|
||||||
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'),
|
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'), 'AcoTest' => array('foreignKey' => 'aco_id'));
|
||||||
'AcoTest' => array('foreignKey' => 'aco_id')
|
|
||||||
);
|
|
||||||
var $actsAs = null;
|
var $actsAs = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,14 +89,55 @@ if(!class_exists('db_acl_test')) {
|
||||||
class AclComponentTest extends CakeTestCase {
|
class AclComponentTest 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 start() {
|
||||||
|
}
|
||||||
|
|
||||||
function startTest() {
|
function startTest() {
|
||||||
Configure::write('Acl.classname', 'DB_ACL_TEST');
|
|
||||||
Configure::write('Acl.database', 'test_suite');
|
|
||||||
$this->Acl =& new AclComponent();
|
$this->Acl =& new AclComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function before() {
|
||||||
|
if (!isset($this->_initialized)) {
|
||||||
|
Configure::write('Acl.classname', 'DB_ACL_TEST');
|
||||||
|
Configure::write('Acl.database', 'test_suite');
|
||||||
|
|
||||||
|
if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
|
||||||
|
unset($this->fixtures);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up DB connection
|
||||||
|
if (isset($this->fixtures)) {
|
||||||
|
$this->_initDb();
|
||||||
|
$this->_loadFixtures();
|
||||||
|
}
|
||||||
|
parent::start();
|
||||||
|
|
||||||
|
// Create records
|
||||||
|
if (isset($this->_fixtures) && isset($this->db)) {
|
||||||
|
foreach ($this->_fixtures as $fixture) {
|
||||||
|
$inserts = $fixture->insert();
|
||||||
|
|
||||||
|
if (isset($inserts) && !empty($inserts)) {
|
||||||
|
foreach ($inserts as $query) {
|
||||||
|
if (isset($query) && $query !== false) {
|
||||||
|
$this->db->execute($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->startTest();
|
||||||
|
$this->_initialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function after() {
|
||||||
|
}
|
||||||
|
|
||||||
function testAclCreate() {
|
function testAclCreate() {
|
||||||
$this->Acl->Aro->create(array('alias'=>'Global'));
|
$this->Acl->Aro->create(array('alias' => 'Global'));
|
||||||
$result = $this->Acl->Aro->save();
|
$result = $this->Acl->Aro->save();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
@ -118,7 +157,7 @@ class AclComponentTest extends CakeTestCase {
|
||||||
$result = $this->Acl->Aro->save();
|
$result = $this->Acl->Aro->save();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$this->Acl->Aco->create(array('alias'=>'Reports'));
|
$this->Acl->Aco->create(array('alias' => 'Reports'));
|
||||||
$result = $this->Acl->Aco->save();
|
$result = $this->Acl->Aco->save();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
@ -160,10 +199,10 @@ class AclComponentTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDbAclAllow() {
|
function testDbAclAllow() {
|
||||||
$result = $this->Acl->allow('Manager','Reports',array('read','delete','update'));
|
$result = $this->Acl->allow('Manager', 'Reports', array('read','delete','update'));
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $this->Acl->allow('Secretary','Links',array('create'));
|
$result = $this->Acl->allow('Secretary', 'Links', array('create'));
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,12 +264,8 @@ class AclComponentTest extends CakeTestCase {
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function after() {
|
|
||||||
parent::after('end');
|
|
||||||
}
|
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
unset($this->Acl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -84,9 +84,7 @@ if(!class_exists('permissiontest')) {
|
||||||
var $name = 'PermissionTest';
|
var $name = 'PermissionTest';
|
||||||
var $useTable = 'aros_acos';
|
var $useTable = 'aros_acos';
|
||||||
var $cacheQueries = false;
|
var $cacheQueries = false;
|
||||||
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'),
|
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'), 'AcoTest' => array('foreignKey' => 'aco_id'));
|
||||||
'AcoTest' => array('foreignKey' => 'aco_id')
|
|
||||||
);
|
|
||||||
var $actsAs = null;
|
var $actsAs = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +165,6 @@ if(!class_exists('db_acl_test')) {
|
||||||
$result = Set::extract($aco->node('Controller2/action3/record5'), '{n}.AcoTest.id');
|
$result = Set::extract($aco->node('Controller2/action3/record5'), '{n}.AcoTest.id');
|
||||||
$expected = array(6, 1);
|
$expected = array(6, 1);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
cake/tests/fixtures/aco_fixture.php
vendored
31
cake/tests/fixtures/aco_fixture.php
vendored
|
@ -35,24 +35,25 @@
|
||||||
class AcoFixture extends CakeTestFixture {
|
class AcoFixture extends CakeTestFixture {
|
||||||
var $name = 'Aco';
|
var $name = 'Aco';
|
||||||
var $fields = array(
|
var $fields = array(
|
||||||
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
|
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
|
||||||
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||||
'model' => array('type' => 'string', 'default' => ''),
|
'model' => array('type' => 'string', 'default' => ''),
|
||||||
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||||
'alias' => array('type' => 'string', 'default' => ''),
|
'alias' => array('type' => 'string', 'default' => ''),
|
||||||
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||||
'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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, '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' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
array('id' => 9, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
cake/tests/fixtures/aro_fixture.php
vendored
2
cake/tests/fixtures/aro_fixture.php
vendored
|
@ -34,6 +34,7 @@
|
||||||
*/
|
*/
|
||||||
class AroFixture extends CakeTestFixture {
|
class AroFixture extends CakeTestFixture {
|
||||||
var $name = 'Aro';
|
var $name = 'Aro';
|
||||||
|
|
||||||
var $fields = array(
|
var $fields = array(
|
||||||
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
|
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
|
||||||
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||||
|
@ -43,6 +44,7 @@ class AroFixture extends CakeTestFixture {
|
||||||
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||||
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
||||||
);
|
);
|
||||||
|
|
||||||
var $records = array(
|
var $records = array(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue