From 7da97b0d02c22c95973bfc0535a86235d0406f3d Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 25 Nov 2025 15:11:36 +0100 Subject: [PATCH] Corrected UO link deactivation logic --- src/Controller/UserController.php | 4 ++-- src/Service/UserOrganizationService.php | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index ea3a955..5783ad1 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -307,7 +307,7 @@ class UserController extends AbstractController } $user->setIsActive(false); $user->setModifiedAt(new \DateTimeImmutable('now')); - $this->userOrganizationService->deactivateAllUserOrganizationLinks($user, $actingUser); + $this->userOrganizationService->deactivateAllUserOrganizationLinks($actingUser, $user); if ($this->userService->isUserConnected($user->getUserIdentifier())) { $this->userService->revokeUserTokens($user->getUserIdentifier()); } @@ -429,7 +429,7 @@ class UserController extends AbstractController } $user->setIsActive(false); $user->setModifiedAt(new \DateTimeImmutable('now')); - $this->userOrganizationService->deactivateAllUserOrganizationLinks($user, $actingUser); + $this->userOrganizationService->deactivateAllUserOrganizationLinks($actingUser, $user); $user->setIsDeleted(true); if ($this->userService->isUserConnected($user)) { $this->userService->revokeUserTokens($user->getUserIdentifier()); diff --git a/src/Service/UserOrganizationService.php b/src/Service/UserOrganizationService.php index 05508a1..8a323da 100644 --- a/src/Service/UserOrganizationService.php +++ b/src/Service/UserOrganizationService.php @@ -26,16 +26,21 @@ readonly class UserOrganizationService /** * Deactive all user organization links. * - * @param User $user * @param User $actingUser + * @param User|null $user + * @param Organizations|null $organizations * @return void */ public function deactivateAllUserOrganizationLinks(User $actingUser, User $user = null, Organizations $organizations = null): void{ + //If user provided, get all UO links for that user that are active if($user !== null) { $uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'isActive' => true]); - }elseif($organizations !== null){ + } + // if organization provided, get all UO links for that organization that are active + elseif($organizations !== null){ $uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['organization' => $organizations, 'isActive' => true]); } + //deactivate all UO links foreach ($uos as $uo) { $this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo); $uo->setIsActive(false);