From 19de34b4dbbb66f1228b82a8be7816a60bd17250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 21:50:55 +0200 Subject: [PATCH 1/2] use fqdn for CreationPersonType --- Form/CreationPersonType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Form/CreationPersonType.php b/Form/CreationPersonType.php index da0b6a90b..5e432de42 100644 --- a/Form/CreationPersonType.php +++ b/Form/CreationPersonType.php @@ -27,7 +27,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\DateType; - +use Chill\MainBundle\Form\Type\CenterType; use Chill\PersonBundle\Form\Type\GenderType; use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer; @@ -101,7 +101,7 @@ class CreationPersonType extends AbstractType 'data' => $options['form_status'], 'mapped' => false )) - ->add('center', 'center') + ->add('center', CenterType::class) ; } } From b042a7ae55a76582161f1e1eeb1bf0c3727e411c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 21:51:16 +0200 Subject: [PATCH 2/2] rewrite PersonVoter for sf3 --- Security/Authorization/PersonVoter.php | 43 ++++++++++++-------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Security/Authorization/PersonVoter.php b/Security/Authorization/PersonVoter.php index 210c7a690..339301c30 100644 --- a/Security/Authorization/PersonVoter.php +++ b/Security/Authorization/PersonVoter.php @@ -23,6 +23,9 @@ use Chill\MainBundle\Security\Authorization\AbstractChillVoter; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; +use Chill\PersonBundle\Entity\Person; +use Chill\MainBundle\Entity\Center; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** * @@ -48,36 +51,28 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte $this->helper = $helper; } - protected function getSupportedAttributes() + protected function supports($attribute, $subject) { - return array(self::CREATE, self::UPDATE, self::SEE, self::STATS, self::LISTS); + if ($subject instanceof Person) { + return \in_array($attribute, [ + self::CREATE, self::UPDATE, self::SEE + ]); + } elseif ($subject instanceof Center) { + return \in_array($attribute, [ + self::STATS, self::LISTS + ]); + } else { + return false; + } } - - protected function getSupportedClasses() + + protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { - return array('Chill\PersonBundle\Entity\Person', 'Chill\MainBundle\Entity\Center'); - } - - protected function isGranted($attribute, $object, $user = null) - { - if (!$user instanceof User) { + if (!$token->getUser() instanceof User) { return false; } - if ($object instanceof \Chill\MainBundle\Entity\Center) { - if (! \in_array($attribute, [ self::STATS, self::LISTS ])) { - throw new \LogicException("the expected type is \Chill\MainBundle\Entity\Center for " - . "role, '".$attribute." ".get_class($object)."' given."); - } - } elseif ($object instanceof \Chill\PersonBundle\Entity\Person) { - if (\in_array($attribute, [ self::STATS, self::LISTS ])){ - 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); - + return $this->helper->userHasAccess($token->getUser(), $subject, $attribute); } public function getRoles()