mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[FIX] use AuthorizationHelperInterface instead of implementation in PickCenterType
This commit is contained in:
parent
38cb1fe357
commit
524123c701
@ -15,6 +15,7 @@ use Chill\MainBundle\Center\GroupingCenterInterface;
|
|||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Export\ExportManager;
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
@ -24,6 +25,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
|||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
|
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use function array_intersect;
|
use function array_intersect;
|
||||||
use function array_key_exists;
|
use function array_key_exists;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
@ -38,30 +40,24 @@ class PickCenterType extends AbstractType
|
|||||||
{
|
{
|
||||||
public const CENTERS_IDENTIFIERS = 'c';
|
public const CENTERS_IDENTIFIERS = 'c';
|
||||||
|
|
||||||
/**
|
protected AuthorizationHelperInterface $authorizationHelper;
|
||||||
* @var AuthorizationHelper
|
|
||||||
*/
|
protected ExportManager $exportManager;
|
||||||
protected $authorizationHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ExportManager
|
* @var array|GroupingCenterInterface[]
|
||||||
*/
|
*/
|
||||||
protected $exportManager;
|
protected array $groupingCenters = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* @var GroupingCenterInterface[]
|
|
||||||
*/
|
|
||||||
protected $groupingCenters = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected UserInterface $user;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TokenStorageInterface $tokenStorage,
|
TokenStorageInterface $tokenStorage,
|
||||||
ExportManager $exportManager,
|
ExportManager $exportManager,
|
||||||
AuthorizationHelper $authorizationHelper
|
AuthorizationHelperInterface $authorizationHelper
|
||||||
) {
|
) {
|
||||||
$this->exportManager = $exportManager;
|
$this->exportManager = $exportManager;
|
||||||
$this->user = $tokenStorage->getToken()->getUser();
|
$this->user = $tokenStorage->getToken()->getUser();
|
||||||
@ -78,22 +74,12 @@ class PickCenterType extends AbstractType
|
|||||||
$export = $this->exportManager->getExport($options['export_alias']);
|
$export = $this->exportManager->getExport($options['export_alias']);
|
||||||
$centers = $this->authorizationHelper->getReachableCenters(
|
$centers = $this->authorizationHelper->getReachableCenters(
|
||||||
$this->user,
|
$this->user,
|
||||||
(string) $export->requiredRole()
|
$export->requiredRole()
|
||||||
);
|
);
|
||||||
|
|
||||||
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, [
|
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, [
|
||||||
'class' => Center::class,
|
'class' => Center::class,
|
||||||
'query_builder' => static function (EntityRepository $er) use ($centers) {
|
'choices' => $centers,
|
||||||
$qb = $er->createQueryBuilder('c');
|
|
||||||
$ids = array_map(
|
|
||||||
static function (Center $el) {
|
|
||||||
return $el->getId();
|
|
||||||
},
|
|
||||||
$centers
|
|
||||||
);
|
|
||||||
|
|
||||||
return $qb->where($qb->expr()->in('c.id', $ids));
|
|
||||||
},
|
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choice_label' => static function (Center $c) {
|
'choice_label' => static function (Center $c) {
|
||||||
|
@ -81,12 +81,8 @@ services:
|
|||||||
|
|
||||||
chill.main.form.pick_centers_type:
|
chill.main.form.pick_centers_type:
|
||||||
class: Chill\MainBundle\Form\Type\Export\PickCenterType
|
class: Chill\MainBundle\Form\Type\Export\PickCenterType
|
||||||
arguments:
|
autowire: true
|
||||||
- "@security.token_storage"
|
autoconfigure: true
|
||||||
- '@Chill\MainBundle\Export\ExportManager'
|
|
||||||
- "@chill.main.security.authorization.helper"
|
|
||||||
tags:
|
|
||||||
- { name: form.type }
|
|
||||||
|
|
||||||
chill.main.form.formatter_type:
|
chill.main.form.formatter_type:
|
||||||
class: Chill\MainBundle\Form\Type\Export\FormatterType
|
class: Chill\MainBundle\Form\Type\Export\FormatterType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user