adding patch for Acl::allow(), fixes #4792, closes #4781

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7072 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-05-31 04:31:30 +00:00
parent 14df77c12d
commit c57b5611a0
2 changed files with 34 additions and 15 deletions

View file

@ -393,6 +393,7 @@ class DbAcl extends AclBase {
$save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id']; $save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id'];
} else { } else {
unset($save['id']); unset($save['id']);
$this->Aro->Permission->id = null;
} }
return ($this->Aro->Permission->save($save) !== false); return ($this->Aro->Permission->save($save) !== false);
} }

View file

@ -113,8 +113,8 @@ class AclComponentTest extends CakeTestCase {
$parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1); $parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
$this->Acl->Aro->create(); $this->Acl->Aro->create();
$this->Acl->Aro->save(array( $this->Acl->Aro->save(array(
'alias' => 'Subordinate', 'alias' => 'Subordinate',
'model' => 'User', 'model' => 'User',
'foreign_key' => 7, 'foreign_key' => 7,
'parent_id' => $parent['AroTwoTest']['id'] 'parent_id' => $parent['AroTwoTest']['id']
)); ));
@ -130,11 +130,29 @@ class AclComponentTest extends CakeTestCase {
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read')); $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete')); $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
// Michael no longer has his delete permission for tpsReports!
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view')); $this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*')); $this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
$this->assertTrue($this->Acl->check('Samir', 'view', 'read')); $this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update')); $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
// Samir should still have his tpsReports/view permissions, but does not
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->expectError('DbAcl::allow() - Invalid node'); $this->expectError('DbAcl::allow() - Invalid node');
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create')); $this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
@ -169,9 +187,9 @@ class AclComponentTest extends CakeTestCase {
/** /**
* testDbAclCascadingDeny function * testDbAclCascadingDeny function
* *
* Setup the acl permissions such that Bobs inherits from admin. * Setup the acl permissions such that Bobs inherits from admin.
* deny Admin delete access to a specific resource, check the permisssions are inherited. * deny Admin delete access to a specific resource, check the permisssions are inherited.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -183,7 +201,7 @@ class AclComponentTest extends CakeTestCase {
$this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete')); $this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
$this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete')); $this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
} }
function testDbAclDeny() { function testDbAclDeny() {
$this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete')); $this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
$this->Acl->deny('Micheal', 'smash', 'delete'); $this->Acl->deny('Micheal', 'smash', 'delete');
@ -369,12 +387,12 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* debug function - to help editing/creating test cases for the ACL component * debug function - to help editing/creating test cases for the ACL component
* *
* To check the overal ACL status at any time call $this->__debug(); * To check the overal ACL status at any time call $this->__debug();
* Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
* Only designed to work with the db based ACL * Only designed to work with the db based ACL
* *
* @param bool $treesToo * @param bool $treesToo
* @access private * @access private
* @return void * @return void
*/ */
@ -393,14 +411,14 @@ class AclComponentTest extends CakeTestCase {
if ($this->Acl->check($aro, $aco, $right)) { if ($this->Acl->check($aro, $aco, $right)) {
if ($right == '*') { if ($right == '*') {
$perms .= '****'; $perms .= '****';
break; break;
} }
$perms .= $right[0]; $perms .= $right[0];
} elseif ($right != '*') { } elseif ($right != '*') {
$perms .= ' '; $perms .= ' ';
} }
} }
$row[] = $perms; $row[] = $perms;
} }
$permissions[$aro] = $row; $permissions[$aro] = $row;
} }
@ -419,14 +437,14 @@ class AclComponentTest extends CakeTestCase {
/** /**
* pad function * pad function
* Used by debug to format strings used in the data dump * Used by debug to format strings used in the data dump
* *
* @param string $string * @param string $string
* @param int $len * @param int $len
* @access private * @access private
* @return void * @return void
*/ */
function __pad($string = '', $len = 14) { function __pad($string = '', $len = 14) {
return str_pad($string, $len); return str_pad($string, $len);
} }
} }
?> ?>