From 0ad0113e77f1f1900640c6327983ab8a95d0bae1 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Dec 2025 09:34:38 +0100 Subject: [PATCH 1/5] fix: Execute the messenger:consume command as www-data --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a4ec75b8..8f40bdfa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,7 +76,7 @@ services: image: probesys38/agentj_app:$VERSION build: context: ./app - command: "php /var/www/agentj/bin/console messenger:consume async scheduler_default --memory-limit=128M" + command: "sudo -u www-data php /var/www/agentj/bin/console messenger:consume async scheduler_default --memory-limit=128M" entrypoint: "/entrypoint-worker.sh" restart: unless-stopped env_file: From faccbb2ced6ca2553be3c6b97417a6607ffbd760 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Dec 2025 09:52:10 +0100 Subject: [PATCH 2/5] fix: Fix autorelease with a high number of untreated messages An issue happened when there was a high number of untreated messages associated to users without the "bypass human authentication" option. Indeed, the `getSearchQuery()` could return 1000 messages concerning these users, while the 1001th message (not returned) could have concerned a user with the "bypass" option enabled. Now, we iterate on the users with the option enabled and we get their untreated messages so we are sure to always load messages that need to be loaded. --- app/src/Command/AmavisAutoReleaseCommand.php | 32 ++++++++------------ app/src/Repository/UserRepository.php | 10 ++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/Command/AmavisAutoReleaseCommand.php b/app/src/Command/AmavisAutoReleaseCommand.php index 810709db..dff9b63a 100644 --- a/app/src/Command/AmavisAutoReleaseCommand.php +++ b/app/src/Command/AmavisAutoReleaseCommand.php @@ -20,7 +20,7 @@ )] class AmavisAutoReleaseCommand extends Command { - private int $batchSize = 1000; + private int $batchSize = 500; public function __construct( private MsgrcptSearchRepository $msgrcptSearchRepository, @@ -43,28 +43,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } - $searchQuery = $this->msgrcptSearchRepository->getSearchQuery( - null, - MessageStatus::UNTREATED - ); + $users = $this->userRepository->findAllWithoutHumanAuthentication(); - $messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult(); + foreach ($users as $user) { + $searchQuery = $this->msgrcptSearchRepository->getSearchQuery( + $user, + MessageStatus::UNTREATED + ); - foreach ($messageRecipients as $messageRecipient) { - if ($messageRecipient->isAmavisReleaseOngoing()) { - continue; - } - - $user = $this->userRepository->findOneBy([ - 'email' => $messageRecipient->getRid()->getEmailClear() - ]); - - if (!$user) { - continue; - } + $messageRecipients = $searchQuery->setMaxResults($this->batchSize)->getResult(); - if ($user->getBypassHumanAuth()) { - $this->messageService->dispatchRelease($messageRecipient); + foreach ($messageRecipients as $messageRecipient) { + if (!$messageRecipient->isAmavisReleaseOngoing()) { + $this->messageService->dispatchRelease($messageRecipient); + } } } diff --git a/app/src/Repository/UserRepository.php b/app/src/Repository/UserRepository.php index da92e0b3..69e7ab8c 100644 --- a/app/src/Repository/UserRepository.php +++ b/app/src/Repository/UserRepository.php @@ -65,6 +65,16 @@ public function findOneByPrincipalName(string $principalName): ?User ->getOneOrNullResult(); } + /** + * @return User[] + */ + public function findAllWithoutHumanAuthentication(): array + { + return $this->findBy([ + 'bypassHumanAuth' => true, + ]); + } + /** * Return all users from active domains * From b428b41dc17afdfaf80d2dd236ddd6097d93036d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 18 Dec 2025 15:05:13 +0100 Subject: [PATCH 3/5] fix: Fix setting the locale Two problems happened. First, the `Accept-Language` header was ignored when the user wasn't logged-in. It means that the French locale was always used. The refactor of the LocaleSubscriber fixes this. The second problem was that once the session expired, but that the user was logged in again through the "remember me" cookie, the locale wasn't set anymore. This is why I introduce a UserLocaleSubscriber which is triggered on "interactive login", meaning it is called both on normal login, and on "remember me" login. --- app/src/EventSubscriber/LocaleSubscriber.php | 26 ++++++------- .../EventSubscriber/UserLocaleSubscriber.php | 38 +++++++++++++++++++ app/src/Security/LoginFormAuthenticator.php | 12 ------ 3 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 app/src/EventSubscriber/UserLocaleSubscriber.php diff --git a/app/src/EventSubscriber/LocaleSubscriber.php b/app/src/EventSubscriber/LocaleSubscriber.php index e2c4c7a2..1abb7a2d 100644 --- a/app/src/EventSubscriber/LocaleSubscriber.php +++ b/app/src/EventSubscriber/LocaleSubscriber.php @@ -2,39 +2,35 @@ namespace App\EventSubscriber; +use App\Service\LocaleService; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class LocaleSubscriber implements EventSubscriberInterface { - private string $defaultLocale; - - public function __construct(string $defaultLocale = 'fr') - { - $this->defaultLocale = $defaultLocale; + public function __construct( + private LocaleService $localeService, + ) { } public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); - if (!$request->hasPreviousSession()) { - return; - } - // try to see if the locale has been set as a _locale routing parameter - if ($locale = $request->attributes->get('_locale')) { - $request->getSession()->set('_locale', $locale); - } else { - // if no explicit locale has been set on this request, use one from the session - $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale)); + $supportedLocalesCodes = $this->localeService->getSupportedLocalesCodes(); + $locale = $request->getPreferredLanguage($supportedLocalesCodes); + + if ($request->hasPreviousSession()) { + $locale = $request->getSession()->get('_locale', $locale); } + + $request->setLocale($locale); } public static function getSubscribedEvents(): array { return [ - // must be registered before (i.e. with a higher priority than) the default Locale listener KernelEvents::REQUEST => [['onKernelRequest', 20]], ]; } diff --git a/app/src/EventSubscriber/UserLocaleSubscriber.php b/app/src/EventSubscriber/UserLocaleSubscriber.php new file mode 100644 index 00000000..530565a9 --- /dev/null +++ b/app/src/EventSubscriber/UserLocaleSubscriber.php @@ -0,0 +1,38 @@ +getAuthenticationToken()->getUser(); + + $request = $this->requestStack->getCurrentRequest(); + $session = $this->requestStack->getSession(); + $userLocale = $this->localeService->getUserLocale($user); + + $session->set('_locale', $userLocale); + $request->setLocale($userLocale); + } + + public static function getSubscribedEvents(): array + { + return [ + SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin', + ]; + } +} diff --git a/app/src/Security/LoginFormAuthenticator.php b/app/src/Security/LoginFormAuthenticator.php index bb85d2d5..3184471a 100644 --- a/app/src/Security/LoginFormAuthenticator.php +++ b/app/src/Security/LoginFormAuthenticator.php @@ -164,18 +164,6 @@ private function getLocalUser(string $userName): ?User public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { - /** @var User $user */ - $user = $token->getUser(); - - if ($user->getDomain() && $user->getDomain()->getDefaultLang()) { - $request->getSession()->set('_locale', $user->getDomain()->getDefaultLang()); - } - - - if ($user->getPreferedLang()) { - $request->getSession()->set('_locale', $user->getPreferedLang()); - } - if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) { return new RedirectResponse($targetPath); } From e9b39cdf333eee767c8aedf83cd11d09f78b6832 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Dec 2025 10:15:57 +0100 Subject: [PATCH 4/5] fix: Fix English translation in dashboard stats --- app/templates/dashboard/stats-by-status.html.twig | 2 +- app/translations/messages.en.yml | 1 + app/translations/messages.fr.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/dashboard/stats-by-status.html.twig b/app/templates/dashboard/stats-by-status.html.twig index 18df50ae..1e4a3acd 100644 --- a/app/templates/dashboard/stats-by-status.html.twig +++ b/app/templates/dashboard/stats-by-status.html.twig @@ -79,7 +79,7 @@ if (filteredData.datasets[0].data.length === 0) { // Display a message if there is no data document.getElementById('messagesChart').style.display = 'none'; var noDataMessage = document.createElement('p'); - noDataMessage.textContent = 'Aucun message bloqué'; + noDataMessage.textContent = '{{ 'Entities.Message.noBlockedMessages' | trans }}'; noDataMessage.style.textAlign = 'center'; noDataMessage.style.marginTop = '20px'; document.getElementById('messagesChart').parentNode.appendChild(noDataMessage); diff --git a/app/translations/messages.en.yml b/app/translations/messages.en.yml index a4554034..c2087978 100644 --- a/app/translations/messages.en.yml +++ b/app/translations/messages.en.yml @@ -622,6 +622,7 @@ Entities: spamLevel: Note dateAuthRequestAt: "Authentication request sent the" isMailingList: "Mailing list? " + noBlockedMessages: 'No blocked messages' labels: infos: "Information about the blockage" preview: "Preview of the message" diff --git a/app/translations/messages.fr.yml b/app/translations/messages.fr.yml index 96ea331a..32fe3985 100644 --- a/app/translations/messages.fr.yml +++ b/app/translations/messages.fr.yml @@ -622,6 +622,7 @@ Entities: spamLevel: Note dateAuthRequestAt: "Demande d'authentification envoyée le" isMailingList: "Mailing liste ? " + noBlockedMessages: 'Aucun message bloqué' labels: infos: "Informations sur les refus" preview: "Aperçu du message" From c4157b1ae08eee8f946bca4f1ddbc8c852ddd512 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Dec 2025 16:49:26 +0100 Subject: [PATCH 5/5] release: Publish version 2.4.2 --- .env.example | 2 +- CHANGELOG.md | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index eea89b03..9bdb2f91 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # Which images to pull for production deployment -VERSION=2.4.1 +VERSION=2.4.2 # Impact containers names, see # https://docs.docker.com/compose/how-tos/environment-variables/envvars/#compose_project_name diff --git a/CHANGELOG.md b/CHANGELOG.md index 347b14b1..09b475d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog of AgentJ +## 2025-12-19 - 2.4.2 + +### Bug fixes + +- Execute the `messenger:consume` command as `www-data` ([0ad0113e](https://github.com/Probesys/agentj/commit/0ad0113e)) +- Fix setting the default locale ([b428b41d](https://github.com/Probesys/agentj/commit/b428b41d)) +- Fix autorelease with a high number of untreated messages ([faccbb2c](https://github.com/Probesys/agentj/commit/faccbb2c)) +- Fix an English translation in the dashboard stats ([e9b39cdf](https://github.com/Probesys/agentj/commit/e9b39cdf)) + ## 2025-12-18 - 2.4.1 ### Maintenance