From 45e14c47ca81772f0b24854f4559e20f012cafa7 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Mar 2026 15:52:06 +0100 Subject: [PATCH 1/2] fix unrecognized field --- src/Service/OrganizationsService.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Service/OrganizationsService.php b/src/Service/OrganizationsService.php index 888ac83..f92e87c 100644 --- a/src/Service/OrganizationsService.php +++ b/src/Service/OrganizationsService.php @@ -142,18 +142,12 @@ class OrganizationsService $roleAdmin = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'ADMIN']); - $adminUOs = $this->uoRepository->findBy(['organization' => $data['organization'], 'isActive' => true]); + $adminUOs = $this->uoRepository->findBy(['organization' => $data['organization'], 'isActive' => true, 'role' => $roleAdmin]); foreach ($adminUOs as $adminUO) { - $uoa = $this->entityManager->getRepository(UsersOrganizations::class) - ->findOneBy([ - 'userOrganization' => $adminUO, - 'role' => $roleAdmin, - 'isActive' => true - ]); switch ($type) { case 'USER_ACCEPTED': - if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) { + if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) { $newUser = $data['user']; $this->notificationService->notifyUserAcceptedInvite( $adminUO->getUsers(), @@ -167,7 +161,7 @@ class OrganizationsService } break; case 'USER_INVITED': - if ($uoa) { + if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) { $invitedUser = $data['user']; $this->notificationService->notifyUserInvited( $adminUO->getUsers(), @@ -182,7 +176,7 @@ class OrganizationsService break; case 'USER_DEACTIVATED': - if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) { + if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) { $removedUser = $data['user']; $this->notificationService->notifyUserDeactivated( $adminUO->getUsers(), @@ -197,7 +191,7 @@ class OrganizationsService break; case 'USER_DELETED': - if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) { + if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) { $removedUser = $data['user']; $this->notificationService->notifyUserDeleted( $adminUO->getUsers(), @@ -211,7 +205,7 @@ class OrganizationsService } break; case 'USER_ACTIVATED': - if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) { + if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) { $activatedUser = $data['user']; $this->notificationService->notifyUserActivated( $adminUO->getUsers(), From 683766259cc28b64d6c47d0d58256816c061e2d0 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Mar 2026 15:58:39 +0100 Subject: [PATCH 2/2] 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; + } }