From 5896a77ae910d32b0a34611405cb714df361205b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 12 Jul 2022 11:10:18 +0200 Subject: [PATCH] Fixed: use CenterResolver where cases when center is resolved differently --- .../Controller/ActivityController.php | 13 ++++++++++--- src/Bundle/ChillActivityBundle/Entity/Activity.php | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index abf242af6..ee2634884 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -21,6 +21,9 @@ use Chill\ActivityBundle\Repository\ActivityTypeRepository; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Repository\LocationRepository; +use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher; +use Chill\MainBundle\Security\Resolver\CenterResolverInterface; +use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Privacy\PrivacyEvent; @@ -70,6 +73,8 @@ final class ActivityController extends AbstractController private ThirdPartyRepository $thirdPartyRepository; + private CenterResolverManagerInterface $centerResolver; + public function __construct( ActivityACLAwareRepositoryInterface $activityACLAwareRepository, ActivityTypeRepository $activityTypeRepository, @@ -82,7 +87,8 @@ final class ActivityController extends AbstractController EntityManagerInterface $entityManager, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, - SerializerInterface $serializer + SerializerInterface $serializer, + CenterResolverManagerInterface $centerResolver ) { $this->activityACLAwareRepository = $activityACLAwareRepository; $this->activityTypeRepository = $activityTypeRepository; @@ -96,6 +102,7 @@ final class ActivityController extends AbstractController $this->eventDispatcher = $eventDispatcher; $this->logger = $logger; $this->serializer = $serializer; + $this->centerResolver = $centerResolver; } /** @@ -198,7 +205,7 @@ final class ActivityController extends AbstractController // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); $form = $this->createForm(ActivityType::class, $entity, [ - 'center' => $entity->getCenters()[0] ?? null, + 'center' => $this->centerResolver->resolveCenters($entity)[0] ?? null, 'role' => new Role('CHILL_ACTIVITY_UPDATE'), 'activityType' => $entity->getActivityType(), 'accompanyingPeriod' => $accompanyingPeriod, @@ -416,7 +423,7 @@ final class ActivityController extends AbstractController $this->denyAccessUnlessGranted(ActivityVoter::CREATE, $entity); $form = $this->createForm(ActivityType::class, $entity, [ - 'center' => $entity->getCenters()[0] ?? null, + 'center' => $this->centerResolver->resolveCenters($entity)[0] ?? null, 'role' => new Role('CHILL_ACTIVITY_CREATE'), 'activityType' => $entity->getActivityType(), 'accompanyingPeriod' => $accompanyingPeriod, diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index faa042e03..828cb68f2 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -306,14 +306,14 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac * get the center * center is extracted from person. */ - public function getCenters(): array + public function getCenters(): iterable { if ($this->person instanceof Person) { return [$this->person->getCenter()]; } if ($this->getAccompanyingPeriod() instanceof AccompanyingPeriod) { - return $this->getAccompanyingPeriod()->getCenters(); + return $this->getAccompanyingPeriod()->getCenters() ?? []; } return [];