diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 67dd19c..80428a3 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -103,6 +103,7 @@ class UserController extends AbstractController 'user' => $user, 'uoas' => $uoa ?? null, 'orgs' => $orgs ?? null, + 'organizationId' => $orgId ?? null, // specific for single organization context and deactivate user from said org ]); } @@ -211,4 +212,37 @@ class UserController extends AbstractController throw $this->createAccessDeniedException(self::ACCESS_DENIED); } + + #[Route('/organization/deactivate/{id}', name: 'deactivate_organization', methods: ['GET', 'POST'])] + public function deactivateUserInOrganization(int $id, Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->userService->hasAccessTo($actingUser, true)) { + $orgId = $request->get('organizationId'); + $org = $this->entityManager->getRepository(Organizations::class)->find($orgId); + if (!$org) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $user = $this->entityManager->getRepository(User::class)->find($id); + if (!$user) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy(['users' => $user, + 'organization' => $org, + 'isActive' => true]); + if (!$uo) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $uo->setIsActive(false); + $this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo); + $this->entityManager->persist($uo); + $this->entityManager->flush(); + $this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier()); + + return $this->redirectToRoute('user_index'); + } + + throw $this->createAccessDeniedException(self::ACCESS_DENIED); + } } diff --git a/templates/user/userInformation.html.twig b/templates/user/userInformation.html.twig index 429e8e9..5fafac5 100644 --- a/templates/user/userInformation.html.twig +++ b/templates/user/userInformation.html.twig @@ -7,7 +7,16 @@

{{ user.surname|capitalize }} {{ user.name|capitalize }}

- Modifier +
+ {% if organizationId is not null %} +
+ + +
+ {% endif %} + Modifier +

Email: {{ user.email }}