8000 Fixed the sample security voter to take into account the role hierarchy by javiereguiluz · Pull Request #5024 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor fixes in the sample code
  • Loading branch information
javiereguiluz committed Feb 19, 2015
commit f9be8688063406f4442a38abb8307517206d6ec6
8 changes: 4 additions & 4 deletions best_practices/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ the same ``getAuthorEmail`` logic you used above:
const CREATE = 'create';
const EDIT = 'edit';

protected $roleHierarchy;
private $roleHierarchy;

public function __construct(RoleHierarchyInterface $roleHierarchy)
{
$this->roleHierarchy = $roleHirarchy;
$this->roleHierarchy = $roleHierarchy;
}

protected function getSupportedAttributes()
Expand All @@ -172,7 +172,7 @@ the same ``getAuthorEmail`` logic you used above:
return false;
}

if ($attribute === self::CREATE && $this->hasRole('ROLE_ADMIN', $user)) {
if ($attribute === self::CREATE && $this->userHasRole($user, 'ROLE_ADMIN')) {
return true;
}

Expand All @@ -187,7 +187,7 @@ the same ``getAuthorEmail`` logic you used above:
* Checks if the user token has the given role taking into account the
* entire role hierarchy defined by the application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] hierarchy if defined [...] or [...] hierarchy as defined [...]?

*/
protected function hasRole($roleName, TokenInterface $userToken)
private function userHasRole(TokenInterface $userToken, $roleName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should pass UserInterface here.

private function userHasRole(UserInterface $user, $roleName)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better. Fixed now. Thanks.

{
foreach ($this->roleHierarchy->getReachableRoles($userToken->getRoles()) as $role) {
if ($roleName === $role->getRole()) {
Expand Down
0