Skip to content

Commit

Permalink
redone bill management permissions: + roles: billManager/Creator/Deleter
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Oct 31, 2016
1 parent d50dcbc commit b4f8334
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 41 deletions.
26 changes: 17 additions & 9 deletions src/Initer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,57 @@ public static function init(AuthManager $auth)
$auth->setRole('reseller');
$auth->setRole('owner');
$auth->setRole('freezer');
$auth->setRole('billCreator');
$auth->setRole('billDeleter');
$auth->setRole('billManager');

$auth->setPermission('restore-password');
$auth->setPermission('deposit');
$auth->setPermission('supporting');
$auth->setPermission('do-support');
$auth->setPermission('manage');
$auth->setPermission('administrate');
$auth->setPermission('resell');
$auth->setPermission('own');
$auth->setPermission('root');

$auth->setPermission('freeze');
$auth->setPermission('unfreeze');
$auth->setPermission('create-bills');
$auth->setPermission('update-bills');
$auth->setPermission('delete-bills');
$auth->setPermission('edit-bills');

$auth->setChild('client', 'restore-password');
$auth->setChild('client', 'deposit');

$auth->setChild('support', 'supporting');
$auth->setChild('support', 'do-support');

$auth->setChild('admin', 'support');
$auth->setChild('admin', 'administrate');

$auth->setChild('manager', 'support');
$auth->setChild('manager', 'manage');

$auth->setChild('reseller', 'manager');
$auth->setChild('reseller', 'billManager');
$auth->setChild('reseller', 'resell');
$auth->setChild('reseller', 'deposit');

$auth->setChild('owner', 'reseller');
$auth->setChild('owner', 'billManager');
$auth->setChild('owner', 'resell');
$auth->setChild('owner', 'own');

$auth->setChild('freezer', 'freeze');
$auth->setChild('freezer', 'unfreeze');

$auth->setChild('billCreator', 'create-bills');
$auth->setChild('billDeleter', 'delete-bills');

$auth->setChild('billManager', 'manager');
$auth->setChild('billManager', 'create-bills');
$auth->setChild('billManager', 'update-bills');
$auth->setChild('billManager', 'delete-bills');
$auth->setChild('billManager', 'edit-bills');

$auth->setAssignment('freezer', 'sol');
$auth->setAssignment('freezer', 'andre');

$auth->setAssignment('manager', 'sol');

$auth->setAssignment('billManager', 'sol');
$auth->setAssignment('billManager', 'margo');
$auth->setAssignment('billManager', 'dsr');
Expand Down
1 change: 0 additions & 1 deletion src/files/assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
return [
'sol' => [
'freezer',
'manager',
'billManager',
],
'andre' => [
Expand Down
36 changes: 26 additions & 10 deletions src/files/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'support' => [
'type' => 1,
'children' => [
'supporting',
'do-support',
],
],
'admin' => [
Expand All @@ -30,14 +30,16 @@
'reseller' => [
'type' => 1,
'children' => [
'manager',
'billManager',
'resell',
'deposit',
],
],
'owner' => [
'type' => 1,
'children' => [
'reseller',
'billManager',
'resell',
'own',
],
],
Expand All @@ -48,11 +50,25 @@
'unfreeze',
],
],
'billCreator' => [
'type' => 1,
'children' => [
'create-bills',
],
],
'billDeleter' => [
'type' => 1,
'children' => [
'delete-bills',
],
],
'billManager' => [
'type' => 1,
'children' => [
'manager',
'create-bills',
'update-bills',
'delete-bills',
'edit-bills',
],
],
'restore-password' => [
Expand All @@ -61,7 +77,7 @@
'deposit' => [
'type' => 2,
],
'supporting' => [
'do-support' => [
'type' => 2,
],
'manage' => [
Expand All @@ -76,19 +92,19 @@
'own' => [
'type' => 2,
],
'root' => [
'type' => 2,
],
'freeze' => [
'type' => 2,
],
'unfreeze' => [
'type' => 2,
],
'delete-bills' => [
'create-bills' => [
'type' => 2,
],
'update-bills' => [
'type' => 2,
],
'edit-bills' => [
'delete-bills' => [
'type' => 2,
],
];
45 changes: 24 additions & 21 deletions tests/unit/CheckAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,65 @@ public function setAssignments()

public function testClient()
{
$this->assertTrue($this->auth->checkAccess('client', 'client'));
$this->assertTrue($this->auth->checkAccess('client', 'deposit'));
$this->assertTrue($this->auth->checkAccess('client', 'restore-password'));

$this->assertFalse($this->auth->checkAccess('client', 'support'));
$this->assertFalse($this->auth->checkAccess('client', 'supporting'));
$this->assertFalse($this->auth->checkAccess('client', 'manager'));
$this->assertFalse($this->auth->checkAccess('client', 'do-support'));
$this->assertFalse($this->auth->checkAccess('client', 'manage'));
$this->assertFalse($this->auth->checkAccess('client', 'freezer'));
$this->assertFalse($this->auth->checkAccess('client', 'freeze'));
$this->assertFalse($this->auth->checkAccess('client', 'unfreeze'));
$this->assertFalse($this->auth->checkAccess('client', 'admin'));
$this->assertFalse($this->auth->checkAccess('client', 'administrate'));
$this->assertFalse($this->auth->checkAccess('client', 'reseller'));
$this->assertFalse($this->auth->checkAccess('client', 'resell'));
$this->assertFalse($this->auth->checkAccess('client', 'owner'));
$this->assertFalse($this->auth->checkAccess('client', 'own'));
}

public function testSupport()
{
$this->assertTrue($this->auth->checkAccess('support', 'support'));
$this->assertTrue($this->auth->checkAccess('support', 'supporting'));
$this->assertTrue($this->auth->checkAccess('support', 'do-support'));

$this->assertFalse($this->auth->checkAccess('support', 'client'));
$this->assertFalse($this->auth->checkAccess('support', 'deposit'));
$this->assertFalse($this->auth->checkAccess('support', 'restore-password'));
$this->assertFalse($this->auth->checkAccess('support', 'manager'));
$this->assertFalse($this->auth->checkAccess('support', 'manage'));
$this->assertFalse($this->auth->checkAccess('support', 'freezer'));
$this->assertFalse($this->auth->checkAccess('support', 'freeze'));
$this->assertFalse($this->auth->checkAccess('support', 'unfreeze'));
$this->assertFalse($this->auth->checkAccess('support', 'admin'));
$this->assertFalse($this->auth->checkAccess('support', 'administrate'));
$this->assertFalse($this->auth->checkAccess('support', 'reseller'));
$this->assertFalse($this->auth->checkAccess('support', 'resell'));
$this->assertFalse($this->auth->checkAccess('support', 'owner'));
$this->assertFalse($this->auth->checkAccess('support', 'own'));
}

public function testManager()
{
$this->assertTrue($this->auth->checkAccess('manager', 'do-support'));
$this->assertTrue($this->auth->checkAccess('manager', 'manage'));

$this->assertFalse($this->auth->checkAccess('manager', 'deposit'));
$this->assertFalse($this->auth->checkAccess('manager', 'restore-password'));
$this->assertFalse($this->auth->checkAccess('manager', 'administrate'));
$this->assertFalse($this->auth->checkAccess('manager', 'resell'));
$this->assertFalse($this->auth->checkAccess('manager', 'owner'));
$this->assertFalse($this->auth->checkAccess('manager', 'own'));
$this->assertFalse($this->auth->checkAccess('manager', 'freeze'));
$this->assertFalse($this->auth->checkAccess('manager', 'unfreeze'));
$this->assertFalse($this->auth->checkAccess('manager', 'create-bills'));
$this->assertFalse($this->auth->checkAccess('manager', 'update-bills'));
$this->assertFalse($this->auth->checkAccess('manager', 'delete-bills'));
}

public function testSol()
{
$this->assertTrue($this->auth->checkAccess('sol', 'support'));
$this->assertTrue($this->auth->checkAccess('sol', 'supporting'));
$this->assertTrue($this->auth->checkAccess('sol', 'manager'));
$this->assertTrue($this->auth->checkAccess('sol', 'do-support'));
$this->assertTrue($this->auth->checkAccess('sol', 'manage'));
$this->assertTrue($this->auth->checkAccess('sol', 'freezer'));
$this->assertTrue($this->auth->checkAccess('sol', 'freeze'));
$this->assertTrue($this->auth->checkAccess('sol', 'unfreeze'));
$this->assertTrue($this->auth->checkAccess('sol', 'admin'));
$this->assertTrue($this->auth->checkAccess('sol', 'administrate'));
$this->assertTrue($this->auth->checkAccess('sol', 'create-bills'));
$this->assertTrue($this->auth->checkAccess('sol', 'update-bills'));
$this->assertTrue($this->auth->checkAccess('sol', 'delete-bills'));

$this->assertFalse($this->auth->checkAccess('sol', 'client'));
$this->assertFalse($this->auth->checkAccess('sol', 'deposit'));
$this->assertFalse($this->auth->checkAccess('sol', 'restore-password'));
$this->assertFalse($this->auth->checkAccess('sol', 'reseller'));
$this->assertFalse($this->auth->checkAccess('sol', 'resell'));
$this->assertFalse($this->auth->checkAccess('sol', 'owner'));
$this->assertFalse($this->auth->checkAccess('sol', 'own'));
Expand Down

0 comments on commit b4f8334

Please sign in to comment.