From 60bb3cf8c4d19ddc6f787ff87d49d5dbcdc7d780 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 25 Mar 2026 10:49:20 +0100 Subject: [PATCH] =?UTF-8?q?fix=20:=20verrouillage=20utilisateur=20+=20modi?= =?UTF-8?q?fication=20de=20contrat=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/User.php | 4 ++++ .../Contracts/EmployeeContractPeriodManager.php | 17 ++++++++++------- .../EmployeeContractPeriodManagerInterface.php | 3 ++- src/State/EmployeeWriteProcessor.php | 4 +++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index d878bfb..b102611 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Attribute\Groups; +use Symfony\Component\Serializer\Attribute\SerializedName; #[ApiResource( operations: [ @@ -86,6 +87,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: 'boolean', options: ['default' => false])] #[Groups(['user:read', 'user:write'])] + #[SerializedName('isLocked')] private bool $isLocked = false; /** @@ -208,6 +210,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + #[Groups(['user:read'])] + #[SerializedName('isLocked')] public function isLocked(): bool { return $this->isLocked; diff --git a/src/Service/Contracts/EmployeeContractPeriodManager.php b/src/Service/Contracts/EmployeeContractPeriodManager.php index 6f8fb01..fec9e9a 100644 --- a/src/Service/Contracts/EmployeeContractPeriodManager.php +++ b/src/Service/Contracts/EmployeeContractPeriodManager.php @@ -45,18 +45,21 @@ final readonly class EmployeeContractPeriodManager implements EmployeeContractPe ?EmployeeContractPeriod $todayPeriod, DateTimeImmutable $requestedEndDate, bool $paidLeaveSettled, - ?string $comment = null + ?string $comment = null, + bool $isAlreadyEnded = false ): void { if (null === $todayPeriod) { throw new UnprocessableEntityHttpException('No active contract period to close.'); } - $this->periodValidator->assertCloseEndDateCanBeApplied( - $todayPeriod->getStartDate(), - $todayPeriod->getEndDate(), - $requestedEndDate, - $todayPeriod->getContractNatureEnum() - ); + if (!$isAlreadyEnded) { + $this->periodValidator->assertCloseEndDateCanBeApplied( + $todayPeriod->getStartDate(), + $todayPeriod->getEndDate(), + $requestedEndDate, + $todayPeriod->getContractNatureEnum() + ); + } $todayPeriod->setEndDate($requestedEndDate); $todayPeriod->setPaidLeaveSettled($paidLeaveSettled); diff --git a/src/Service/Contracts/EmployeeContractPeriodManagerInterface.php b/src/Service/Contracts/EmployeeContractPeriodManagerInterface.php index 12697f2..9198f6f 100644 --- a/src/Service/Contracts/EmployeeContractPeriodManagerInterface.php +++ b/src/Service/Contracts/EmployeeContractPeriodManagerInterface.php @@ -25,7 +25,8 @@ interface EmployeeContractPeriodManagerInterface ?EmployeeContractPeriod $todayPeriod, DateTimeImmutable $requestedEndDate, bool $paidLeaveSettled, - ?string $comment = null + ?string $comment = null, + bool $isAlreadyEnded = false ): void; public function createNextPeriod( diff --git a/src/State/EmployeeWriteProcessor.php b/src/State/EmployeeWriteProcessor.php index a5f541b..1fefcd3 100644 --- a/src/State/EmployeeWriteProcessor.php +++ b/src/State/EmployeeWriteProcessor.php @@ -92,11 +92,13 @@ final readonly class EmployeeWriteProcessor implements ProcessorInterface if (null === $requestedEndDate) { throw new UnprocessableEntityHttpException('contractEndDate is required for close-only request.'); } + $isAlreadyEnded = null === $todayPeriod; $this->periodManager->closeCurrentPeriod( $effectivePeriod, $requestedEndDate, $changeRequest->contractPaidLeaveSettled ?? false, - $changeRequest->contractComment + $changeRequest->contractComment, + $isAlreadyEnded ); return $result;