dynamic remote project CRUD

This commit is contained in:
Charles 2026-02-23 09:57:06 +01:00
parent 6569af4720
commit f08bf51c70
5 changed files with 45 additions and 11 deletions

3
.env
View File

@ -73,4 +73,5 @@ AWS_REGION=us-east-1
AWS_ENDPOINT=https://s3.amazonaws.com AWS_ENDPOINT=https://s3.amazonaws.com
AWS_S3_PORTAL_URL=https://s3.amazonaws.com/portal AWS_S3_PORTAL_URL=https://s3.amazonaws.com/portal
###< aws/aws-sdk-php-symfony ### ###< aws/aws-sdk-php-symfony ###
APP_URL='https://example.com' APP_URL='https://example.com'
APP_DOMAIN='example.com'

View File

@ -22,7 +22,7 @@ export const TABULATOR_FR_LANG = {
}; };
export function eyeIconLink(url) { export function eyeIconLink(url) {
return `<a href="${url}" class="p-3 align-middle color-primary" title="Accéder au profil" target="_blank"> return `<a href="${url}" class="p-3 align-middle color-primary" title="Accéder au profil" >
<svg xmlns="http://www.w3.org/2000/svg" <svg xmlns="http://www.w3.org/2000/svg"
width="35px" width="35px"
height="35px" height="35px"

View File

@ -8,6 +8,7 @@ parameters:
aws_public_url: '%env(AWS_ENDPOINT)%' aws_public_url: '%env(AWS_ENDPOINT)%'
aws_bucket: '%env(S3_PORTAL_BUCKET)%' aws_bucket: '%env(S3_PORTAL_BUCKET)%'
app_url: '%env(APP_URL)%' app_url: '%env(APP_URL)%'
app_domain: '%env(APP_DOMAIN)%'
mercure_secret: '%env(MERCURE_JWT_SECRET)%' mercure_secret: '%env(MERCURE_JWT_SECRET)%'
logos_directory: '%kernel.project_dir%/public/uploads/logos' logos_directory: '%kernel.project_dir%/public/uploads/logos'
oauth_sso_identifier: '%env(OAUTH_SSO_IDENTIFIER)%' oauth_sso_identifier: '%env(OAUTH_SSO_IDENTIFIER)%'

View File

@ -22,12 +22,13 @@ use Symfony\Component\Routing\Attribute\Route;
final class ProjectController extends AbstractController final class ProjectController extends AbstractController
{ {
public function __construct(private readonly EntityManagerInterface $entityManager, public function __construct(private readonly EntityManagerInterface $entityManager,
private readonly OrganizationsRepository $organizationsRepository, private readonly OrganizationsRepository $organizationsRepository,
private readonly ProjectRepository $projectRepository, private readonly ProjectRepository $projectRepository,
private readonly ProjectService $projectService, private readonly ProjectService $projectService,
private readonly AppsRepository $appsRepository, private readonly AppsRepository $appsRepository,
private readonly SSOProjectService $SSOProjectService, private readonly SSOProjectService $SSOProjectService,
) )
{ {
} }
@ -83,16 +84,20 @@ final class ProjectController extends AbstractController
$this->entityManager->persist($project); $this->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. $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 // Remote creation logic
try { 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) { } catch (\Exception $e) {
return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500); return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500);
} }
return new JsonResponse(['message' => 'Project created successfully'], 201); return new JsonResponse(['message' => 'Project created successfully'], 201);
} }
@ -129,7 +134,12 @@ final class ProjectController extends AbstractController
$this->entityManager->persist($project); $this->entityManager->persist($project);
// Remote editing logic // Remote editing logic
try { 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) { } catch (\Exception $e) {
return new JsonResponse(['error' => 'Remote creation failed: ' . $e->getMessage()], 500); 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); return new JsonResponse(['error' => 'Project not found'], Response::HTTP_NOT_FOUND);
} }
$project->setIsDeleted(true); $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->persist($project);
$this->entityManager->flush(); $this->entityManager->flush();
return new JsonResponse(['message' => 'Project deleted successfully'], Response::HTTP_OK); return new JsonResponse(['message' => 'Project deleted successfully'], Response::HTTP_OK);

View File

@ -25,7 +25,7 @@ class ProjectService
$accessToken = $tokenResponse->toArray()['access_token']; $accessToken = $tokenResponse->toArray()['access_token'];
// data must match easy check database // data must match easy check database
$projectJson = $this->getTokenResponse($project); $projectJson = $this->getProjectToJson($project);
// 2. Call the Client Application's Webhook/API // 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{ public function getTokenResponse(): ResponseInterface{
$portalClient = $this->entityManager->getRepository(Client::class)->findOneBy(['identifier' => $this->clientIdentifier]); $portalClient = $this->entityManager->getRepository(Client::class)->findOneBy(['identifier' => $this->clientIdentifier]);
return $this->httpClient->request('POST', $this->appUrl . 'token', [ return $this->httpClient->request('POST', $this->appUrl . 'token', [
@ -64,7 +76,7 @@ class ProjectService
return [ return [
'id' => $project->getId(), 'id' => $project->getId(),
'projet' => $project->getName(), 'projet' => $project->getName(),
'entity_id' => 3, 'entity_id' => $project->getOrganization()->getId(),
'bdd' => $project->getBddName(), 'bdd' => $project->getBddName(),
'isactive' => $project->isActive(), 'isactive' => $project->isActive(),
'logo' => $project->getLogo(), 'logo' => $project->getLogo(),