diff --git a/assets/controllers/application_controller.js b/assets/controllers/application_controller.js
index 5aba951..ebc6e66 100644
--- a/assets/controllers/application_controller.js
+++ b/assets/controllers/application_controller.js
@@ -5,8 +5,9 @@ export default class extends Controller {
static values = {
application: String,
organization: String,
+ user: Number,
}
- static targets = ['hidden', 'submitBtn']
+ static targets = ['hidden', 'submitBtn', 'appList']
connect() {
// Map each editor to its toolbar and hidden field
@@ -40,6 +41,9 @@ export default class extends Controller {
hiddenTarget.value = quill.root.innerHTML
})
}
+ if(this.userValue){
+ this.loadApplications();
+ }
}
handleAuthorizeSubmit(event) {
@@ -107,4 +111,59 @@ export default class extends Controller {
alert('Erreur lors de l\'action');
});
}
+
+ async loadApplications() {
+ if (!this.userValue) return;
+
+ try {
+ // Note: Ensure the URL matches your route prefix (e.g. /application/user/123)
+ // Adjust the base path below if your controller route is prefixed!
+ const response = await fetch(`/application/user/${this.userValue}`);
+
+ if (!response.ok) throw new Error("Failed to load apps");
+
+ const apps = await response.json();
+ this.renderApps(apps);
+
+ } catch (error) {
+ console.error(error);
+ this.appListTarget.innerHTML = `Erreur`;
+ }
+ }
+
+ renderApps(apps) {
+ if (apps.length === 0) {
+ // Span 2 columns if empty so the message is centered
+ this.appListTarget.innerHTML = `Aucune application`;
+ return;
+ }
+
+ const html = apps.map(app => {
+ const url = `https://${app.subDomain}.solutions-easy.moi`;
+
+ // Check for logo string vs object
+ const logoSrc = (typeof app.logoMiniUrl === 'string') ? app.logoMiniUrl : '';
+
+ // Render Icon (Image or Fallback)
+ const iconHtml = logoSrc
+ ? ``
+ : ``;
+
+ // Return a Card-like block
+ return `
+
+
+ ${iconHtml}
+
+
+ ${app.name}
+
+
+ `;
+ }).join('');
+
+ this.appListTarget.innerHTML = html;
+ }
}
\ No newline at end of file
diff --git a/src/Controller/ApplicationController.php b/src/Controller/ApplicationController.php
index e883449..b7aa207 100644
--- a/src/Controller/ApplicationController.php
+++ b/src/Controller/ApplicationController.php
@@ -4,26 +4,32 @@ namespace App\Controller;
use App\Entity\Apps;
use App\Entity\Organizations;
+use App\Repository\UserRepository;
use App\Service\ActionService;
use App\Service\ApplicationService;
use App\Service\LoggerService;
+use App\Service\UserOrganizationAppService;
use App\Service\UserService;
use Doctrine\ORM\EntityManagerInterface;
+use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
-use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
-
+use Symfony\Component\Asset\Packages;
#[Route(path: '/application', name: 'application_')]
class ApplicationController extends AbstractController
{
public function __construct(private readonly EntityManagerInterface $entityManager,
- private readonly UserService $userService,
- private readonly ActionService $actionService,
- private readonly LoggerService $loggerService,
- private readonly ApplicationService $applicationService)
+ private readonly UserService $userService,
+ private readonly ActionService $actionService,
+ private readonly LoggerService $loggerService,
+ private readonly ApplicationService $applicationService,
+ private readonly UserRepository $userRepository,
+ private Packages $assetsManager,
+ private readonly UserOrganizationAppService $userOrganizationAppService)
{
}
@@ -172,4 +178,30 @@ class ApplicationController extends AbstractController
return new Response('', Response::HTTP_OK);
}
+
+ #[Route(path:'/user/{id}', name: 'user', methods: ['GET'])]
+ public function getApplicationUsers(int $id): JSONResponse
+ {
+ $user = $this->userRepository->find($id);
+ $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
+ if (!$user) {
+ $this->loggerService->logEntityNotFound('User', ['message'=> 'User not found for application list'], $actingUser->getId());
+ return new JsonResponse(['error' => 'User not found'], Response::HTTP_NOT_FOUND);
+ }
+ if ($this->isGranted('ROLE_SUPER_ADMIN')) {
+ $applications = $this->entityManager->getRepository(Apps::class)->findAll();
+ }else{
+ $applications = $this->userOrganizationAppService->getUserApplications($user);
+
+ }
+ $data = array_map(function($app) {
+ return [
+ 'name' => $app->getName(),
+ 'subDomain' => $app->getSubDomain(),
+ 'logoMiniUrl' => $this->assetsManager->getUrl($app->getLogoMiniUrl()),
+ ];
+ }, $applications);
+
+ return new JsonResponse($data, Response::HTTP_OK);
+ }
}
diff --git a/src/Service/UserOrganizationAppService.php b/src/Service/UserOrganizationAppService.php
index bf2615f..53fc759 100644
--- a/src/Service/UserOrganizationAppService.php
+++ b/src/Service/UserOrganizationAppService.php
@@ -248,4 +248,26 @@ class UserOrganizationAppService
$uoaAdmin->setIsActive(true);
}
}
+
+ /**
+ * Get users applications links for a given user
+ *
+ * @param User $user
+ * @return Apps[]
+ */
+ public function getUserApplications(User $user): array
+ {
+ $uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user]);
+ $apps = [];
+ foreach ($uos as $uo) {
+ $uoas = $this->entityManager->getRepository(UserOrganizatonApp::class)->findBy(['userOrganization' => $uo, 'isActive' => true]);
+ foreach ($uoas as $uoa) {
+ $app = $uoa->getApplication();
+ if (!in_array($app, $apps, true)) {
+ $apps[] = $app;
+ }
+ }
+ }
+ return $apps;
+ }
}
diff --git a/templates/elements/navbar.html.twig b/templates/elements/navbar.html.twig
index 9b52742..a701010 100644
--- a/templates/elements/navbar.html.twig
+++ b/templates/elements/navbar.html.twig
@@ -72,6 +72,35 @@
+