wip.. adapt EventVoter to sf3

This commit is contained in:
2019-01-17 16:21:35 +01:00
parent c235fb75a7
commit 15ff92257c
5 changed files with 103 additions and 47 deletions

View File

@@ -2,21 +2,15 @@
namespace Chill\EventBundle\Menu;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Role\Role;
use Knp\Menu\MenuItem;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\EventBundle\Security\Authorization\EventVoter;
class PersonMenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var TokenStorageInterface
*/
protected $tokenStorage;
/**
*
@@ -26,18 +20,16 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
/**
*
* @var AuthorizationHelper
* @var AuthorizationCheckerInterface
*/
protected $authorizationHelper;
protected $authorizationChecker;
public function __construct(
AuthorizationHelper $authorizationHelper,
TokenStorageInterface $tokenStorage,
AuthorizationCheckerInterface $authorizationChecker,
TranslatorInterface $translator
) {
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
$this->authorizationHelper = $authorizationHelper;
}
@@ -46,11 +38,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
/* @var $person \Chill\PersonBundle\Entity\Person */
$person = $parameters['person'];
$user = $this->tokenStorage->getToken()->getUser();
$roleSee = new Role(EventVoter::SEE);
// ASK use authorizationHelper or authorizationChecker ??
if ($this->authorizationHelper->userHasAccess($user, $person, $roleSee)) {
if ($this->authorizationChecker->isGranted(EventVoter::SEE, $person)) {
$menu->addChild($this->translator->trans('Events participation'), [
'route' => 'chill_event__list_by_person',