From 0ab2e85aef55d9ff2775411d6fcfef6fd7bbf621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 26 Jan 2016 11:23:38 +0100 Subject: [PATCH] refactor voter to take into account two differents object type --- Security/Authorization/PersonVoter.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Security/Authorization/PersonVoter.php b/Security/Authorization/PersonVoter.php index 8808882f8..916966a8a 100644 --- a/Security/Authorization/PersonVoter.php +++ b/Security/Authorization/PersonVoter.php @@ -57,13 +57,23 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleInterface return array('Chill\PersonBundle\Entity\Person', 'Chill\MainBundle\Entity\Center'); } - protected function isGranted($attribute, $person, $user = null) + protected function isGranted($attribute, $object, $user = null) { if (!$user instanceof User) { return false; } - return $this->helper->userHasAccess($user, $person, $attribute); + if ($attribute === self::STATS and !$object instanceof \Chill\MainBundle\Entity\Center) { + throw new \LogicException("the expected type is \Chill\MainBundle\Entity\Center for " + . "role ".self::STATS." ".get_class($object)." given."); + } + + if ($attribute !== self::STATS and !$object instanceof \Chill\PersonBundle\Entity\Person) { + throw new \LogicException("the expected type is \Chill\PersonBundle\Entity\Person for " + . "role ".$attribute." ".get_class($object)." given."); + } + + return $this->helper->userHasAccess($user, $object, $attribute); }