Fix using being able to be invited twice in the same org
This commit is contained in:
parent
45e14c47ca
commit
683766259c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue