mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
AuthorizationHelper: compare center and scope based on id, not on equality
For an unknown reason, in some circumstances, the use of the `===` comparator does not work when comparing Center instances and Scope instances. Then, we compare them based on the id.
This commit is contained in:
@@ -47,7 +47,8 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
|
||||
public function dataProvider_getReachableCenters()
|
||||
{
|
||||
$this->setUp();
|
||||
self::bootKernel();
|
||||
|
||||
$centerA = $this->prepareCenter(1, 'center A');
|
||||
$centerB = $this->prepareCenter(2, 'center B');
|
||||
$scopeA = $this->prepareScope(1, 'scope default');
|
||||
@@ -311,9 +312,9 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
public function testUserHasAccessEntityMultiScope()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'center');
|
||||
$centerB = $this->prepareCenter(1, 'centerB');
|
||||
$scopeA = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$scopeB = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$centerB = $this->prepareCenter(2, 'centerB');
|
||||
$scopeA = $this->prepareScope(3, 'other'); //the user will be granted this scope
|
||||
$scopeB = $this->prepareScope(4, 'other'); //the user will be granted this scope
|
||||
$user = $this->prepareUser([
|
||||
[
|
||||
'center' => $centerA, 'permissionsGroup' => [
|
||||
@@ -331,6 +332,24 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
$this->assertTrue($helper->userHasAccess($user, $entity->reveal(), 'CHILL_ROLE'));
|
||||
}
|
||||
|
||||
public function testUserHasAccessEntityIsCenter()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'center');
|
||||
$centerB = $this->prepareCenter(2, 'centerB');
|
||||
$user = $this->prepareUser([
|
||||
[
|
||||
'center' => $centerA, 'permissionsGroup' => [
|
||||
['scope' => null, 'role' => 'CHILL_ROLE'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$helper = $this->getAuthorizationHelper();
|
||||
|
||||
$this->assertFalse($helper->userHasAccess($user, $centerB, 'CHILL_ROLE'));
|
||||
$this->assertTrue($helper->userHasAccess($user, $centerA, 'CHILL_ROLE'));
|
||||
}
|
||||
|
||||
public function testUserHasAccessMultiCenterEntityWithoutScope()
|
||||
{
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
@@ -515,10 +534,10 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
public function testUserHasNoAccessEntityMultiScope()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'center');
|
||||
$centerB = $this->prepareCenter(1, 'centerB');
|
||||
$scopeA = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$scopeB = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$scopeC = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$centerB = $this->prepareCenter(2, 'centerB');
|
||||
$scopeA = $this->prepareScope(3, 'other'); //the user will be granted this scope
|
||||
$scopeB = $this->prepareScope(4, 'other'); //the user will be granted this scope
|
||||
$scopeC = $this->prepareScope(5, 'other'); //the user will be granted this scope
|
||||
$user = $this->prepareUser([
|
||||
[
|
||||
'center' => $centerA, 'permissionsGroup' => [
|
||||
@@ -539,9 +558,9 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
public function testUserHasNoAccessMultiCenterEntityWithoutScope()
|
||||
{
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$centerB = $this->prepareCenter(1, 'centerB');
|
||||
$centerC = $this->prepareCenter(1, 'centerC');
|
||||
$scopeB = $this->prepareScope(2, 'other'); //the user will be granted this scope
|
||||
$centerB = $this->prepareCenter(2, 'centerB');
|
||||
$centerC = $this->prepareCenter(3, 'centerC');
|
||||
$scopeB = $this->prepareScope(4, 'other'); //the user will be granted this scope
|
||||
$user = $this->prepareUser([
|
||||
[
|
||||
'center' => $center, 'permissionsGroup' => [
|
||||
|
Reference in New Issue
Block a user