Skip to content

Commit

Permalink
UPGRADE file updated and review changes
Browse files Browse the repository at this point in the history
UPGRADE file updated and review changes

fix services
  • Loading branch information
ernestWarwas committed Sep 15, 2022
1 parent 530e68e commit 5d9ad1e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
36 changes: 36 additions & 0 deletions UPGRADE-1.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions src/Sylius/Bundle/ApiBundle/Context/TokenBasedUserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ public function __construct(private TokenStorageInterface $tokenStorage)

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
) {
}

public function onSuccessLogin(LoginSuccessEvent $loginSuccessEvent): void
public function onLoginSuccess(LoginSuccessEvent $loginSuccessEvent): void
{
if (!$this->uriBasedSectionContext->getSection() instanceof ShopApiOrdersSubSection) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function it_throws_an_exception_when_cart_does_not_implement_core_order_interfac

$this
->shouldThrow(UnexpectedTypeException::class)
->during('onSuccessLogin', [
->during('onLoginSuccess', [
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand Down Expand Up @@ -106,7 +106,7 @@ function it_blames_cart_on_user_on_interactive_login(
->willReturn(new Envelope($blameCart))
;

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand Down Expand Up @@ -135,7 +135,7 @@ function it_does_nothing_if_given_cart_has_been_blamed_in_past(

$cart->setCustomer(Argument::any())->shouldNotBeCalled();

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand Down Expand Up @@ -163,7 +163,7 @@ function it_does_nothing_if_given_user_is_invalid_on_interactive_login(

$cart->setCustomer(Argument::any())->shouldNotBeCalled();

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand All @@ -189,7 +189,7 @@ function it_does_nothing_if_there_is_no_existing_cart_on_interactive_login(
$cartContext->getCart()->willThrow(CartNotFoundException::class);
$token->getUser()->willReturn($user);

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand All @@ -215,7 +215,7 @@ function it_does_nothing_if_the_current_section_is_not_shop_on_interactive_login
$token->getUser()->shouldNotBeCalled();
$cartContext->getCart()->shouldNotBeCalled();

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand All @@ -241,7 +241,7 @@ function it_does_nothing_if_the_current_section_is_not_orders_subsection(
$token->getUser()->shouldNotBeCalled();
$cartContext->getCart()->shouldNotBeCalled();

$this->onSuccessLogin(
$this->onLoginSuccess(
new LoginSuccessEvent(
$authenticator->getWrappedObject(),
$passport->getWrappedObject(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ public function validate($value, Constraint $constraint): void
/** @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;
}
}
Expand All @@ -56,8 +55,10 @@ public function validate($value, Constraint $constraint): void
}
}

private function getAuthenticatedUserEmail(?TokenInterface $token): ?string
private function getAuthenticatedUserEmail(): ?string
{
$token = $this->tokenStorage->getToken();

if (null === $token) {
return null;
}
Expand Down

0 comments on commit 5d9ad1e

Please sign in to comment.