mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-03 04:29:40 +00:00
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:
@@ -213,6 +213,8 @@ class HouseholdMemberController extends ApiController
|
||||
}
|
||||
$em->flush();
|
||||
|
||||
$editor->triggerAudit();
|
||||
|
||||
return $this->json($editor->getHousehold(), Response::HTTP_OK, [], ['groups' => ['read']]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user