*/ final readonly class ImageRightsItemProvider implements ProviderInterface { public function __construct( private UserRepository $userRepository, private TenantContext $tenantContext, private AuthorizationCheckerInterface $authorizationChecker, ) { } #[Override] public function provide(Operation $operation, array $uriVariables = [], array $context = []): ImageRightsResource { if (!$this->tenantContext->hasTenant()) { throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.'); } if (!$this->authorizationChecker->isGranted(ImageRightsVoter::EDIT)) { throw new AccessDeniedHttpException('Vous n\'êtes pas autorisé à modifier les droits à l\'image.'); } /** @var string|null $studentId */ $studentId = $uriVariables['id'] ?? null; if ($studentId === null) { throw new NotFoundHttpException('Élève non trouvé.'); } try { $user = $this->userRepository->get(UserId::fromString($studentId)); } catch (UserNotFoundException|InvalidUuidStringException) { throw new NotFoundHttpException('Élève non trouvé.'); } if ((string) $user->tenantId !== (string) $this->tenantContext->getCurrentTenantId()) { throw new NotFoundHttpException('Élève non trouvé.'); } $resource = new ImageRightsResource(); $resource->id = (string) $user->id; $resource->firstName = $user->firstName; $resource->lastName = $user->lastName; $resource->email = (string) $user->email; $resource->imageRightsStatus = $user->imageRightsStatus->value; $resource->imageRightsStatusLabel = $user->imageRightsStatus->label(); $resource->imageRightsUpdatedAt = $user->imageRightsUpdatedAt; return $resource; } }