diff --git a/features/admin/user/managing_users/changing_shop_user_password.feature b/features/admin/user/managing_users/changing_shop_user_password.feature index 603bfde0dc..b05422d149 100644 --- a/features/admin/user/managing_users/changing_shop_user_password.feature +++ b/features/admin/user/managing_users/changing_shop_user_password.feature @@ -9,7 +9,7 @@ Feature: Changing shop user's password And there is a user "kibsoon@example.com" identified by "goodGuy" And I am logged in as an administrator - @todo-api @ui + @api @ui Scenario: Changing a password of a shop user When I change the password of user "kibsoon@example.com" to "veryGoodGuy" Then I should be notified that it has been successfully edited diff --git a/src/Sylius/Behat/Context/Setup/UserContext.php b/src/Sylius/Behat/Context/Setup/UserContext.php index ff1c822294..485e8ee24c 100644 --- a/src/Sylius/Behat/Context/Setup/UserContext.php +++ b/src/Sylius/Behat/Context/Setup/UserContext.php @@ -23,7 +23,7 @@ use Sylius\Component\User\Model\UserInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; use Symfony\Component\Messenger\MessageBusInterface; -final class UserContext implements Context +final readonly class UserContext implements Context { public function __construct( private SharedStorageInterface $sharedStorage, @@ -40,8 +40,9 @@ final class UserContext implements Context * @Given there was account of :email with password :password * @Given there is a user :email */ - public function thereIsUserIdentifiedBy($email, $password = 'sylius') + public function thereIsUserIdentifiedBy(string $email, string $password = 'sylius'): void { + /** @var ShopUserInterface $user */ $user = $this->userFactory->create(['email' => $email, 'password' => $password, 'enabled' => true]); $this->sharedStorage->set('user', $user); @@ -68,7 +69,7 @@ final class UserContext implements Context * @Given the account of :email was deleted * @Given my account :email was deleted */ - public function accountWasDeleted($email) + public function accountWasDeleted(string $email) { /** @var ShopUserInterface $user */ $user = $this->userRepository->findOneByEmail($email); @@ -81,7 +82,7 @@ final class UserContext implements Context /** * @Given its account was deleted */ - public function hisAccountWasDeleted() + public function hisAccountWasDeleted(): void { $user = $this->sharedStorage->get('user'); @@ -93,7 +94,7 @@ final class UserContext implements Context * @Given /^(this user) is not verified$/ * @Given /^(I) have not verified my account (?:yet)$/ */ - public function accountIsNotVerified(UserInterface $user) + public function accountIsNotVerified(UserInterface $user): void { $user->setVerifiedAt(null); @@ -103,7 +104,7 @@ final class UserContext implements Context /** * @Given /^(?:(I) have|(this user) has) already received a verification email$/ */ - public function iHaveReceivedVerificationEmail(UserInterface $user) + public function iHaveReceivedVerificationEmail(UserInterface $user): void { $this->prepareUserVerification($user); } @@ -111,7 +112,7 @@ final class UserContext implements Context /** * @Given a verification email has already been sent to :email */ - public function aVerificationEmailHasBeenSentTo($email) + public function aVerificationEmailHasBeenSentTo(string $email): void { $user = $this->userRepository->findOneByEmail($email); @@ -121,7 +122,7 @@ final class UserContext implements Context /** * @Given /^(I) have already verified my account$/ */ - public function iHaveAlreadyVerifiedMyAccount(UserInterface $user) + public function iHaveAlreadyVerifiedMyAccount(UserInterface $user): void { $user->setVerifiedAt(new \DateTime()); @@ -136,7 +137,7 @@ final class UserContext implements Context $this->prepareUserPasswordResetToken($user); } - private function prepareUserVerification(UserInterface $user) + private function prepareUserVerification(UserInterface $user): void { $token = 'marryhadalittlelamb'; $this->sharedStorage->set('verification_token', $token); diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/Customer.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/Customer.xml index 87625bf667..28fb371b6d 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/Customer.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/admin/Customer.xml @@ -72,7 +72,12 @@ - + @@ -104,7 +109,12 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_processors.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_processors.xml index 76386b2e13..1e883cc97f 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_processors.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/state_processors.xml @@ -134,5 +134,11 @@ + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/StateProcessor/Admin/Customer/PersistProcessor.php b/src/Sylius/Bundle/ApiBundle/StateProcessor/Admin/Customer/PersistProcessor.php new file mode 100644 index 0000000000..7ebb2e0cdf --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/StateProcessor/Admin/Customer/PersistProcessor.php @@ -0,0 +1,46 @@ + */ +final readonly class PersistProcessor implements ProcessorInterface +{ + public function __construct( + private ProcessorInterface $persistProcessor, + private PasswordUpdaterInterface $passwordUpdater, + ) { + } + + public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + { + Assert::isInstanceOf($data, Customer::class); + Assert::notInstanceOf($operation, DeleteOperationInterface::class); + + if ($operation instanceof Put) { + $shopUser = $data->getUser(); + + $this->passwordUpdater->updatePassword($shopUser); + } + + return $this->persistProcessor->process($data, $operation, $uriVariables, $context); + } +}