mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
refactor voter to take into account two differents object type
This commit is contained in:
parent
9cb37a6115
commit
0ab2e85aef
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user