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; } /**