Acl refactoring

This commit is contained in:
Frédéric Guillot
2014-12-31 12:37:15 -05:00
parent 66f150d887
commit 772804add8
93 changed files with 943 additions and 626 deletions

View File

@@ -62,14 +62,14 @@ class ProjectPermissionTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
// We allow the admin user
$this->assertTrue($pp->allowUser(1, 1));
$this->assertTrue($pp->allowUser(1, 2));
$this->assertTrue($pp->addMember(1, 1));
$this->assertTrue($pp->addMember(1, 2));
// Non-existant project
$this->assertFalse($pp->allowUser(50, 1));
$this->assertFalse($pp->addMember(50, 1));
// Non-existant user
$this->assertFalse($pp->allowUser(1, 50));
$this->assertFalse($pp->addMember(1, 50));
// Both users should be allowed
$this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
@@ -89,7 +89,7 @@ class ProjectPermissionTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
// We revoke our admin user (not existing row)
$this->assertFalse($pp->revokeUser(1, 1));
$this->assertFalse($pp->revokeMember(1, 1));
// We should have nobody in the users list
$this->assertEmpty($pp->getMembers(1));
@@ -99,7 +99,7 @@ class ProjectPermissionTest extends Base
$this->assertFalse($pp->isUserAllowed(1, 2));
// We allow only the regular user
$this->assertTrue($pp->allowUser(1, 2));
$this->assertTrue($pp->addMember(1, 2));
// All users should be allowed (admin and regular)
$this->assertTrue($pp->isUserAllowed(1, 1));
@@ -109,13 +109,13 @@ class ProjectPermissionTest extends Base
$this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1));
// We allow our admin, we should have both in the list
$this->assertTrue($pp->allowUser(1, 1));
$this->assertTrue($pp->addMember(1, 1));
$this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertTrue($pp->isUserAllowed(1, 2));
// We revoke the regular user
$this->assertTrue($pp->revokeUser(1, 2));
$this->assertTrue($pp->revokeMember(1, 2));
// Only admin should be allowed
$this->assertTrue($pp->isUserAllowed(1, 1));
@@ -125,7 +125,7 @@ class ProjectPermissionTest extends Base
$this->assertEquals(array('1' => 'admin'), $pp->getMembers(1));
// We revoke the admin user
$this->assertTrue($pp->revokeUser(1, 1));
$this->assertTrue($pp->revokeMember(1, 1));
$this->assertEmpty($pp->getMembers(1));
// Only admin should be allowed again
@@ -133,6 +133,42 @@ class ProjectPermissionTest extends Base
$this->assertFalse($pp->isUserAllowed(1, 2));
}
public function testManager()
{
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new User($this->container);
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertFalse($pp->isMember(1, 2));
$this->assertFalse($pp->isManager(1, 2));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2'), 1, true));
$this->assertFalse($pp->isMember(2, 2));
$this->assertFalse($pp->isManager(2, 2));
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3'), 2, true));
$this->assertTrue($pp->isMember(3, 2));
$this->assertTrue($pp->isManager(3, 2));
$this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
$this->assertTrue($pp->addManager(4, 2));
$this->assertTrue($pp->isMember(4, 2));
$this->assertTrue($pp->isManager(4, 2));
$this->assertEquals(5, $p->create(array('name' => 'UnitTest5')));
$this->assertTrue($pp->addMember(5, 2));
$this->assertTrue($pp->changeRole(5, 2, 1));
$this->assertTrue($pp->isMember(5, 2));
$this->assertTrue($pp->isManager(5, 2));
$this->assertTrue($pp->changeRole(5, 2, 0));
$this->assertTrue($pp->isMember(5, 2));
$this->assertFalse($pp->isManager(5, 2));
}
public function testUsersList()
{
$p = new Project($this->container);
@@ -151,7 +187,7 @@ class ProjectPermissionTest extends Base
);
// We allow only the regular user
$this->assertTrue($pp->allowUser(1, 2));
$this->assertTrue($pp->addMember(1, 2));
$this->assertEquals(
array(0 => 'Unassigned', 2 => 'unittest'),
@@ -159,7 +195,7 @@ class ProjectPermissionTest extends Base
);
// We allow the admin user
$this->assertTrue($pp->allowUser(1, 1));
$this->assertTrue($pp->addMember(1, 1));
$this->assertEquals(
array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'),
@@ -167,7 +203,7 @@ class ProjectPermissionTest extends Base
);
// We revoke only the regular user
$this->assertTrue($pp->revokeUser(1, 2));
$this->assertTrue($pp->revokeMember(1, 2));
$this->assertEquals(
array(0 => 'Unassigned', 1 => 'admin'),
@@ -175,7 +211,7 @@ class ProjectPermissionTest extends Base
);
// We revoke only the admin user, we should have everybody
$this->assertTrue($pp->revokeUser(1, 1));
$this->assertTrue($pp->revokeMember(1, 1));
$this->assertEquals(
array(0 => 'Unassigned'),