Merge branch 'dev/user-bugfix' into 'develop'
Dev/user bugfix See merge request easy-solutions/apps/easyportal!48
This commit is contained in:
commit
195f841f8c
|
|
@ -872,6 +872,9 @@ class UserController extends AbstractController
|
||||||
$email = $user->getEmail();
|
$email = $user->getEmail();
|
||||||
$existingUser = $this->userRepository->findOneBy(['email' => $email]);
|
$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
|
// CASE A: User exists -> Add to org
|
||||||
if ($existingUser) {
|
if ($existingUser) {
|
||||||
// Check if already in org to avoid logic errors or duplicate logs
|
// Check if already in org to avoid logic errors or duplicate logs
|
||||||
|
|
|
||||||
|
|
@ -142,18 +142,12 @@ class OrganizationsService
|
||||||
|
|
||||||
$roleAdmin = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'ADMIN']);
|
$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) {
|
foreach ($adminUOs as $adminUO) {
|
||||||
$uoa = $this->entityManager->getRepository(UsersOrganizations::class)
|
|
||||||
->findOneBy([
|
|
||||||
'userOrganization' => $adminUO,
|
|
||||||
'role' => $roleAdmin,
|
|
||||||
'isActive' => true
|
|
||||||
]);
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'USER_ACCEPTED':
|
case 'USER_ACCEPTED':
|
||||||
if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
||||||
$newUser = $data['user'];
|
$newUser = $data['user'];
|
||||||
$this->notificationService->notifyUserAcceptedInvite(
|
$this->notificationService->notifyUserAcceptedInvite(
|
||||||
$adminUO->getUsers(),
|
$adminUO->getUsers(),
|
||||||
|
|
@ -167,7 +161,7 @@ class OrganizationsService
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'USER_INVITED':
|
case 'USER_INVITED':
|
||||||
if ($uoa) {
|
if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
||||||
$invitedUser = $data['user'];
|
$invitedUser = $data['user'];
|
||||||
$this->notificationService->notifyUserInvited(
|
$this->notificationService->notifyUserInvited(
|
||||||
$adminUO->getUsers(),
|
$adminUO->getUsers(),
|
||||||
|
|
@ -182,7 +176,7 @@ class OrganizationsService
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'USER_DEACTIVATED':
|
case 'USER_DEACTIVATED':
|
||||||
if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
||||||
$removedUser = $data['user'];
|
$removedUser = $data['user'];
|
||||||
$this->notificationService->notifyUserDeactivated(
|
$this->notificationService->notifyUserDeactivated(
|
||||||
$adminUO->getUsers(),
|
$adminUO->getUsers(),
|
||||||
|
|
@ -197,7 +191,7 @@ class OrganizationsService
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'USER_DELETED':
|
case 'USER_DELETED':
|
||||||
if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
||||||
$removedUser = $data['user'];
|
$removedUser = $data['user'];
|
||||||
$this->notificationService->notifyUserDeleted(
|
$this->notificationService->notifyUserDeleted(
|
||||||
$adminUO->getUsers(),
|
$adminUO->getUsers(),
|
||||||
|
|
@ -211,7 +205,7 @@ class OrganizationsService
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'USER_ACTIVATED':
|
case 'USER_ACTIVATED':
|
||||||
if ($uoa && $adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
if ($adminUO->getUsers()->getId() !== $data['user']->getId() ) {
|
||||||
$activatedUser = $data['user'];
|
$activatedUser = $data['user'];
|
||||||
$this->notificationService->notifyUserActivated(
|
$this->notificationService->notifyUserActivated(
|
||||||
$adminUO->getUsers(),
|
$adminUO->getUsers(),
|
||||||
|
|
|
||||||
|
|
@ -750,4 +750,21 @@ class UserService
|
||||||
$this->entityManager->flush();
|
$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