From ac47a75a759f9a692f36943558a379be62ad08b8 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 22 Jun 2021 12:26:56 +0200 Subject: [PATCH] fix bug issue 163 Address JSON string not valid --- .../Controller/PersonAddressController.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php index 5dc6fea46..4ec1b6218 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php @@ -297,18 +297,16 @@ class PersonAddressController extends AbstractController */ protected function findAddressById(Person $person, $address_id) { - // filtering address - $criteria = Criteria::create() - ->where(Criteria::expr()->eq('id', $address_id)) - ->setMaxResults(1); - $addresses = $person->getAddresses()->matching($criteria); + $address = $this->getDoctrine()->getManager() + ->getRepository(Address::class) + ->find($address_id) + ; - if (count($addresses) === 0) { - throw $this->createNotFoundException("Address with id $address_id " - . "matching person $person_id not found "); + if (!$person->getAddresses()->contains($address)) { + throw $this->createAccessDeniedException("Not allowed to see this address"); } - return $addresses->first(); + return $address; } /**