From 71c6f82b77b713e402dac84a2d6147d6d423a5bc Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 27 Aug 2025 13:56:08 +0200 Subject: [PATCH] Display indivodual user informations --- src/Controller/UserController.php | 43 +++++++++++++- src/Service/UserOrganizationAppService.php | 40 +++++++++++++ templates/elements/navbar.html.twig | 8 +-- .../user/application/information.html.twig | 59 ++++++++++++------- templates/user/show.html.twig | 26 +++----- templates/user/userInformation.html.twig | 2 +- templates/user/userList.html.twig | 22 +++---- 7 files changed, 144 insertions(+), 56 deletions(-) create mode 100644 src/Service/UserOrganizationAppService.php diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index e524644..b5976e5 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -4,9 +4,11 @@ namespace App\Controller; use App\Entity\Organizations; use App\Entity\User; +use App\Entity\UserOrganizatonApp; use App\Entity\UsersOrganizations; use App\Form\UserForm; use App\Service\ActionService; +use App\Service\UserOrganizationAppService; use App\Service\UserOrganizationService; use App\Service\UserService; use Doctrine\ORM\EntityManagerInterface; @@ -26,7 +28,7 @@ class UserController extends AbstractController private readonly UserOrganizationService $userOrganizationService, private readonly EntityManagerInterface $entityManager, private readonly UserService $userService, - private readonly ActionService $actionService, + private readonly ActionService $actionService, private readonly UserOrganizationAppService $userOrganizationAppService, ) { } @@ -65,4 +67,43 @@ class UserController extends AbstractController 'usersByOrganization' => $usersByOrganization, ]); } + + #[Route('/view/{id}', name: 'show', methods: ['GET'])] + public function view(int $id, Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_USER'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if($this->userService->hasAccessTo($actingUser)){ + $user = $this->entityManager->getRepository(User::class)->find($id); + try{ + $orgId = $request->query->get('organizationId'); + if($orgId){ + $orgs = $this->entityManager->getRepository(Organizations::class)->findBy(['id' =>$orgId]); + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs, 'isActive' => true]); + if(!$uo){ + throw $this->createNotFoundException(self::NOT_FOUND); + } + } + else{ + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users'=> $user, 'isActive' => true]); + foreach ($uo as $u){ + $orgs[] = $u->getOrganization(); + } + } + $uoa = $this->entityManager->getRepository(UserOrganizatonApp::class)->findBy(['userOrganization'=> $uo, 'isActive' => true]); + $uoa = $this->userOrganizationAppService->groupUserOrganizationAppsByApplication($uoa); + dd($uoa, $orgs["name"]); + }catch(\Exception $e){ + //ignore + } + }else{ + throw $this->createAccessDeniedException(self::ACCESS_DENIED); + } + + return $this->render('user/show.html.twig', [ + 'user' => $user, + 'uoas' => $uoa ?? null, + 'orgs' => $orgs ?? null, + ]); + } } diff --git a/src/Service/UserOrganizationAppService.php b/src/Service/UserOrganizationAppService.php new file mode 100644 index 0000000..8f8ac23 --- /dev/null +++ b/src/Service/UserOrganizationAppService.php @@ -0,0 +1,40 @@ +getApplication(); + $appId = $app->getId(); + $roleEntity = $uoa->getRole(); + + if (!isset($grouped[$appId])) { + $grouped[$appId] = [ + 'userOrganization'=> $uoa->getUserOrganization(), + 'application' => $app, + 'roles' => [], + ]; + } + + $grouped[$appId]['roles'][] = [ + 'id' => $roleEntity->getId(), + 'name' => $roleEntity->getName(), // adjust to your Role entity fields + ]; + } + + // if you want a simple indexed array instead of associative keyed by appId + return array_values($grouped); + } + +} diff --git a/templates/elements/navbar.html.twig b/templates/elements/navbar.html.twig index 87d18a4..b202cdc 100644 --- a/templates/elements/navbar.html.twig +++ b/templates/elements/navbar.html.twig @@ -69,10 +69,10 @@