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 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/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/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 * 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); } 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" 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: