Added S3 bucket for organizations

This commit is contained in:
Charles 2025-10-13 15:12:53 +02:00
parent 25bad81f03
commit ead3666a4f
5 changed files with 24 additions and 26 deletions

View File

@ -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

View File

@ -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',
],
];

View File

@ -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),
];
}

View File

@ -3,7 +3,7 @@
{% block title %} Gestion des organisations {% endblock %}
{% block body %}
<div class="w-100 h-100 p-5 m-auto" data-controller="organization">
<div class="w-100 h-100 p-5 m-auto">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Gestion des organisations</h1>
{% if is_granted("ROLE_SUPER_ADMIN") %}
@ -33,7 +33,7 @@
<tr>
<td>
{% if organization.logoUrl %}
<img src="{{ asset(organization.logoUrl) }}" alt="Organization logo"
<img src="{{ aws_url ~ organization.logoUrl }}" alt="Organization logo"
class="rounded-circle" style="width:40px; height:40px;">
{% endif %}
</td>
@ -59,4 +59,5 @@
{% endif %}
</div>
{% endblock %}

View File

@ -5,7 +5,7 @@
<div class="col d-flex justify-content-between align-items-center ">
<div class="d-flex ">
{% if organization.logoUrl %}
<img src="{{ asset(organization.logoUrl) }}" alt="Organization logo"
<img src="{{aws_url ~ organization.logoUrl }}" alt="Organization logo"
class="rounded-circle" style="width:40px; height:40px;">
{% endif %}
<h1 class="mb-4 ms-3">{{ organization.name|title }} - Dashboard</h1>