mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
Add tracking of addressee history in ticket system
The updates introduce tracking for the history of addressees in the ticket system, both when added and when removed. The user who removed an addressee is now recorded. The changes also ensure these updated aspects are correctly normalized and users can see them in the ticket history. A new database migration file was created for the changes.
This commit is contained in:
parent
fa67835690
commit
ed45f14a45
@ -11,17 +11,20 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Action\Ticket\Handler;
|
namespace Chill\TicketBundle\Action\Ticket\Handler;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\TicketBundle\Action\Ticket\SetAddresseesCommand;
|
use Chill\TicketBundle\Action\Ticket\SetAddresseesCommand;
|
||||||
use Chill\TicketBundle\Entity\AddresseeHistory;
|
use Chill\TicketBundle\Entity\AddresseeHistory;
|
||||||
use Chill\TicketBundle\Entity\Ticket;
|
use Chill\TicketBundle\Entity\Ticket;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Clock\ClockInterface;
|
use Symfony\Component\Clock\ClockInterface;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
final readonly class SetAddresseesCommandHandler
|
final readonly class SetAddresseesCommandHandler
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ClockInterface $clock,
|
private ClockInterface $clock,
|
||||||
private EntityManagerInterface $entityManager,
|
private EntityManagerInterface $entityManager,
|
||||||
|
private Security $security,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function handle(Ticket $ticket, SetAddresseesCommand $command): void
|
public function handle(Ticket $ticket, SetAddresseesCommand $command): void
|
||||||
@ -34,6 +37,9 @@ final readonly class SetAddresseesCommandHandler
|
|||||||
|
|
||||||
if (!in_array($addressHistory->getAddressee(), $command->addressees, true)) {
|
if (!in_array($addressHistory->getAddressee(), $command->addressees, true)) {
|
||||||
$addressHistory->setEndDate($this->clock->now());
|
$addressHistory->setEndDate($this->clock->now());
|
||||||
|
if (($user = $this->security->getUser()) instanceof User) {
|
||||||
|
$addressHistory->setRemovedBy($user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20240423212824 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add endDate and removedBy columns on addressee history (ticket)';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history ADD endDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT null');
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history ADD removedBy_id INT DEFAULT NULL');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_ticket.addressee_history.endDate IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history ADD CONSTRAINT FK_434EBDBDB8346CCF FOREIGN KEY (removedBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('CREATE INDEX IDX_434EBDBDB8346CCF ON chill_ticket.addressee_history (removedBy_id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history DROP CONSTRAINT FK_434EBDBDB8346CCF');
|
||||||
|
$this->addSql('DROP INDEX chill_ticket.IDX_434EBDBDB8346CCF');
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history DROP endDate');
|
||||||
|
$this->addSql('ALTER TABLE chill_ticket.addressee_history DROP removedBy_id');
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Component\Clock\MockClock;
|
use Symfony\Component\Clock\MockClock;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -113,6 +114,9 @@ final class SetAddressesCommandHandlerTest extends TestCase
|
|||||||
|
|
||||||
private function buildHandler(EntityManagerInterface $entityManager): SetAddresseesCommandHandler
|
private function buildHandler(EntityManagerInterface $entityManager): SetAddresseesCommandHandler
|
||||||
{
|
{
|
||||||
return new SetAddresseesCommandHandler(new MockClock(), $entityManager);
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->getUser()->willReturn(new User());
|
||||||
|
|
||||||
|
return new SetAddresseesCommandHandler(new MockClock(), $entityManager, $security->reveal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,10 @@ class SetAddresseesControllerTest extends KernelTestCase
|
|||||||
|
|
||||||
private function buildController(bool $willSave, bool $isValid): SetAddresseesController
|
private function buildController(bool $willSave, bool $isValid): SetAddresseesController
|
||||||
{
|
{
|
||||||
|
$user = new User();
|
||||||
$security = $this->prophesize(Security::class);
|
$security = $this->prophesize(Security::class);
|
||||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
$security->getUser()->willReturn($user);
|
||||||
|
|
||||||
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ class SetAddresseesControllerTest extends KernelTestCase
|
|||||||
$security->reveal(),
|
$security->reveal(),
|
||||||
$entityManager->reveal(),
|
$entityManager->reveal(),
|
||||||
$this->serializer,
|
$this->serializer,
|
||||||
new SetAddresseesCommandHandler(new MockClock(), $entityManager->reveal()),
|
new SetAddresseesCommandHandler(new MockClock(), $entityManager->reveal(), $security->reveal()),
|
||||||
$validator->reveal()
|
$validator->reveal()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user