diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index fd35ef31b..2131f5c65 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -213,6 +213,8 @@ class HouseholdMemberController extends ApiController } $em->flush(); + $editor->triggerAudit(); + return $this->json($editor->getHousehold(), Response::HTTP_OK, [], ['groups' => ['read']]); } } diff --git a/src/Bundle/ChillPersonBundle/Household/MembersEditor.php b/src/Bundle/ChillPersonBundle/Household/MembersEditor.php index d5e1dfe59..751bbad0f 100644 --- a/src/Bundle/ChillPersonBundle/Household/MembersEditor.php +++ b/src/Bundle/ChillPersonBundle/Household/MembersEditor.php @@ -11,12 +11,15 @@ declare(strict_types=1); namespace Chill\PersonBundle\Household; +use Chill\MainBundle\Audit\TriggerAuditInterface; +use Chill\MainBundle\Entity\AuditTrail; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Household\Position; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent; use Doctrine\Common\Collections\Criteria; +use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -32,6 +35,9 @@ class MembersEditor private array $events = []; + /** + * @var list + */ private array $membershipsAffected = []; private array $oldMembershipsHashes = []; @@ -42,6 +48,7 @@ class MembersEditor private readonly ValidatorInterface $validator, private readonly ?Household $household, private readonly EventDispatcherInterface $eventDispatcher, + private readonly TriggerAuditInterface $triggerAudit, ) {} /** @@ -195,6 +202,13 @@ class MembersEditor } } + public function triggerAudit(): void + { + foreach ($this->membershipsAffected as $participation) { + $this->triggerAudit->triggerAudit(AuditTrail::AUDIT_UPDATE, $participation, description: new TranslatableMessage('audit.household.edit_participation')); + } + } + public function validate(): ConstraintViolationListInterface { if ($this->hasHousehold()) { diff --git a/src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php b/src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php index 071866b96..aa51c125f 100644 --- a/src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php +++ b/src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php @@ -11,16 +11,21 @@ declare(strict_types=1); namespace Chill\PersonBundle\Household; +use Chill\MainBundle\Audit\TriggerAuditInterface; use Chill\PersonBundle\Entity\Household\Household; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class MembersEditorFactory { - public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly ValidatorInterface $validator) {} + public function __construct( + private readonly EventDispatcherInterface $eventDispatcher, + private readonly ValidatorInterface $validator, + private readonly TriggerAuditInterface $triggerAudit, + ) {} public function createEditor(?Household $household = null): MembersEditor { - return new MembersEditor($this->validator, $household, $this->eventDispatcher); + return new MembersEditor($this->validator, $household, $this->eventDispatcher, $this->triggerAudit); } }