UPGRADE file updated and review changes

UPGRADE file updated and review changes

fix services
This commit is contained in:
Ernest Warwas 2022-09-15 11:53:29 +02:00
parent 530e68ea3b
commit 5d9ad1efad
No known key found for this signature in database
GPG key ID: 53E6A337C5C09665
6 changed files with 52 additions and 24 deletions

View file

@ -38,6 +38,42 @@ with test or remove these services with complier pass.
7. The `Sylius\Component\Promotion\Event\CatalogPromotionFailed` has been removed as it is not used anymore.
8. Due to updating to Symfony 6 security file was changed to use the updated security system so you need to adjust your `config/packages/security.yaml` file:
```diff
security:
- always_authenticate_before_granting: true
+ enable_authenticator_manager: true
```
and you need to adjust all of your firewalls like that:
```diff
admin:
# ...
form_login:
# ...
- csrf_token_generator: security.csrf.token_manager
+ enable_csrf: true
# ...
new_api_admin_user:
# ...
- anonymous: true
+ entry_point: jwt
# ...
- guard:
# ...
+ jwt: true
```
and also you need to adjust all of your access_control like that:
```diff
- - { path: "%sylius.security.admin_regex%/forgotten-password", role: IS_AUTHENTICATED_ANONYMOUSLY }
+ - { path: "%sylius.security.admin_regex%/forgotten-password", role: PUBLIC_ACCESS }
```
### Asset management changes
We updated gulp-sass plugin as well as the sass implementation we use to be compatible with most installation

View file

@ -25,18 +25,9 @@ final class TokenBasedUserContext implements UserContextInterface
public function getUser(): ?UserInterface
{
$token = $this->tokenStorage->getToken();
if ($token === null) {
return null;
}
/** @var UserInterface|null $user */
$user = $this->tokenStorage->getToken()?->getUser();
/** @var UserInterface|string|null $user */
$user = $token->getUser();
if (is_string($user) || null === $user) {
return null;
}
return $user;
return $user instanceof UserInterface ? $user : null;
}
}

View file

@ -35,7 +35,7 @@ final class ApiCartBlamerListener
) {
}
public function onSuccessLogin(LoginSuccessEvent $loginSuccessEvent): void
public function onLoginSuccess(LoginSuccessEvent $loginSuccessEvent): void
{
if (!$this->uriBasedSectionContext->getSection() instanceof ShopApiOrdersSubSection) {
return;

View file

@ -117,7 +117,7 @@
<argument type="service" id="sylius.context.cart" />
<argument type="service" id="sylius.section_resolver.uri_based_section_resolver" />
<argument type="service" id="sylius.command_bus" />
<tag name="kernel.event_listener" event="Symfony\Component\Security\Http\Event\LoginSuccessEvent" method="onSuccessLogin" />
<tag name="kernel.event_listener" event="Symfony\Component\Security\Http\Event\LoginSuccessEvent" method="onLoginSuccess" />
</service>
<service id="sylius.listener.api_authentication_success_listener" class="Sylius\Bundle\ApiBundle\EventListener\AuthenticationSuccessListener">

View file

@ -63,7 +63,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$this
->shouldThrow(UnexpectedTypeException::class)
->during('onSuccessLogin', [
->during('onLoginSuccess', [
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -106,7 +106,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
->willReturn(new Envelope($blameCart))
;
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -135,7 +135,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$cart->setCustomer(Argument::any())->shouldNotBeCalled();
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -163,7 +163,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$cart->setCustomer(Argument::any())->shouldNotBeCalled();
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -189,7 +189,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$cartContext->getCart()->willThrow(CartNotFoundException::class);
$token->getUser()->willReturn($user);
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -215,7 +215,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$token->getUser()->shouldNotBeCalled();
$cartContext->getCart()->shouldNotBeCalled();
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
@ -241,7 +241,7 @@ final class ApiCartBlamerListenerSpec extends ObjectBehavior
$token->getUser()->shouldNotBeCalled();
$cartContext->getCart()->shouldNotBeCalled();
$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),

View file

@ -40,13 +40,12 @@ class UniqueReviewerEmailValidator extends ConstraintValidator
/** @var ReviewerInterface|null $customer */
$customer = $value->getAuthor();
$token = $this->tokenStorage->getToken();
if (null !== $customer) {
if (null === $customer->getEmail()) {
return;
}
if ($customer->getEmail() === $this->getAuthenticatedUserEmail($token)) {
if ($customer->getEmail() === $this->getAuthenticatedUserEmail()) {
return;
}
}
@ -56,8 +55,10 @@ class UniqueReviewerEmailValidator extends ConstraintValidator
}
}
private function getAuthenticatedUserEmail(?TokenInterface $token): ?string
private function getAuthenticatedUserEmail(): ?string
{
$token = $this->tokenStorage->getToken();
if (null === $token) {
return null;
}