Add audit functionality to MembersEditor and trigger audit in HouseholdMemberController

- Added `TriggerAuditInterface` to `MembersEditorFactory` and `MembersEditor` for managing audit events.
- Implemented `triggerAudit` method in `MembersEditor` to log participation edits with translatable descriptions.
- Updated `HouseholdMemberController` to invoke `triggerAudit` after saving changes.
This commit is contained in:
2026-02-26 16:00:23 +01:00
parent c013cfd032
commit 7d147f921d
3 changed files with 23 additions and 2 deletions

View File

@@ -213,6 +213,8 @@ class HouseholdMemberController extends ApiController
}
$em->flush();
$editor->triggerAudit();
return $this->json($editor->getHousehold(), Response::HTTP_OK, [], ['groups' => ['read']]);
}
}

View File

@@ -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<HouseholdMember>
*/
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()) {

View File

@@ -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);
}
}