Merge branch 'upgrade-sf3' of framagit.org:Chill-project/Chill-Person into upgrade-sf3

merge...
This commit is contained in:
nobohan 2018-04-04 22:02:29 +02:00
commit 833950046c
2 changed files with 21 additions and 26 deletions

View File

@ -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)
;
}
}

View File

@ -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()