diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index d734529..afc9345 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -4,8 +4,11 @@ twig: globals: application: '%env(APPLICATION)%' + aws_url: '%env(AWS_S3_PORTAL_URL)%' version: '0.4' + + when@test: twig: strict_variables: true diff --git a/importmap.php b/importmap.php index e42216c..eeacc81 100644 --- a/importmap.php +++ b/importmap.php @@ -66,4 +66,11 @@ return [ 'lodash.isequal' => [ 'version' => '4.5.0', ], + 'tabulator-tables' => [ + 'version' => '6.3.1', + ], + 'tabulator-tables/dist/css/tabulator.min.css' => [ + 'version' => '6.3.1', + 'type' => 'css', + ], ]; diff --git a/src/Service/OrganizationsService.php b/src/Service/OrganizationsService.php index 35bc53e..a0b1d90 100644 --- a/src/Service/OrganizationsService.php +++ b/src/Service/OrganizationsService.php @@ -4,44 +4,31 @@ namespace App\Service; use App\Entity\Apps; use App\Entity\Organizations; -use App\Entity\Roles; -use App\Entity\UsersOrganizations; -use Doctrine\ORM\EntityManagerInterface; -use SebastianBergmann\CodeCoverage\Util\DirectoryCouldNotBeCreatedException; +use App\Service\AwsService; use Symfony\Component\HttpFoundation\File\Exception\FileException; class OrganizationsService { private string $logoDirectory; - public function __construct(private readonly EntityManagerInterface $entityManager, - string $logoDirectory + + public function __construct( + string $logoDirectory, private readonly AwsService $awsService ) { $this->logoDirectory = $logoDirectory; } - public function handleLogo(Organizations $organization, $logoFile) + public function handleLogo(Organizations $organization, $logoFile): void { $extension = $logoFile->guessExtension(); - $customFilename = $organization->getName() . '_'. date('dmyHis') . "." . $extension; + $customFilename = $organization->getName() . '_' . date('dmyHis') . "." . $extension; - $uploadDirectory = $this->logoDirectory; - - if (!is_dir($uploadDirectory) && !mkdir($uploadDirectory, 0755, true) && !is_dir($uploadDirectory)) { - throw new DirectoryCouldNotBeCreatedException(sprintf('Directory "%s" was not created', $uploadDirectory)); - } try { - - // Move the file to the upload directory - $logoFile->move($uploadDirectory, $customFilename); - - // Update user entity with the file path (relative to public directory) - $organization->setLogoUrl('uploads/logos/' . $customFilename); - + $this->awsService->PutDocObj($_ENV['S3_PORTAL_BUCKET'], $logoFile, $customFilename, $extension, 'logo/'); + $organization->setLogoUrl('logo/' . $customFilename); } catch (FileException $e) { - // Handle upload error - throw new FileException('File upload failed: ' . $e->getMessage()); + throw new FileException('Failed to upload logo to S3: ' . $e->getMessage()); } } @@ -60,7 +47,7 @@ class OrganizationsService $result = []; foreach ($appsAll as $app) { $result[] = [ - 'entity' => $app, // Keep the full entity for Twig + 'entity' => $app, // Keep the full entity for Twig 'hasAccess' => in_array($app->getId(), $orgAppIds, true), ]; } diff --git a/templates/organization/index.html.twig b/templates/organization/index.html.twig index 76a06de..560c999 100644 --- a/templates/organization/index.html.twig +++ b/templates/organization/index.html.twig @@ -3,7 +3,7 @@ {% block title %} Gestion des organisations {% endblock %} {% block body %} -