diff --git a/README.MD b/README.MD index b0d5014..d500616 100644 --- a/README.MD +++ b/README.MD @@ -25,6 +25,10 @@ php bin/console importmap:require choices.js php bin/console importmap:require choices.js/public/assets/styles/choices.min.css ``` - - +### Notes +- certaines abbreviations sont utilisées afin de simplifier le code et d'éviter les répétitions ou noms trop longs : + - `uo` pour `User Organization` + - `uoId` pour `User Organization Id` + - `oa` pour `Organization Application` + - `at` pour `Access Token` diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index 44af13f..4eec39a 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Entity\Apps; use App\Entity\Roles; use App\Entity\UsersOrganizations; use App\Service\OrganizationsService; @@ -73,6 +74,10 @@ class OrganizationController extends AbstractController $adminUsers = $this->entityManager->getRepository(UsersOrganizations::class)->getAdminUsersByOrganization($organization); // reusing the method to avoid code duplication even though it returns an array of UsersOrganizations $org = $this->usersOrganizationService->findActiveUsersByOrganizations([$organization]); + +// get all applications + $applications = $this->organizationsService->getApplicationsWithAccessStatus($organization); + }else{ throw $this->createNotFoundException(self::ACCESS_DENIED); } @@ -82,6 +87,7 @@ class OrganizationController extends AbstractController 'adminUsers' => $adminUsers, 'newUsers' => $newUsers, 'org' => $org[0], + 'applications' => $applications, ]); } diff --git a/src/Service/OrganizationsService.php b/src/Service/OrganizationsService.php index 8bb69d6..362d850 100644 --- a/src/Service/OrganizationsService.php +++ b/src/Service/OrganizationsService.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Entity\Apps; use App\Entity\Organizations; use App\Entity\Roles; use App\Entity\UsersOrganizations; @@ -25,4 +26,36 @@ class OrganizationsService 'isActive' => true]); } + /** + * Get all applications with organization access status + * + * @param Organizations $organization + * @return array + */ + public function getApplicationsWithAccessStatus(Organizations $organization): array + { + // Get all applications + $allApplications = $this->entityManager->getRepository(Apps::class)->findAll(); + + // Get applications the organization has access to + $organizationApps = $organization->getApps(); + + // Create a lookup array for faster checking + $orgAppIds = []; + foreach ($organizationApps as $app) { + $orgAppIds[$app->getId()] = true; + } + + // Build result array + $result = []; + foreach ($allApplications as $app) { + $result[] = [ + 'application' => $app, + 'has_access' => isset($orgAppIds[$app->getId()]) + ]; + } + + return $result; + } + } \ No newline at end of file diff --git a/src/Service/UserOrganizationService.php b/src/Service/UserOrganizationService.php index dd4f9d7..ec96780 100644 --- a/src/Service/UserOrganizationService.php +++ b/src/Service/UserOrganizationService.php @@ -459,4 +459,6 @@ readonly class UserOrganizationService return $userToOrgs; } + + }