diff --git a/.changes/unreleased/Fixed-20250128-130242.yaml b/.changes/unreleased/Fixed-20250128-130242.yaml new file mode 100644 index 000000000..bd03e44b4 --- /dev/null +++ b/.changes/unreleased/Fixed-20250128-130242.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Add validation error to manual selection of person in PersonDuplicateController +time: 2025-01-28T13:02:42.369442185+01:00 +custom: + Issue: "350" + SchemaChange: No schema change diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index b11390a46..348a3495d 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -29,6 +29,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Security\Core\Security; +use Symfony\Contracts\Translation\TranslatorInterface; use function count; class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController @@ -40,6 +41,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll private readonly EventDispatcherInterface $eventDispatcher, private readonly Security $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, + private readonly TranslatorInterface $translator, ) {} #[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/person/{person1_id}/duplicate/{person2_id}/confirm', name: 'chill_person_duplicate_confirm')] @@ -125,7 +127,14 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll $person2 = $form->get('person')->getData(); if (null === $person2) { - throw $this->createNotFoundException("Person with id {$person2->getId}() not".' found on this server'); + throw $this->createNotFoundException('Person not found on this server'); + } + + // Validation: Ensure person1 is not the same as person2 + if ($person->getId() === $person2->getId()) { + $this->addFlash('error', $this->translator->trans('Person1 cannot be the same as Person2')); + + return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person2->getId()]); } $direction = $form->get('direction')->getData(); diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 6b3c5cd0e..dd4c9c3ba 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -127,6 +127,7 @@ not-duplicate: Faux-positif Switch to truefalse: Marquer comme faux-positif Switch to duplicate: Marquer comme doublon No duplicate candidates: Il n'y a pas de doublons détectés, ni de faux-positifs +Person1 cannot be the same as Person2: La personne que vous sélectionnez ne peut pas être la même que celle de ce dossier. # addresses part address_street_address_1: Adresse ligne 1