From 683766259cc28b64d6c47d0d58256816c061e2d0 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Mar 2026 15:58:39 +0100 Subject: [PATCH] Fix using being able to be invited twice in the same org --- src/Controller/UserController.php | 3 +++ src/Service/UserService.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index e86d7c2..819c664 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -872,6 +872,9 @@ class UserController extends AbstractController $email = $user->getEmail(); $existingUser = $this->userRepository->findOneBy(['email' => $email]); + if($this->userService->checkUserOrganizationLinkExists($existingUser, $org)){ + return $this->json(['error' => "L'utilisateur existe déjà dans votre organisation"], 400); + } // CASE A: User exists -> Add to org if ($existingUser) { // Check if already in org to avoid logic errors or duplicate logs diff --git a/src/Service/UserService.php b/src/Service/UserService.php index a40dc47..2c981e8 100644 --- a/src/Service/UserService.php +++ b/src/Service/UserService.php @@ -750,4 +750,21 @@ class UserService $this->entityManager->flush(); } + /* + * Check if the user organization link doesn't already exist + * Return true if the link exists, false otherwise. + * + * @param User $user + * @param Organization $organization + * @return bool + * */ + public function checkUserOrganizationLinkExists(User $user, Organizations $organization): bool + { + $existingLink = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy([ + 'users' => $user, + 'organization' => $organization + ]); + + return $existingLink !== null; + } }