From b354ea1ce24e320e0daabd237ed14cb4d7b86970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Feb 2026 15:57:21 +0100 Subject: [PATCH] Add "list" action to audit functionality and French translations - Introduced `AUDIT_LIST` constant in `AuditTrail` entity to support "list" action auditing. - Updated French translations (`messages.fr.yml`) to include label for "list" action. --- .../Converter/CalendarSubjectConverter.php | 56 +++++++++++++++++++ .../Audit/Displayer/CalendarDisplayer.php | 43 ++++++++++++++ .../Controller/CalendarController.php | 29 ++++++---- .../Resources/config/services.yml | 5 ++ .../translations/messages+intl-icu.fr.yml | 7 +++ 5 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Audit/Converter/CalendarSubjectConverter.php create mode 100644 src/Bundle/ChillCalendarBundle/Audit/Displayer/CalendarDisplayer.php diff --git a/src/Bundle/ChillCalendarBundle/Audit/Converter/CalendarSubjectConverter.php b/src/Bundle/ChillCalendarBundle/Audit/Converter/CalendarSubjectConverter.php new file mode 100644 index 000000000..031ed84ac --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Audit/Converter/CalendarSubjectConverter.php @@ -0,0 +1,56 @@ + $subject->getId()], + ); + + $bag = new SubjectBag($main); + if ($includeAssociated) { + if (null !== $subject->getPerson()) { + $bag->append($this->subjectConverterManager->getSubjectsForEntity($subject->getPerson(), false)); + } + if (null !== $subject->getAccompanyingPeriod()) { + $bag->append($this->subjectConverterManager->getSubjectsForEntity($subject->getAccompanyingPeriod(), false)); + } + } + + return $bag; + } + + public static function getDefaultPriority(): int + { + return 0; + } +} diff --git a/src/Bundle/ChillCalendarBundle/Audit/Displayer/CalendarDisplayer.php b/src/Bundle/ChillCalendarBundle/Audit/Displayer/CalendarDisplayer.php new file mode 100644 index 000000000..1219486c3 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Audit/Displayer/CalendarDisplayer.php @@ -0,0 +1,43 @@ +type; + } + + public function display(Subject $subject, string $format = 'html', array $options = []): string + { + $calendar = $this->calendarRepository->find($subject->identifiers['id']); + + if (null === $calendar) { + $label = $this->translator->trans('audit.calendar.subject', ['id' => $subject->identifiers['id']], 'messages'); + } else { + $label = $this->translator->trans('audit.calendar.subject_with_details', ['id' => $subject->identifiers['id'], 'at' => $calendar->getStartDate()], 'messages'); + } + + return 'html' === $format ? ''.$label.'' : $label; + } +} diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 6705d7bb7..2c38eca49 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -18,6 +18,8 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterfa use Chill\CalendarBundle\Repository\CalendarACLAwareRepositoryInterface; use Chill\CalendarBundle\Security\Voter\CalendarVoter; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; +use Chill\MainBundle\Audit\TriggerAuditInterface; +use Chill\MainBundle\Entity\AuditTrail; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\UserRepositoryInterface; @@ -44,6 +46,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatorInterface; class CalendarController extends AbstractController @@ -61,6 +64,7 @@ class CalendarController extends AbstractController private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly UserRepositoryInterface $userRepository, private readonly TranslatorInterface $translator, + private readonly TriggerAuditInterface $triggerAudit, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $em, ) {} @@ -96,6 +100,8 @@ class CalendarController extends AbstractController 'calendar_id' => $entity->getId(), ]); + ($this->triggerAudit)(AuditTrail::AUDIT_DELETE, $entity); + $em->remove($entity); $em->flush(); @@ -148,6 +154,9 @@ class CalendarController extends AbstractController $calendar->setStatus($calendar::STATUS_CANCELED); $calendar->setSmsStatus($calendar::SMS_CANCEL_PENDING); + + ($this->triggerAudit)(AuditTrail::AUDIT_UPDATE, $calendar, description: new TranslatableMessage('audit.calendar.cancel')); + $this->em->flush(); $this->addFlash('success', $this->translator->trans('chill_calendar.calendar_canceled')); @@ -204,6 +213,7 @@ class CalendarController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + ($this->triggerAudit)(AuditTrail::AUDIT_UPDATE, $entity); $em->flush(); $this->addFlash('success', $this->translator->trans('Success : calendar item updated!')); @@ -250,6 +260,8 @@ class CalendarController extends AbstractController { $this->denyAccessUnlessGranted(CalendarVoter::SEE, $accompanyingPeriod); + ($this->triggerAudit)(AuditTrail::AUDIT_LIST, $accompanyingPeriod, description: new TranslatableMessage('audit.calendar.list_by_period')); + $filterOrder = $this->buildListFilterOrder(); ['from' => $from, 'to' => $to] = $filterOrder->getDateRangeData('startDate'); @@ -283,6 +295,8 @@ class CalendarController extends AbstractController { $this->denyAccessUnlessGranted(CalendarVoter::SEE, $person); + ($this->triggerAudit)(AuditTrail::AUDIT_LIST, $person, description: new TranslatableMessage('audit.calendar.list_by_person')); + $filterOrder = $this->buildListFilterOrder(); ['from' => $from, 'to' => $to] = $filterOrder->getDateRangeData('startDate'); @@ -381,6 +395,8 @@ class CalendarController extends AbstractController $em->persist($entity); $em->flush(); + ($this->triggerAudit)(AuditTrail::AUDIT_CREATE, $entity); + $this->addFlash('success', $this->translator->trans('Success : calendar item created!')); if ($form->get('save_and_upload_doc')->isClicked()) { @@ -453,20 +469,12 @@ class CalendarController extends AbstractController /** @var Calendar $entity */ $entity = $em->getRepository(Calendar::class)->find($id); + ($this->triggerAudit)(AuditTrail::AUDIT_VIEW, $entity); + if (null === $entity) { throw $this->createNotFoundException('Unable to find Calendar entity.'); } - if (null !== $accompanyingPeriod) { - // @TODO: These properties are declared dynamically. - // It must be removed. - // @See https://wiki.php.net/rfc/deprecate_dynamic_properties - $entity->personsAssociated = $entity->getPersonsAssociated(); - $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); - } - - // $deleteForm = $this->createDeleteForm($id, $accompanyingPeriod); - $personsId = array_map( static fn (Person $p): int => $p->getId(), $entity->getPersons()->toArray() @@ -495,7 +503,6 @@ class CalendarController extends AbstractController 'entity' => $entity, 'user' => $user, 'activityData' => $activityData, - // 'delete_form' => $deleteForm->createView(), ]); } diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services.yml index 7e316acf3..b0f461606 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services.yml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services.yml @@ -39,5 +39,10 @@ services: autowire: true resource: '../../Service/' + Chill\CalendarBundle\Audit\: + autoconfigure: true + autowire: true + resource: '../../Audit/' + Chill\CalendarBundle\Service\ShortMessageForCalendarBuilderInterface: alias: Chill\CalendarBundle\Service\DefaultShortMessageForCalendarBuider diff --git a/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml index 7c8e59231..0320451aa 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml @@ -1,3 +1,10 @@ +audit: + calendar: + cancel: Annulation du rendez-vous + subject: Rendez-vous n°{id} + subject_with_details: Rendez-vous n°{id} le {at, date, medium} - {at, time, medium} + list_by_person: Liste les rendez-vous par usager + list_by_period: Liste les rendez-vous par parcours d''accompagnement chill_calendar: There are count ignored calendars by date filter: >- {nbIgnored, plural,