I found this controller method that helps filtering access with a role name :
$this->denyAccessUnlessGranted('ROLE_EDIT', $item, 'You cannot edit this item.');
Is it possible to use the same method with multiple roles. I tried something like this but it doesnt seems to work :
$this->denyAccessUnlessGranted(array('ROLE_EDIT', 'ROLE_WHATEVER'), $item, 'You cannot edit this item.');
looking into the method shows how it works
protected function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.')
{
if (!$this->isGranted($attributes, $object)) {
throw $this->createAccessDeniedException($message);
}
}
so you could easily adapt this to your case
in your controller sth. like:
if(!$this->isGranted('ROLE_EDIT', $item) && !$this->isGranted('ROLE_OTHER', $item)){
throw $this->createAccessDeniedException('not allowed');
}
denyAccessUnlessGranted accepts an array of Role Names, so
$this->denyAccessUnlessGranted(['ROLE_EDIT', 'ROLE_ADMIN'], $item, 'You cannot edit this item.');
so, you should be able to pass all your roles.
Craig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With