From c791c482484f54069ac116769c4d5eedabe5070c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 28 Sep 2021 14:06:52 +0200 Subject: [PATCH] tp: adapt to new ACL interface (wip) --- .../Controller/ThirdPartyController.php | 32 +++++++++---------- .../ThirdPartyACLAwareRepository.php | 23 +++++++++++++ .../ThirdPartyACLAwareRepositoryInterface.php | 16 ++++++++++ .../Security/Voter/ThirdPartyVoter.php | 2 ++ 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepositoryInterface.php diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php index d16934b18..dff892b99 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php @@ -66,8 +66,8 @@ class ThirdPartyController extends Controller $this->getUser(), new Role(ThirdPartyVoter::SHOW) ); - - $nbThirdParties = $repository->countByMemberOfCenters($centers); + + $nbThirdParties = $repository->countByMemberOfCenters($centers); // $pagination = $this->paginatorFactory->create($nbThirdParties); $thirdParties = $repository->findByMemberOfCenters( @@ -88,18 +88,18 @@ class ThirdPartyController extends Controller public function newAction(Request $request) { $this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE); - - $centers = $this->authorizationHelper + + /* $centers = $this->authorizationHelper ->getReachableCenters( - $this->getUser(), + $this->getUser(), new Role(ThirdPartyVoter::CREATE) ); - - if (count($centers) === 0) { + + if ($centers === []) { // throw new \LogicException("There should be at least one center reachable " . "if role ".ThirdPartyVoter::CREATE." is granted"); - } - + } */ + $thirdParty = new ThirdParty(); $thirdParty->setCenters(new ArrayCollection($centers)); @@ -141,18 +141,18 @@ class ThirdPartyController extends Controller public function updateAction(ThirdParty $thirdParty, Request $request) { $this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE); - - $centers = $this->authorizationHelper + + /* $centers = $this->authorizationHelper ->getReachableCenters( - $this->getUser(), + $this->getUser(), new Role(ThirdPartyVoter::CREATE) ); - - if (count($centers) === 0) { + + if ($centers === []) { throw new \LogicException("There should be at least one center reachable " . "if role ".ThirdPartyVoter::CREATE." is granted"); - } - + } */ + // we want to keep centers the users has no access to. So we will add them // later if they are removed. (this is a ugly hack but it will works $centersAssociatedNotForUsers = \array_diff( diff --git a/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php new file mode 100644 index 000000000..ff21d18c7 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php @@ -0,0 +1,23 @@ +getUser(); if (!$user instanceof User) {