feat: Désignation de remplaçants temporaires avec corrections sécurité
Permet aux administrateurs de désigner un enseignant remplaçant pour un autre enseignant absent, sur des classes et matières précises, pour une période donnée. Le dashboard enseignant affiche les remplacements actifs avec les noms de classes/matières au lieu des identifiants bruts. Inclut les corrections de la code review : - Requête findActiveByTenant qui excluait les remplacements en cours mais incluait les futurs (manquait start_date <= :at) - Validation tenant et rôle enseignant dans le handler de désignation pour empêcher l'affectation cross-tenant ou de non-enseignants - Validation structurée du payload classes (Assert\Collection + UUID) pour éviter les erreurs serveur sur payloads malformés - API replaced-classes enrichie avec les noms classe/matière
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DesignateReplacement;
|
||||
|
||||
final readonly class DesignateReplacementCommand
|
||||
{
|
||||
/**
|
||||
* @param array<array{classId: string, subjectId: string}> $classes
|
||||
*/
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $replacedTeacherId,
|
||||
public string $replacementTeacherId,
|
||||
public string $startDate,
|
||||
public string $endDate,
|
||||
public array $classes,
|
||||
public ?string $reason,
|
||||
public string $createdBy,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DesignateReplacement;
|
||||
|
||||
use App\Administration\Domain\Exception\TenantMismatchException;
|
||||
use App\Administration\Domain\Model\SchoolClass\ClassId;
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\Role;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Administration\Domain\Repository\UserRepository;
|
||||
use App\Scolarite\Domain\Exception\UtilisateurNonEnseignantException;
|
||||
use App\Scolarite\Domain\Model\TeacherReplacement\ClassSubjectPair;
|
||||
use App\Scolarite\Domain\Model\TeacherReplacement\TeacherReplacement;
|
||||
use App\Scolarite\Domain\Repository\TeacherReplacementRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class DesignateReplacementHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TeacherReplacementRepository $replacementRepository,
|
||||
private UserRepository $userRepository,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(DesignateReplacementCommand $command): TeacherReplacement
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$replacedTeacherId = UserId::fromString($command->replacedTeacherId);
|
||||
$replacementTeacherId = UserId::fromString($command->replacementTeacherId);
|
||||
|
||||
// Valider l'existence, le tenant et le rôle des enseignants
|
||||
$replacedTeacher = $this->userRepository->get($replacedTeacherId);
|
||||
if (!$replacedTeacher->tenantId->equals($tenantId)) {
|
||||
throw TenantMismatchException::pourUtilisateur($replacedTeacherId, $tenantId);
|
||||
}
|
||||
if (!$replacedTeacher->aLeRole(Role::PROF)) {
|
||||
throw UtilisateurNonEnseignantException::pourUtilisateur($replacedTeacherId);
|
||||
}
|
||||
|
||||
$replacementTeacher = $this->userRepository->get($replacementTeacherId);
|
||||
if (!$replacementTeacher->tenantId->equals($tenantId)) {
|
||||
throw TenantMismatchException::pourUtilisateur($replacementTeacherId, $tenantId);
|
||||
}
|
||||
if (!$replacementTeacher->aLeRole(Role::PROF)) {
|
||||
throw UtilisateurNonEnseignantException::pourUtilisateur($replacementTeacherId);
|
||||
}
|
||||
|
||||
$classes = array_map(
|
||||
static fn (array $pair) => new ClassSubjectPair(
|
||||
ClassId::fromString($pair['classId']),
|
||||
SubjectId::fromString($pair['subjectId']),
|
||||
),
|
||||
$command->classes,
|
||||
);
|
||||
|
||||
$replacement = TeacherReplacement::designer(
|
||||
tenantId: $tenantId,
|
||||
replacedTeacherId: $replacedTeacherId,
|
||||
replacementTeacherId: $replacementTeacherId,
|
||||
startDate: new DateTimeImmutable($command->startDate),
|
||||
endDate: new DateTimeImmutable($command->endDate),
|
||||
classes: $classes,
|
||||
reason: $command->reason,
|
||||
createdBy: UserId::fromString($command->createdBy),
|
||||
now: $this->clock->now(),
|
||||
);
|
||||
|
||||
$this->replacementRepository->save($replacement);
|
||||
|
||||
return $replacement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\EndReplacement;
|
||||
|
||||
final readonly class EndReplacementCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $replacementId,
|
||||
public string $tenantId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\EndReplacement;
|
||||
|
||||
use App\Scolarite\Domain\Model\TeacherReplacement\TeacherReplacementId;
|
||||
use App\Scolarite\Domain\Repository\TeacherReplacementRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class EndReplacementHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TeacherReplacementRepository $replacementRepository,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EndReplacementCommand $command): void
|
||||
{
|
||||
$replacement = $this->replacementRepository->get(
|
||||
TeacherReplacementId::fromString($command->replacementId),
|
||||
TenantId::fromString($command->tenantId),
|
||||
);
|
||||
|
||||
$replacement->terminer($this->clock->now());
|
||||
$this->replacementRepository->save($replacement);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user