From e5af0508745f3f8ce378c164859a7fde53ee7bd7 Mon Sep 17 00:00:00 2001 From: Saidi Date: Tue, 24 Sep 2024 16:57:04 +0200 Subject: [PATCH 1/2] handle warning and deprecations issues #3087 #3088 #3089 --- src/Controller/Back/AffectationController.php | 2 +- .../Back/ArchivedSignalementController.php | 2 +- .../Back/AutoAffectationRuleController.php | 2 +- .../Back/BackArchivedAccountController.php | 2 +- .../Back/BackArchivedPartnerController.php | 2 +- .../Back/BackDashboardController.php | 2 +- .../Back/BackExpiredAccountController.php | 2 +- .../Back/BackInactiveAccountController.php | 2 +- ...BackSignalementQualificationController.php | 2 +- .../Back/BackStatistiquesController.php | 2 +- src/Controller/Back/BackTagController.php | 2 +- .../Back/CartographieController.php | 2 +- src/Controller/Back/CguController.php | 2 +- .../Back/ExportSignalementController.php | 2 +- src/Controller/Back/IdossController.php | 2 +- .../Back/NotificationController.php | 2 +- src/Controller/Back/PartnerController.php | 2 +- src/Controller/Back/ProfilController.php | 2 +- .../Back/SignalementActionController.php | 2 +- src/Controller/Back/SignalementController.php | 2 +- .../Back/SignalementEditController.php | 2 +- .../Back/SignalementFileController.php | 2 +- .../Back/SignalementListController.php | 2 +- .../Back/SignalementVisitesController.php | 2 +- src/Controller/Back/TagController.php | 2 +- src/Controller/Back/WidgetController.php | 2 +- .../Back/WidgetSettingsController.php | 2 +- src/Controller/BailleurController.php | 2 +- src/Controller/FileController.php | 2 +- src/Controller/HomepageController.php | 2 +- src/Controller/QuestionController.php | 2 +- .../Security/SecurityController.php | 2 +- .../Security/UserAccountController.php | 2 +- src/Controller/SignalementController.php | 14 ++--- src/Controller/SignalementFileController.php | 2 +- src/Controller/StatistiquesController.php | 2 +- src/EventListener/ExceptionListener.php | 41 ++++++------- .../Mail/Error/ErrorSignalementMailer.php | 1 - src/Service/Security/FileScanner.php | 5 ++ .../Signalement/SignalementDraftHelper.php | 4 ++ .../emails/erreur_signalement_email.html.twig | 5 +- .../Controller/SignalementControllerTest.php | 13 ++++ tests/Unit/Service/FileScannerTest.php | 60 +++++++++++++++++++ 43 files changed, 145 insertions(+), 68 deletions(-) create mode 100644 tests/Unit/Service/FileScannerTest.php diff --git a/src/Controller/Back/AffectationController.php b/src/Controller/Back/AffectationController.php index 292a39d2d..cfc3ca04b 100755 --- a/src/Controller/Back/AffectationController.php +++ b/src/Controller/Back/AffectationController.php @@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Contracts\Cache\TagAwareCacheInterface; #[Route('/bo/signalements')] diff --git a/src/Controller/Back/ArchivedSignalementController.php b/src/Controller/Back/ArchivedSignalementController.php index 86a0ae052..b8a62a52f 100755 --- a/src/Controller/Back/ArchivedSignalementController.php +++ b/src/Controller/Back/ArchivedSignalementController.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/signalements-archives')] diff --git a/src/Controller/Back/AutoAffectationRuleController.php b/src/Controller/Back/AutoAffectationRuleController.php index 0115d1a4b..ee9b80b53 100644 --- a/src/Controller/Back/AutoAffectationRuleController.php +++ b/src/Controller/Back/AutoAffectationRuleController.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/auto-affectation')] diff --git a/src/Controller/Back/BackArchivedAccountController.php b/src/Controller/Back/BackArchivedAccountController.php index b4adebab6..92dcf21ed 100755 --- a/src/Controller/Back/BackArchivedAccountController.php +++ b/src/Controller/Back/BackArchivedAccountController.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/comptes-archives')] diff --git a/src/Controller/Back/BackArchivedPartnerController.php b/src/Controller/Back/BackArchivedPartnerController.php index 947dc352b..02eae61e2 100755 --- a/src/Controller/Back/BackArchivedPartnerController.php +++ b/src/Controller/Back/BackArchivedPartnerController.php @@ -8,7 +8,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/partner-archives')] diff --git a/src/Controller/Back/BackDashboardController.php b/src/Controller/Back/BackDashboardController.php index de286e878..abd4557c0 100755 --- a/src/Controller/Back/BackDashboardController.php +++ b/src/Controller/Back/BackDashboardController.php @@ -4,7 +4,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo')] class BackDashboardController extends AbstractController diff --git a/src/Controller/Back/BackExpiredAccountController.php b/src/Controller/Back/BackExpiredAccountController.php index 098fa7fa0..3d71064b1 100755 --- a/src/Controller/Back/BackExpiredAccountController.php +++ b/src/Controller/Back/BackExpiredAccountController.php @@ -5,7 +5,7 @@ use App\Repository\UserRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/comptes-expires')] diff --git a/src/Controller/Back/BackInactiveAccountController.php b/src/Controller/Back/BackInactiveAccountController.php index 86eda912c..0bdc71b8d 100755 --- a/src/Controller/Back/BackInactiveAccountController.php +++ b/src/Controller/Back/BackInactiveAccountController.php @@ -5,7 +5,7 @@ use App\Repository\UserRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/comptes-inactifs')] diff --git a/src/Controller/Back/BackSignalementQualificationController.php b/src/Controller/Back/BackSignalementQualificationController.php index 35db8c9cb..720d6b625 100644 --- a/src/Controller/Back/BackSignalementQualificationController.php +++ b/src/Controller/Back/BackSignalementQualificationController.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; #[Route('/bo/signalements')] diff --git a/src/Controller/Back/BackStatistiquesController.php b/src/Controller/Back/BackStatistiquesController.php index 4fe6673eb..070fbae59 100755 --- a/src/Controller/Back/BackStatistiquesController.php +++ b/src/Controller/Back/BackStatistiquesController.php @@ -15,7 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/statistiques')] class BackStatistiquesController extends AbstractController diff --git a/src/Controller/Back/BackTagController.php b/src/Controller/Back/BackTagController.php index 6083e23f4..e1f5b2e08 100755 --- a/src/Controller/Back/BackTagController.php +++ b/src/Controller/Back/BackTagController.php @@ -8,7 +8,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/signalements')] class BackTagController extends AbstractController diff --git a/src/Controller/Back/CartographieController.php b/src/Controller/Back/CartographieController.php index a2ef6143a..5ccaafafe 100755 --- a/src/Controller/Back/CartographieController.php +++ b/src/Controller/Back/CartographieController.php @@ -11,7 +11,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/cartographie')] class CartographieController extends AbstractController diff --git a/src/Controller/Back/CguController.php b/src/Controller/Back/CguController.php index eb842888d..813d43236 100755 --- a/src/Controller/Back/CguController.php +++ b/src/Controller/Back/CguController.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/cgu')] class CguController extends AbstractController diff --git a/src/Controller/Back/ExportSignalementController.php b/src/Controller/Back/ExportSignalementController.php index 179890869..c13a92a88 100644 --- a/src/Controller/Back/ExportSignalementController.php +++ b/src/Controller/Back/ExportSignalementController.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\Messenger\MessageBusInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/export/signalement')] class ExportSignalementController extends AbstractController diff --git a/src/Controller/Back/IdossController.php b/src/Controller/Back/IdossController.php index bf97d9bb7..68aa35f4e 100644 --- a/src/Controller/Back/IdossController.php +++ b/src/Controller/Back/IdossController.php @@ -11,7 +11,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/idoss')] diff --git a/src/Controller/Back/NotificationController.php b/src/Controller/Back/NotificationController.php index 70d62b7a2..a9f4983d5 100755 --- a/src/Controller/Back/NotificationController.php +++ b/src/Controller/Back/NotificationController.php @@ -10,7 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo')] class NotificationController extends AbstractController diff --git a/src/Controller/Back/PartnerController.php b/src/Controller/Back/PartnerController.php index c55e7a99d..a4760d9c4 100755 --- a/src/Controller/Back/PartnerController.php +++ b/src/Controller/Back/PartnerController.php @@ -32,7 +32,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; diff --git a/src/Controller/Back/ProfilController.php b/src/Controller/Back/ProfilController.php index ea2023be0..f4dc13435 100755 --- a/src/Controller/Back/ProfilController.php +++ b/src/Controller/Back/ProfilController.php @@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Validator\ValidatorInterface; diff --git a/src/Controller/Back/SignalementActionController.php b/src/Controller/Back/SignalementActionController.php index 979d1bd25..00bb60363 100755 --- a/src/Controller/Back/SignalementActionController.php +++ b/src/Controller/Back/SignalementActionController.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/signalements')] diff --git a/src/Controller/Back/SignalementController.php b/src/Controller/Back/SignalementController.php index 1059edb64..7719f4b43 100755 --- a/src/Controller/Back/SignalementController.php +++ b/src/Controller/Back/SignalementController.php @@ -32,7 +32,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/signalements')] class SignalementController extends AbstractController diff --git a/src/Controller/Back/SignalementEditController.php b/src/Controller/Back/SignalementEditController.php index 98e7c69d4..576a672a1 100755 --- a/src/Controller/Back/SignalementEditController.php +++ b/src/Controller/Back/SignalementEditController.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; diff --git a/src/Controller/Back/SignalementFileController.php b/src/Controller/Back/SignalementFileController.php index c480a1fe1..e27a49f77 100755 --- a/src/Controller/Back/SignalementFileController.php +++ b/src/Controller/Back/SignalementFileController.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo/signalements')] class SignalementFileController extends AbstractController diff --git a/src/Controller/Back/SignalementListController.php b/src/Controller/Back/SignalementListController.php index 301fdb165..e4d02817b 100755 --- a/src/Controller/Back/SignalementListController.php +++ b/src/Controller/Back/SignalementListController.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Attribute\MapQueryString; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo')] class SignalementListController extends AbstractController diff --git a/src/Controller/Back/SignalementVisitesController.php b/src/Controller/Back/SignalementVisitesController.php index 07f71e368..7f74d3cdf 100755 --- a/src/Controller/Back/SignalementVisitesController.php +++ b/src/Controller/Back/SignalementVisitesController.php @@ -22,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Validator\Validator\ValidatorInterface; #[Route('/bo/signalements')] diff --git a/src/Controller/Back/TagController.php b/src/Controller/Back/TagController.php index c869e4db8..ffce78b84 100755 --- a/src/Controller/Back/TagController.php +++ b/src/Controller/Back/TagController.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[Route('/bo/etiquettes')] diff --git a/src/Controller/Back/WidgetController.php b/src/Controller/Back/WidgetController.php index b5125c2f3..8c232f466 100755 --- a/src/Controller/Back/WidgetController.php +++ b/src/Controller/Back/WidgetController.php @@ -10,7 +10,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; #[Route('/bo')] diff --git a/src/Controller/Back/WidgetSettingsController.php b/src/Controller/Back/WidgetSettingsController.php index 03ce341fe..4da201d06 100644 --- a/src/Controller/Back/WidgetSettingsController.php +++ b/src/Controller/Back/WidgetSettingsController.php @@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/bo')] class WidgetSettingsController extends AbstractController diff --git a/src/Controller/BailleurController.php b/src/Controller/BailleurController.php index 1705d0893..5fc25bc52 100644 --- a/src/Controller/BailleurController.php +++ b/src/Controller/BailleurController.php @@ -9,7 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; class BailleurController extends AbstractController { diff --git a/src/Controller/FileController.php b/src/Controller/FileController.php index 0c8e50a7f..16e363b16 100644 --- a/src/Controller/FileController.php +++ b/src/Controller/FileController.php @@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\File as SymfonyFile; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; class FileController extends AbstractController { diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php index 9a9ef4714..ec8accd20 100755 --- a/src/Controller/HomepageController.php +++ b/src/Controller/HomepageController.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\RateLimiter\RateLimiterFactory; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; class HomepageController extends AbstractController { diff --git a/src/Controller/QuestionController.php b/src/Controller/QuestionController.php index 5afa86016..57f34bc79 100644 --- a/src/Controller/QuestionController.php +++ b/src/Controller/QuestionController.php @@ -5,7 +5,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/api')] class QuestionController extends AbstractController diff --git a/src/Controller/Security/SecurityController.php b/src/Controller/Security/SecurityController.php index 64018886f..09b1d3aec 100755 --- a/src/Controller/Security/SecurityController.php +++ b/src/Controller/Security/SecurityController.php @@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class SecurityController extends AbstractController diff --git a/src/Controller/Security/UserAccountController.php b/src/Controller/Security/UserAccountController.php index bd658001b..87a098956 100755 --- a/src/Controller/Security/UserAccountController.php +++ b/src/Controller/Security/UserAccountController.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\RateLimiter\RateLimiterFactory; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Validator\Validator\ValidatorInterface; class UserAccountController extends AbstractController diff --git a/src/Controller/SignalementController.php b/src/Controller/SignalementController.php index 1412f4222..ff66d0873 100755 --- a/src/Controller/SignalementController.php +++ b/src/Controller/SignalementController.php @@ -35,7 +35,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -143,7 +143,7 @@ public function checkSignalementOrDraftAlreadyExists( 'already_exists' => true, 'type' => 'signalement', 'signalements' => $signalements, - 'draft_exists' => $existingSignalementDraft ? true : false, + 'draft_exists' => (bool) $existingSignalementDraft, ]); } @@ -233,9 +233,7 @@ public function sendMailContinueFromDraft( $signalementDraftRequest, ); - if ( - $signalementDraft - ) { + if ($signalementDraft) { $success = $notificationMailerRegistry->send( new NotificationMail( type: NotificationMailerType::TYPE_CONTINUE_FROM_DRAFT, @@ -251,7 +249,7 @@ public function sendMailContinueFromDraft( 'success' => false, 'label' => 'Erreur', 'message' => 'L\'envoi du mail n\'a pas fonctionné, veuillez réessayer ou faire un nouveau signalement.', - ]); + ], Response::HTTP_BAD_REQUEST); } return $this->json(['response' => 'error'], Response::HTTP_BAD_REQUEST); @@ -420,7 +418,7 @@ public function suiviProcedure( EntityManagerInterface $entityManager, SuiviFactory $suiviFactory, SignalementDesordresProcessor $signalementDesordresProcessor - ) { + ): RedirectResponse|Response { $signalement = $signalementRepository->findOneByCodeForPublic($code); if (!$signalement) { $this->addFlash('error', 'Le lien utilisé est expiré ou invalide.'); @@ -541,7 +539,7 @@ public function suiviSignalement( Request $request, UserManager $userManager, SignalementDesordresProcessor $signalementDesordresProcessor - ) { + ): RedirectResponse|Response { if ($signalement = $signalementRepository->findOneByCodeForPublic($code, false)) { $requestEmail = $request->get('from'); $fromEmail = \is_array($requestEmail) ? array_pop($requestEmail) : $requestEmail; diff --git a/src/Controller/SignalementFileController.php b/src/Controller/SignalementFileController.php index 126a40985..093073072 100644 --- a/src/Controller/SignalementFileController.php +++ b/src/Controller/SignalementFileController.php @@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; #[Route('/signalement')] class SignalementFileController extends AbstractController diff --git a/src/Controller/StatistiquesController.php b/src/Controller/StatistiquesController.php index fec3bec56..b653988e5 100755 --- a/src/Controller/StatistiquesController.php +++ b/src/Controller/StatistiquesController.php @@ -15,7 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; class StatistiquesController extends AbstractController { diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 84b5b9690..8c240171d 100755 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -2,46 +2,47 @@ namespace App\EventListener; -use App\Entity\Signalement; use App\Service\Mailer\NotificationMail; use App\Service\Mailer\NotificationMailerRegistry; use App\Service\Mailer\NotificationMailerType; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\Routing\Exception\MethodNotAllowedException; +use Symfony\Component\Serializer\Exception\NotEncodableValueException; -class ExceptionListener +readonly class ExceptionListener { public function __construct( - private readonly NotificationMailerRegistry $notificationMailerRegistry, - private readonly ParameterBagInterface $params, + private NotificationMailerRegistry $notificationMailerRegistry, + private ParameterBagInterface $params, + private LoggerInterface $logger, ) { } public function onKernelException(ExceptionEvent $event): void { - if (!$event->getThrowable() instanceof MethodNotAllowedException - && null !== $event->getRequest()->get('signalement')) { - $attachment = ['documents' => 0, 'photos' => 0]; - if ($files = $event->getRequest()->files->get('signalement')) { - foreach ($files as $k => $file) { - foreach ($file as $file_) { - ++$attachment[$k]; - } - } - } + $exception = $event->getThrowable(); + if ($exception instanceof NotEncodableValueException) { + $this->logger->error(sprintf('Format json incorrect : %s', $exception->getMessage())); - $territory = null; - if ($event->getRequest()->get('signalement') instanceof Signalement) { - $territory = $event->getRequest()->get('signalement')->getTerritory(); - } + $response = new JsonResponse([ + 'success' => false, + 'label' => 'Erreur', + 'message' => 'Le format JSON est incorrect', + ], Response::HTTP_BAD_REQUEST); + + $event->setResponse($response); + } + + if (!$exception instanceof MethodNotAllowedException) { $this->notificationMailerRegistry->send( new NotificationMail( type: NotificationMailerType::TYPE_ERROR_SIGNALEMENT, to: $this->params->get('admin_email'), - territory: $territory, event: $event, - attachment: $attachment, ) ); } diff --git a/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php b/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php index b5ac7a817..ac9de6696 100644 --- a/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php +++ b/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php @@ -35,7 +35,6 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa 'code' => $event->getThrowable()->getCode(), 'error' => $event->getThrowable()->getMessage(), 'req' => $event->getRequest()->getContent(), - 'signalement' => $event->getRequest()->get('signalement'), 'attachment' => $attachment, ]; } diff --git a/src/Service/Security/FileScanner.php b/src/Service/Security/FileScanner.php index c5fd4f2dc..3d45097d5 100644 --- a/src/Service/Security/FileScanner.php +++ b/src/Service/Security/FileScanner.php @@ -28,6 +28,11 @@ public function isClean(string $filePath, ?bool $copy = true): bool if (!$this->clamavScanEnable) { return true; } + + if (empty($filePath)) { + return false; + } + if ($copy) { $copiedFilepath = $this->parameterBag->get('uploads_tmp_dir').'clamav_'.Uuid::v4(); file_put_contents($copiedFilepath, file_get_contents($filePath)); diff --git a/src/Service/Signalement/SignalementDraftHelper.php b/src/Service/Signalement/SignalementDraftHelper.php index 721a44d7b..aec746de2 100644 --- a/src/Service/Signalement/SignalementDraftHelper.php +++ b/src/Service/Signalement/SignalementDraftHelper.php @@ -24,6 +24,10 @@ public static function isTiersDeclarant(SignalementDraftRequest $signalementDraf public static function getEmailDeclarant(SignalementDraftRequest $signalementDraftRequest): ?string { + if (empty($signalementDraftRequest->getProfil())) { + return null; + } + switch (strtoupper($signalementDraftRequest->getProfil())) { case ProfileDeclarant::SERVICE_SECOURS->name: case ProfileDeclarant::BAILLEUR->name: diff --git a/templates/emails/erreur_signalement_email.html.twig b/templates/emails/erreur_signalement_email.html.twig index fc5cca4c8..212f74fea 100755 --- a/templates/emails/erreur_signalement_email.html.twig +++ b/templates/emails/erreur_signalement_email.html.twig @@ -16,7 +16,4 @@ {% if req is defined %}

{{ req|json_encode() }}

{% endif %} - {% if signalement is defined %} -

{{ signalement|json_encode()|replace({',':',
'})|raw }}

- {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/tests/Functional/Controller/SignalementControllerTest.php b/tests/Functional/Controller/SignalementControllerTest.php index 7ce9cf187..565a928d5 100644 --- a/tests/Functional/Controller/SignalementControllerTest.php +++ b/tests/Functional/Controller/SignalementControllerTest.php @@ -250,6 +250,19 @@ public function testSignalementEdit(): void $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); } + public function testSendMailContinueFromNotValidDraft(): void + { + $client = static::createClient(); + + /** @var RouterInterface $router */ + $router = $client->getContainer()->get(RouterInterface::class); + $url = $router->generate('send_mail_continue_from_draft'); + + $client->request('POST', $url, [], [], [], ''); + + $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode()); + } + public function provideSignalementRequestPayload(): \Generator { yield 'Post signalement as locataire (Mails sent: Occupant + RT)' => [ diff --git a/tests/Unit/Service/FileScannerTest.php b/tests/Unit/Service/FileScannerTest.php new file mode 100644 index 000000000..d7c9010e3 --- /dev/null +++ b/tests/Unit/Service/FileScannerTest.php @@ -0,0 +1,60 @@ +createMock(Scanner::class); + $parameterBag = $this->createMock(ParameterBagInterface::class); + + $fileScanner = new FileScanner($scanner, $parameterBag, true); + $result = $fileScanner->isClean(''); + + $this->assertFalse($result, 'Should return false for empty file path.'); + } + + public function testIsCleanWithCopyOption() + { + $scanner = $this->createMock(Scanner::class); + $parameterBag = $this->createMock(ParameterBagInterface::class); + $scannedFile = $this->createMock(ScannedFile::class); + + $parameterBag + ->expects($this->once()) + ->method('get') + ->with('uploads_tmp_dir') + ->willReturn('tmp/'); + + $scannedFile + ->expects($this->once()) + ->method('isClean') + ->willReturn(true); + + $scanner + ->expects($this->once()) + ->method('scan') + ->with($this->callback(function ($copiedFilepath) { + return str_starts_with($copiedFilepath, 'tmp/clamav_'); + })) + ->willReturn($scannedFile); + + $fileScanner = new FileScanner($scanner, $parameterBag, true); + + $dummyFilePath = 'tmp/dummy.txt'; + file_put_contents($dummyFilePath, 'dummy content'); + + $result = $fileScanner->isClean($dummyFilePath); + + unlink($dummyFilePath); + + $this->assertTrue($result, 'Should return true for a clean scanned file.'); + } +} From cce2e503f1b500ed81646169d649148c0051b28d Mon Sep 17 00:00:00 2001 From: Saidi Date: Wed, 25 Sep 2024 16:53:14 +0200 Subject: [PATCH 2/2] remove attachement for error template #3087 #3088 --- src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php | 2 -- templates/emails/erreur_signalement_email.html.twig | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php b/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php index ac9de6696..45b50c527 100644 --- a/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php +++ b/src/Service/Mailer/Mail/Error/ErrorSignalementMailer.php @@ -28,14 +28,12 @@ public function __construct( public function getMailerParamsFromNotification(NotificationMail $notificationMail): array { $event = $notificationMail->getEvent(); - $attachment = $notificationMail->getAttachment(); return [ 'url' => $_SERVER['SERVER_NAME'] ?? 'non défini', 'code' => $event->getThrowable()->getCode(), 'error' => $event->getThrowable()->getMessage(), 'req' => $event->getRequest()->getContent(), - 'attachment' => $attachment, ]; } } diff --git a/templates/emails/erreur_signalement_email.html.twig b/templates/emails/erreur_signalement_email.html.twig index 212f74fea..3baae815a 100755 --- a/templates/emails/erreur_signalement_email.html.twig +++ b/templates/emails/erreur_signalement_email.html.twig @@ -9,10 +9,6 @@ {% if error is defined %}

Message erreur: {{ error }}

{% endif %} - {% if attachment is defined %} -

Documents: {{ attachment.documents }}

-

Photos: {{ attachment.photos }}

- {% endif %} {% if req is defined %}

{{ req|json_encode() }}

{% endif %}