Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62cbfdd

Browse files
committed
bug #23069 [SecurityBundle] Show unique Inherited roles in profile panel (yceruto)
This PR was merged into the 2.7 branch. Discussion ---------- [SecurityBundle] Show unique Inherited roles in profile panel | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT When more than one assigned role reaches the same inherited role then it's duplicated in the "Inherited roles" list. The changes in the test case show the unexpected result before fix it: ```console There was 1 failure: 1) Symfony\Bundle\SecurityBundle\Tests\DataCollector\SecurityDataCollectorTest::testCollectAuthenticationTokenAndRoles with data set #4 (array('ROLE_ADMIN', 'ROLE_OPERATOR'), array('ROLE_ADMIN', 'ROLE_OPERATOR'), array('ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH')) Failed asserting that Array &0 ( 0 => 'ROLE_USER' 1 => 'ROLE_ALLOWED_TO_SWITCH' 2 => 'ROLE_USER' ) is identical to Array &0 ( 0 => 'ROLE_USER' 1 => 'ROLE_ALLOWED_TO_SWITCH' ) ``` Commits ------- 7061bfb show unique inherited roles
2 parents 658236b + 7061bfb commit 62cbfdd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function collect(Request $request, Response $response, \Exception $except
8282
'token_class' => get_class($token),
8383
'user' => $token->getUsername(),
8484
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles),
85-
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
85+
'inherited_roles' => array_unique(array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles)),
8686
'supports_role_hierarchy' => null !== $this->roleHierarchy,
8787
);
8888
}

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,19 @@ public function provideRoles()
111111
array('ROLE_ADMIN'),
112112
array('ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH'),
113113
),
114+
array(
115+
array('ROLE_ADMIN', 'ROLE_OPERATOR'),
116+
array('ROLE_ADMIN', 'ROLE_OPERATOR'),
117+
array('ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH'),
118+
),
114119
);
115120
}
116121

117122
private function getRoleHierarchy()
118123
{
119124
return new RoleHierarchy(array(
120125
'ROLE_ADMIN' => array('ROLE_USER', 'ROLE_ALLOWED_TO_SWITCH'),
126+
'ROLE_OPERATOR' => array('ROLE_USER'),
121127
));
122128
}
123129

0 commit comments

Comments
 (0)