diff --git a/.env b/.env index 29f1e55..0f00f8c 100644 --- a/.env +++ b/.env @@ -73,4 +73,5 @@ AWS_REGION=us-east-1 AWS_ENDPOINT=https://s3.amazonaws.com AWS_S3_PORTAL_URL=https://s3.amazonaws.com/portal ###< aws/aws-sdk-php-symfony ### -APP_URL='https://example.com' \ No newline at end of file +APP_URL='https://example.com' +APP_DOMAIN='example.com' \ No newline at end of file diff --git a/assets/js/global.js b/assets/js/global.js index 42d51d4..84a0c84 100644 --- a/assets/js/global.js +++ b/assets/js/global.js @@ -22,7 +22,7 @@ export const TABULATOR_FR_LANG = { }; export function eyeIconLink(url) { - return ` + return ` entityManager->persist($project); $this->entityManager->flush(); //On met le flush avant parce qu'on a besoin de l'ID du projet pour la création distante. - //Oui ducoup c'est chiant parce que le projet est crée même s'il y a une erreur API, mais OH ffs at that point. + //Oui ducoup c'est chiant parce que le projet est créé même s'il y a une erreur API, mais OH ffs at that point. ducoup s'il y a un pb, vue que la gestion de projet et fait pas le super admin, il faudra recree le projet dans la bdd corespondant à l'appli qui fonctionne pas // Remote creation logic + try { - $this->SSOProjectService->createRemoteProject('http://api.solutions-easy.moi', $project); + foreach ($project->getApplications() as $appId) { + $app = $this->appsRepository->find($appId); + $clientUrl = 'http://' . $app->getSubDomain() . '.' .$this->getParameter('app_domain') ; + $this->SSOProjectService->createRemoteProject($clientUrl, $project); + } + } catch (\Exception $e) { return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500); } - - return new JsonResponse(['message' => 'Project created successfully'], 201); } @@ -129,7 +134,12 @@ final class ProjectController extends AbstractController $this->entityManager->persist($project); // Remote editing logic try { - $this->SSOProjectService->editRemoteProject('http://api.solutions-easy.moi', $project); + foreach ($project->getApplications() as $appId) { + $app = $this->appsRepository->find($appId); + $clientUrl = 'http://' . $app->getSubDomain() . '.' .$this->getParameter('app_domain') ; + $this->SSOProjectService->editRemoteProject($clientUrl, $project); + } + } catch (\Exception $e) { return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500); } @@ -208,6 +218,16 @@ final class ProjectController extends AbstractController return new JsonResponse(['error' => 'Project not found'], Response::HTTP_NOT_FOUND); } $project->setIsDeleted(true); + try { + foreach ($project->getApplications() as $appId) { + $app = $this->appsRepository->find($appId); + $clientUrl = 'http://' . $app->getSubDomain() . '.' .$this->getParameter('app_domain') ; + $this->SSOProjectService->deleteRemoteProject($clientUrl, $project->getId()); + } + + } catch (\Exception $e) { + return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500); + } $this->entityManager->persist($project); $this->entityManager->flush(); return new JsonResponse(['message' => 'Project deleted successfully'], Response::HTTP_OK); diff --git a/src/Service/SSO/ProjectService.php b/src/Service/SSO/ProjectService.php index 77df55d..69444c3 100644 --- a/src/Service/SSO/ProjectService.php +++ b/src/Service/SSO/ProjectService.php @@ -25,7 +25,7 @@ class ProjectService $accessToken = $tokenResponse->toArray()['access_token']; // data must match easy check database - $projectJson = $this->getTokenResponse($project); + $projectJson = $this->getProjectToJson($project); // 2. Call the Client Application's Webhook/API @@ -50,6 +50,18 @@ class ProjectService } + public function deleteRemoteProject(string $clientAppUrl, int $projectId): void + { + $tokenResponse = $this->getTokenResponse(); + + $accessToken = $tokenResponse->toArray()['access_token']; + + // 2. Call the Client Application's Webhook/API + $this->httpClient->request('DELETE', $clientAppUrl . '/api/v1/project/delete/'. $projectId, [ + 'headers' => ['Authorization' => 'Bearer ' . $accessToken], + ]); + } + public function getTokenResponse(): ResponseInterface{ $portalClient = $this->entityManager->getRepository(Client::class)->findOneBy(['identifier' => $this->clientIdentifier]); return $this->httpClient->request('POST', $this->appUrl . 'token', [ @@ -64,7 +76,7 @@ class ProjectService return [ 'id' => $project->getId(), 'projet' => $project->getName(), - 'entity_id' => 3, + 'entity_id' => $project->getOrganization()->getId(), 'bdd' => $project->getBddName(), 'isactive' => $project->isActive(), 'logo' => $project->getLogo(),