Commit 83395004 authored by Julien Minet's avatar Julien Minet

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

merge...
parents 193b6c3a b042a7ae
Pipeline #45978 passed with stages
in 5 minutes and 57 seconds
......@@ -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)
;
}
}
......
......@@ -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);
}
protected function getSupportedClasses()
{
return array('Chill\PersonBundle\Entity\Person', 'Chill\MainBundle\Entity\Center');
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 isGranted($attribute, $object, $user = null)
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment