mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
bugfix #15251 Fix error with being unable to add product review while being logged in using remember me (TheMilek)
This PR was merged into the 1.12 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.12 <!-- see the comment below --> | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no <!-- don't forget to update the UPGRADE-*.md file --> | | Related tickets | fixes https://github.com/Sylius/Sylius/issues/14898 and https://github.com/Sylius/Sylius/issues/9430 | | License | MIT | <!-- - Bug fixes must be submitted against the 1.12 branch - Features and deprecations must be submitted against the 1.13 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> As being said [here](https://github.com/Sylius/Sylius/issues/14898) we were checking access against `IS_AUTHENTICATED_FULLY` while creating product review and it leads to a problem, that prevents us from creating review while using remember me functionality:  By changing it to `IS_AUTHENTICATED_REMEMBERED` resolves the bug Commits ------- Fix error with being unable to add product review when the user is logged in by remember me option
This commit is contained in:
commit
290029bff5
5 changed files with 54 additions and 3 deletions
|
|
@ -7,12 +7,21 @@ Feature: Adding product review as a customer
|
|||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And the store has a product "Necronomicon"
|
||||
And I am a logged in customer
|
||||
|
||||
@ui @api
|
||||
Scenario: Adding product reviews as a logged in customer
|
||||
Given I am a logged in customer
|
||||
When I want to review product "Necronomicon"
|
||||
And I leave a comment "Great book for every advanced sorcerer.", titled "Scary but astonishing"
|
||||
And I rate it with 5 points
|
||||
And I add it
|
||||
Then I should be notified that my review is waiting for the acceptation
|
||||
|
||||
@ui
|
||||
Scenario: Adding product reviews as a logged in customer with remember me option
|
||||
Given I am a logged in customer by using remember me option
|
||||
When I want to review product "Necronomicon"
|
||||
And I leave a comment "Great book for every advanced sorcerer.", titled "Scary but astonishing"
|
||||
And I rate it with 3 points
|
||||
And I add it
|
||||
Then I should be notified that my review is waiting for the acceptation
|
||||
|
|
|
|||
|
|
@ -67,4 +67,17 @@ final class ShopSecurityContext implements Context
|
|||
|
||||
$this->sharedStorage->set('user', $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I am a logged in customer by using remember me option
|
||||
*/
|
||||
public function iAmLoggedInCustomerByUsingRememberMeOption(): void
|
||||
{
|
||||
$userData = ['email' => 'sylius@example.com', 'password' => 'sylius', 'enabled' => true];
|
||||
|
||||
$user = $this->userFactory->create($userData);
|
||||
$this->userRepository->add($user);
|
||||
|
||||
$this->securityService->logInWithRememberMe($user);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Behat\Service;
|
||||
|
||||
use Sylius\Component\User\Model\UserInterface;
|
||||
|
||||
interface RememberMeAwareSecurityServiceInterface extends SecurityServiceInterface
|
||||
{
|
||||
public function logInWithRememberMe(UserInterface $user): void;
|
||||
}
|
||||
|
|
@ -19,11 +19,12 @@ use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
|
||||
|
||||
final class SecurityService implements SecurityServiceInterface
|
||||
final class SecurityService implements RememberMeAwareSecurityServiceInterface
|
||||
{
|
||||
private string $sessionTokenVariable;
|
||||
|
||||
|
|
@ -48,6 +49,13 @@ final class SecurityService implements SecurityServiceInterface
|
|||
$this->setToken($token);
|
||||
}
|
||||
|
||||
public function logInWithRememberMe(UserInterface $user): void
|
||||
{
|
||||
$token = new RememberMeToken($user, $this->firewallContextName, 'secret');
|
||||
|
||||
$this->setToken($token);
|
||||
}
|
||||
|
||||
public function logOut(): void
|
||||
{
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
{{ form_widget(form.comment, sylius_test_form_attribute('comment')|sylius_merge_recursive( {'attr': {'placeholder': 'sylius.ui.write_your_own_review'|trans}})) }}
|
||||
{{ form_errors(form.comment) }}
|
||||
</div>
|
||||
{% if not is_granted("IS_AUTHENTICATED_FULLY") %}
|
||||
{% if not is_granted("IS_AUTHENTICATED_REMEMBERED") %}
|
||||
<div class="field">
|
||||
{{ form_widget(form.author.email, sylius_test_form_attribute('author-email')|sylius_merge_recursive( {'attr': {'placeholder': 'sylius.ui.email'|trans}})) }}
|
||||
{{ form_errors(form.author.email) }}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue