From 86f25196f15a1b4c4875df9d0b804dab9287be24 Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Fri, 5 Jul 2024 08:48:31 +0000 Subject: [PATCH] chore: Bumped --- LICENSE.md | 2 +- composer.json | 22 ++++------ config/api_resources/user.yaml | 8 ++-- phpstan.neon | 6 +-- src/Api/Dto/UserOutput.php | 19 +-------- .../PurgeUserValidationTokenCommand.php | 5 ++- src/Entity/UserValidationToken.php | 1 + .../UserSignedUpSubscriber.php | 5 ++- src/Manager/UserMetadataManager.php | 8 +++- src/Manager/UserValidationTokenManager.php | 41 ++++++++++++++----- src/State/UserPasswordRequestProcessor.php | 2 +- src/State/UserPasswordResetProcessor.php | 2 +- src/State/UserSignupProcessor.php | 4 +- src/State/UserTokenProvider.php | 8 ++-- src/State/UserValidationRequestProcessor.php | 4 +- src/State/UserValidationTokenProcessor.php | 4 +- 16 files changed, 75 insertions(+), 66 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 8e18fa6..d4d8a00 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright © 2024 Ambroise Maupate +Copyright © 2023 Ambroise Maupate Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/composer.json b/composer.json index 2c0a650..2bdfc3e 100644 --- a/composer.json +++ b/composer.json @@ -17,26 +17,20 @@ } ], "type": "symfony-bundle", - "minimum-stability": "dev", "prefer-stable": true, "require": { "php": ">=8.1", - "api-platform/core": "~3.2.14", - "roadiz/core-bundle": "2.3.*", - "symfony/framework-bundle": "6.4.*", - "symfony/rate-limiter": "6.4.*", - "symfony/lock": "6.4.*", - "doctrine/orm": "~2.19.0" + "api-platform/core": "~2.7.0", + "symfony/framework-bundle": "5.4.*", + "symfony/rate-limiter": "5.4.*", + "doctrine/orm": "~2.17.0" }, "require-dev": { + "roadiz/core-bundle": "2.2.*", "php-coveralls/php-coveralls": "^2.4", "phpstan/phpstan": "^1.5.3", "squizlabs/php_codesniffer": "^3.5", - "phpstan/phpstan-doctrine": "^1.3", - "roadiz/entity-generator": "2.3.*", - "roadiz/doc-generator": "2.3.*", - "roadiz/random": "2.3.*", - "roadiz/jwt": "2.3.*" + "phpstan/phpstan-doctrine": "^1.3" }, "config": { "optimize-autoloader": true, @@ -58,8 +52,8 @@ }, "extra": { "branch-alias": { - "dev-main": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-main": "2.2.x-dev", + "dev-develop": "2.3.x-dev" } } } diff --git a/config/api_resources/user.yaml b/config/api_resources/user.yaml index b848be7..288d582 100644 --- a/config/api_resources/user.yaml +++ b/config/api_resources/user.yaml @@ -89,14 +89,14 @@ RZ\Roadiz\CoreBundle\Entity\User: method: 'GET' security: "is_granted('ROLE_ACCESS_USERS') or object == user" normalizationContext: - groups: ['user', 'user_personal', 'user_security'] + groups: ['user', 'user_security'] enable_max_depth: true ApiPlatform\Metadata\GetCollection: method: 'GET' security: "is_granted('ROLE_ACCESS_USERS')" normalizationContext: - groups: [ 'user', 'user_personal' ] + groups: [ 'user' ] enable_max_depth: true # Current user information operation MUST be declared AFTER ApiPlatform\Metadata\Get @@ -106,11 +106,9 @@ RZ\Roadiz\CoreBundle\Entity\User: class: ApiPlatform\Metadata\Get # Path must be different from item operation to avoid conflict uriTemplate: '/me' + itemUriTemplate: /users/{id} provider: RZ\Roadiz\UserBundle\State\UserTokenProvider output: RZ\Roadiz\UserBundle\Api\Dto\UserOutput - normalizationContext: - groups: ['user', 'user_personal', 'user_security'] - enable_max_depth: true openapiContext: summary: Get current user (JWT) information description: | diff --git a/phpstan.neon b/phpstan.neon index 4bc7774..f312ced 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 5 paths: - src excludePaths: @@ -7,8 +7,6 @@ parameters: - */bower_components/* - */static/* ignoreErrors: - - identifier: missingType.iterableValue - - identifier: missingType.generics - '#Call to an undefined method RZ\\Roadiz\\CoreBundle\\Repository#' - '#Call to an undefined method RZ\\Roadiz\\UserBundle\\Repository#' - '#Call to an undefined method Doctrine\\Persistence\\ObjectRepository#' @@ -32,6 +30,8 @@ parameters: - '#does not accept Doctrine\\Common\\Collections\\ReadableCollection]+>#' reportUnmatchedIgnoredErrors: false + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false doctrine: repositoryClass: RZ\Roadiz\CoreBundle\Repository\EntityRepository includes: diff --git a/src/Api/Dto/UserOutput.php b/src/Api/Dto/UserOutput.php index 7ba5b93..dd16e8e 100644 --- a/src/Api/Dto/UserOutput.php +++ b/src/Api/Dto/UserOutput.php @@ -4,38 +4,21 @@ namespace RZ\Roadiz\UserBundle\Api\Dto; -use ApiPlatform\Metadata\ApiResource; -use Symfony\Component\Serializer\Attribute\Groups; +use ApiPlatform\Metadata\ApiProperty; -#[ApiResource( - operations: [], -)] final class UserOutput { - #[Groups(['user'])] public string $identifier = ''; - #[Groups(['user'])] public array $roles = []; - #[Groups(['user'])] public ?string $firstName = null; - #[Groups(['user'])] public ?string $publicName = null; - #[Groups(['user'])] public ?string $lastName = null; - #[Groups(['user'])] public ?string $phone = null; - #[Groups(['user'])] public ?string $company = null; - #[Groups(['user'])] public ?string $locale = null; - #[Groups(['user'])] public ?string $pictureUrl = null; - #[Groups(['user'])] public ?array $metadata = null; - #[Groups(['user'])] public ?string $job = null; - #[Groups(['user'])] public ?\DateTime $birthday = null; - #[Groups(['user'])] public bool $emailValidated = false; } diff --git a/src/Console/PurgeUserValidationTokenCommand.php b/src/Console/PurgeUserValidationTokenCommand.php index 9dd0140..2996d9c 100644 --- a/src/Console/PurgeUserValidationTokenCommand.php +++ b/src/Console/PurgeUserValidationTokenCommand.php @@ -13,9 +13,12 @@ final class PurgeUserValidationTokenCommand extends Command { - public function __construct(private readonly ManagerRegistry $managerRegistry, string $name = null) + private ManagerRegistry $managerRegistry; + + public function __construct(ManagerRegistry $managerRegistry, string $name = null) { parent::__construct($name); + $this->managerRegistry = $managerRegistry; } protected function configure(): void diff --git a/src/Entity/UserValidationToken.php b/src/Entity/UserValidationToken.php index 87bf734..5f06756 100644 --- a/src/Entity/UserValidationToken.php +++ b/src/Entity/UserValidationToken.php @@ -5,6 +5,7 @@ namespace RZ\Roadiz\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use RZ\Roadiz\CoreBundle\Entity\User; use RZ\Roadiz\UserBundle\Repository\UserValidationTokenRepository; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; diff --git a/src/EventSubscriber/UserSignedUpSubscriber.php b/src/EventSubscriber/UserSignedUpSubscriber.php index 4e72bc0..06813a0 100644 --- a/src/EventSubscriber/UserSignedUpSubscriber.php +++ b/src/EventSubscriber/UserSignedUpSubscriber.php @@ -10,9 +10,12 @@ final class UserSignedUpSubscriber implements EventSubscriberInterface { + private UserValidationTokenManagerInterface $userValidationTokenManager; + public function __construct( - private readonly UserValidationTokenManagerInterface $userValidationTokenManager + UserValidationTokenManagerInterface $userValidationTokenManager ) { + $this->userValidationTokenManager = $userValidationTokenManager; } /** diff --git a/src/Manager/UserMetadataManager.php b/src/Manager/UserMetadataManager.php index fe6609d..f2628c6 100644 --- a/src/Manager/UserMetadataManager.php +++ b/src/Manager/UserMetadataManager.php @@ -10,8 +10,14 @@ class UserMetadataManager implements UserMetadataManagerInterface { - public function __construct(private readonly ManagerRegistry $managerRegistry) + private ManagerRegistry $managerRegistry; + + /** + * @param ManagerRegistry $managerRegistry + */ + public function __construct(ManagerRegistry $managerRegistry) { + $this->managerRegistry = $managerRegistry; } public function getMetadataForUser(User $user): ?UserMetadata diff --git a/src/Manager/UserValidationTokenManager.php b/src/Manager/UserValidationTokenManager.php index 08f3adc..2f79bef 100644 --- a/src/Manager/UserValidationTokenManager.php +++ b/src/Manager/UserValidationTokenManager.php @@ -20,18 +20,39 @@ final class UserValidationTokenManager implements UserValidationTokenManagerInterface { + private ManagerRegistry $managerRegistry; + private UrlGeneratorInterface $urlGenerator; + private TranslatorInterface $translator; + private LoggerInterface $logger; + private EmailManager $emailManager; + private Settings $settingsBag; + private RoleHierarchyInterface $roleHierarchy; + private string $emailValidatedRoleName; + private int $userValidationExpiresIn; + private string $userValidationUrl; + public function __construct( - private readonly ManagerRegistry $managerRegistry, - private readonly UrlGeneratorInterface $urlGenerator, - private readonly TranslatorInterface $translator, - private readonly LoggerInterface $logger, - private readonly EmailManager $emailManager, - private readonly Settings $settingsBag, - private readonly RoleHierarchyInterface $roleHierarchy, - private readonly string $emailValidatedRoleName, - private readonly int $userValidationExpiresIn, - private readonly string $userValidationUrl + ManagerRegistry $managerRegistry, + UrlGeneratorInterface $urlGenerator, + TranslatorInterface $translator, + LoggerInterface $logger, + EmailManager $emailManager, + Settings $settingsBag, + RoleHierarchyInterface $roleHierarchy, + string $emailValidatedRoleName, + int $userValidationExpiresIn, + string $userValidationUrl ) { + $this->managerRegistry = $managerRegistry; + $this->logger = $logger; + $this->userValidationExpiresIn = $userValidationExpiresIn; + $this->emailManager = $emailManager; + $this->userValidationUrl = $userValidationUrl; + $this->settingsBag = $settingsBag; + $this->urlGenerator = $urlGenerator; + $this->translator = $translator; + $this->roleHierarchy = $roleHierarchy; + $this->emailValidatedRoleName = $emailValidatedRoleName; } public function createForUser(UserInterface $user): UserValidationToken diff --git a/src/State/UserPasswordRequestProcessor.php b/src/State/UserPasswordRequestProcessor.php index 34df59e..062fc9c 100644 --- a/src/State/UserPasswordRequestProcessor.php +++ b/src/State/UserPasswordRequestProcessor.php @@ -59,7 +59,7 @@ protected function getRecaptchaHeaderName(): string return $this->recaptchaHeaderName; } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput { if (!$data instanceof UserPasswordRequestInput) { throw new \RuntimeException(sprintf('Cannot process %s', get_class($data))); diff --git a/src/State/UserPasswordResetProcessor.php b/src/State/UserPasswordResetProcessor.php index 350c0d9..beb3667 100644 --- a/src/State/UserPasswordResetProcessor.php +++ b/src/State/UserPasswordResetProcessor.php @@ -31,7 +31,7 @@ public function __construct( ) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput { if (!$data instanceof UserPasswordTokenInput) { throw new \RuntimeException(sprintf('Cannot process %s', get_class($data))); diff --git a/src/State/UserSignupProcessor.php b/src/State/UserSignupProcessor.php index b13988a..711add6 100644 --- a/src/State/UserSignupProcessor.php +++ b/src/State/UserSignupProcessor.php @@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; use Symfony\Component\RateLimiter\RateLimiterFactory; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; final class UserSignupProcessor implements ProcessorInterface @@ -51,7 +51,7 @@ protected function getRecaptchaHeaderName(): string return $this->recaptchaHeaderName; } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput { if (!$data instanceof UserInput) { throw new BadRequestHttpException(sprintf('Cannot process %s', get_class($data))); diff --git a/src/State/UserTokenProvider.php b/src/State/UserTokenProvider.php index 14e3ccd..d4a157d 100644 --- a/src/State/UserTokenProvider.php +++ b/src/State/UserTokenProvider.php @@ -12,15 +12,15 @@ use RZ\Roadiz\UserBundle\Manager\UserMetadataManagerInterface; use RZ\Roadiz\UserBundle\Manager\UserValidationTokenManagerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\User\UserInterface; final class UserTokenProvider implements ProviderInterface { public function __construct( - private readonly Security $security, - private readonly UserValidationTokenManagerInterface $userValidationTokenManager, - private readonly UserMetadataManagerInterface $userMetadataManager, + private Security $security, + private UserValidationTokenManagerInterface $userValidationTokenManager, + private UserMetadataManagerInterface $userMetadataManager, ) { } diff --git a/src/State/UserValidationRequestProcessor.php b/src/State/UserValidationRequestProcessor.php index e8c1b09..46c066f 100644 --- a/src/State/UserValidationRequestProcessor.php +++ b/src/State/UserValidationRequestProcessor.php @@ -14,7 +14,7 @@ use RZ\Roadiz\UserBundle\Manager\UserValidationTokenManagerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; final class UserValidationRequestProcessor implements ProcessorInterface { @@ -27,7 +27,7 @@ public function __construct( ) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput { if (!$data instanceof UserValidationRequestInput) { throw new \RuntimeException(sprintf('Cannot process %s', get_class($data))); diff --git a/src/State/UserValidationTokenProcessor.php b/src/State/UserValidationTokenProcessor.php index 72e2a85..e32a7ab 100644 --- a/src/State/UserValidationTokenProcessor.php +++ b/src/State/UserValidationTokenProcessor.php @@ -15,7 +15,7 @@ use RZ\Roadiz\UserBundle\Event\UserEmailValidated; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; -use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\Security\Core\Security; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; final class UserValidationTokenProcessor implements ProcessorInterface @@ -29,7 +29,7 @@ public function __construct( ) { } - public function process($data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): VoidOutput { if (!$data instanceof UserValidationTokenInput) { throw new \RuntimeException(sprintf('Cannot process %s', get_class($data)));