Skip to content

Commit

Permalink
Merge pull request #80 from BitBagCommerce/release/20230602
Browse files Browse the repository at this point in the history
Release 20230602
  • Loading branch information
senghe authored Jun 6, 2023
2 parents 6ceac78 + aa61b42 commit 8bfa0b3
Show file tree
Hide file tree
Showing 33 changed files with 503 additions and 142 deletions.
15 changes: 12 additions & 3 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
```yml
bitbag_sylius_vue_storefront2:
refresh_token_lifespan: 2592000 #that its default value
test_endpoint: 'http://127.0.0.1:8080/api/v2/graphql' #that its default value
```
![Step6](/doc/images/Step6.png)
Expand Down Expand Up @@ -176,15 +175,25 @@ security:
![Step11](/doc/images/Step11.png)
4Add redirection to your `.env` file:
14. Add redirection to your `.env` file:
```env
VSF2_HOST= #your VueStoreFront url address
```
![Step12](/doc/images/Step12.png)
15. Add JWT token and refresh token TTL's to your `.env` file:
```env
APP_TOKEN_TTL=3600
APP_REFRESH_TOKEN_TTL="+1 week"
APP_REFRESH_TOKEN_EXTENDED_TTL="+3 month"
```
14. After all steps, run this commends in your project directory:
16. After all steps, run this commends in your project directory:
```bash
yarn install
Expand Down
86 changes: 0 additions & 86 deletions spec/DataProvider/TaxonCollectionDataProviderSpec.php

This file was deleted.

7 changes: 4 additions & 3 deletions spec/Factory/ShopUserTokenFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace spec\BitBag\SyliusVueStorefront2Plugin\Factory;

use BitBag\SyliusVueStorefront2Plugin\Factory\ShopUserTokenFactory;
use BitBag\SyliusVueStorefront2Plugin\Model\RefreshTokenInterface;
use BitBag\SyliusVueStorefront2Plugin\Model\ShopUserToken;
use Doctrine\ORM\EntityManagerInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use PhpSpec\ObjectBehavior;
Expand All @@ -27,7 +27,7 @@ public function let(
JWTTokenManagerInterface $jwtManager,
RefreshTokenManagerInterface $refreshJwtManager,
): void {
$this->beConstructedWith($entityManager, $jwtManager, $refreshJwtManager);
$this->beConstructedWith($entityManager, $jwtManager, $refreshJwtManager, '+5 second', '+3 month');
}

public function it_is_initializable(): void
Expand Down Expand Up @@ -68,6 +68,7 @@ public function it_gets_refresh_token(
$username = 'canonical';
$user->getUsernameCanonical()->willReturn($username);
$refreshToken->setUsername($username)->shouldBeCalled();
$refreshToken->setRememberMe(true)->shouldBeCalled();

$refreshToken->setRefreshToken()->shouldBeCalled();

Expand All @@ -76,6 +77,6 @@ public function it_gets_refresh_token(
$entityManager->persist($refreshToken)->shouldBeCalled();
$entityManager->flush()->shouldBeCalled();

$this->getRefreshToken($user)->shouldReturn($refreshToken);
$this->getRefreshToken($user, true)->shouldReturn($refreshToken);
}
}
10 changes: 7 additions & 3 deletions spec/Resolver/Mutation/LoginResolverSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace spec\BitBag\SyliusVueStorefront2Plugin\Resolver\Mutation;

use BitBag\SyliusVueStorefront2Plugin\Factory\ShopUserTokenFactoryInterface;
use BitBag\SyliusVueStorefront2Plugin\Model\RefreshTokenInterface;
use BitBag\SyliusVueStorefront2Plugin\Model\ShopUserTokenInterface;
use BitBag\SyliusVueStorefront2Plugin\Resolver\Mutation\LoginResolver;
use Doctrine\ORM\EntityManagerInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Channel\Context\ChannelContextInterface;
Expand Down Expand Up @@ -70,13 +70,15 @@ public function it_is_invokable(
'input' => [
'username' => 'username',
'password' => 'somepass',
'rememberMe' => true,
],
],
];

$input = $context['args']['input'];
$username = (string) $input['username'];
$password = (string) $input['password'];
$rememberMe = (bool) $input['rememberMe'];

$userRepository->findOneBy(['username' => $username])->willReturn($user);
$encoderFactory->getEncoder($user)->willReturn($encoder);
Expand All @@ -93,7 +95,7 @@ public function it_is_invokable(

$encoder->isPasswordValid($userPassword, $password, $userSalt)->shouldBeCalled()->willReturn(true);

$tokenFactory->getRefreshToken($user)->willReturn($refreshToken);
$tokenFactory->getRefreshToken($user, $rememberMe)->willReturn($refreshToken);
$tokenFactory->create($user, $refreshToken)->willReturn($shopUserToken);

$eventDispatcher->dispatch(Argument::any(), LoginResolver::EVENT_NAME)->shouldBeCalled();
Expand Down Expand Up @@ -223,13 +225,15 @@ public function it_doesnt_throw_exception_when_logging_in_unverified_user_but_ch
'input' => [
'username' => 'username',
'password' => 'somepass',
'rememberMe' => true,
],
],
];

$input = $context['args']['input'];
$username = (string) $input['username'];
$password = (string) $input['password'];
$rememberMe = (bool) $input['rememberMe'];

$userRepository->findOneBy(['username' => $username])->willReturn($user);
$encoderFactory->getEncoder($user)->willReturn($encoder);
Expand All @@ -246,7 +250,7 @@ public function it_doesnt_throw_exception_when_logging_in_unverified_user_but_ch

$encoder->isPasswordValid($userPassword, $password, $userSalt)->shouldBeCalled()->willReturn(true);

$tokenFactory->getRefreshToken($user)->willReturn($refreshToken);
$tokenFactory->getRefreshToken($user, $rememberMe)->willReturn($refreshToken);
$tokenFactory->create($user, $refreshToken)->willReturn($shopUserToken);

$eventDispatcher->dispatch(Argument::any(), LoginResolver::EVENT_NAME)->shouldBeCalled();
Expand Down
10 changes: 6 additions & 4 deletions spec/Resolver/Mutation/RefreshTokenResolverSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace spec\BitBag\SyliusVueStorefront2Plugin\Resolver\Mutation;

use BitBag\SyliusVueStorefront2Plugin\Factory\ShopUserTokenFactoryInterface;
use BitBag\SyliusVueStorefront2Plugin\Model\RefreshToken;
use BitBag\SyliusVueStorefront2Plugin\Model\RefreshTokenInterface;
use BitBag\SyliusVueStorefront2Plugin\Model\ShopUserTokenInterface;
use BitBag\SyliusVueStorefront2Plugin\Resolver\Mutation\RefreshTokenResolver;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\ShopUserInterface;
Expand All @@ -34,13 +34,15 @@ public function let(
EventDispatcherInterface $eventDispatcher,
): void {
$entityManager->getRepository(RefreshToken::class)->willReturn($refreshTokenRepository);
$lifespan = '2592000';
$refreshTokenTTL = '+1 week';
$refreshTokenExtendedTTL = '+3 month';
$this->beConstructedWith(
$entityManager,
$tokenFactory,
$userRepository,
$eventDispatcher,
$lifespan,
$refreshTokenTTL,
$refreshTokenExtendedTTL,
);
}

Expand Down
85 changes: 85 additions & 0 deletions spec/Serializer/TaxonNormalizerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusVueStorefront2Plugin\Serializer;

use BitBag\SyliusVueStorefront2Plugin\Serializer\TaxonNormalizer;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ApiBundle\Serializer\ContextKeys;
use Sylius\Component\Core\Model\Taxon;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface;

final class TaxonNormalizerSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(TaxonNormalizer::class);
}

public function it_normalizes_taxon(
TaxonInterface $taxon,
TaxonInterface $taxonParent,
TaxonTranslationInterface $translation,
): void {
$id = 111;
$parentId = 100;
$name = 'Test taxon name';
$code = 'test_taxon_code';
$position = 1;
$slug = 'test_taxon_slug';
$description = 'Test taxon description';
$enabled = true;
$level = 1;

$context = [
ContextKeys::LOCALE_CODE => 'en_US',
];

$locale = $context[ContextKeys::LOCALE_CODE];
$taxon->getTranslation($locale)->willReturn($translation);

$taxon->getId()->willReturn($id);
$translation->getName()->willReturn($name);
$taxon->getName()->willReturn($name);
$taxon->getCode()->willReturn($code);
$taxon->getPosition()->willReturn($position);
$translation->getSlug()->willReturn($slug);
$taxon->getSlug()->willReturn($slug);
$translation->getDescription()->willReturn($description);
$taxon->getDescription()->willReturn($description);
$taxon->getParent()->willReturn($taxonParent);
$taxon->isEnabled()->willReturn($enabled);
$taxon->getLevel()->willReturn($level);
$taxon->getTranslation()->willReturn($translation);
$taxonParent->getId()->willReturn($parentId);

$result = [
'id' => $id,
'name' => $name,
'code' => $code,
'position' => $position,
'slug' => $slug,
'description' => $description,
'parent' => [
'id' => $parentId,
],
'enabled' => $enabled,
'level' => $level,
];

$this->normalize($taxon, null, $context)->shouldReturn($result);
}

public function it_checks_if_it_supports_normalization(Taxon $taxon): void
{
$this->supportsNormalization($taxon)->shouldReturn(true);
}
}
10 changes: 4 additions & 6 deletions src/DataProvider/TaxonCollectionDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ public function getCollection(string $resourceClass, string $operationName = nul
$channelMenuTaxon = $channelContext->getMenuTaxon();

$user = $this->userContext->getUser();
if ($this->isUserAllowedToGetAllTaxa($user)) {
return $this->taxonRepository->findAll();
if ($this->hasAccessToAllTaxa($user)) {
$channelMenuTaxon = null;
}

$queryBuilder = $this->taxonRepository->createChildrenByChannelMenuTaxonQueryBuilder(
$channelMenuTaxon,
);
$queryBuilder = $this->taxonRepository->createChildrenByParentQueryBuilder($channelMenuTaxon);

/** @var QueryCollectionExtensionInterface $extension */
foreach ($this->collectionExtensions as $extension) {
Expand All @@ -95,7 +93,7 @@ public function getCollection(string $resourceClass, string $operationName = nul
);
}

private function isUserAllowedToGetAllTaxa(?UserInterface $user): bool
private function hasAccessToAllTaxa(?UserInterface $user): bool
{
/** @psalm-suppress DeprecatedClass */
return $user !== null && in_array('ROLE_API_ACCESS', $user->getRoles(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function load(array $configs, ContainerBuilder $container): void

$loader->load('services.xml');

$container->setParameter('bitbag_sylius_vue_storefront2.refresh_token_lifespan', $config['refresh_token_lifespan']);
$container->setParameter('bitbag_sylius_vue_storefront2.test_endpoint', $config['test_endpoint']);
}

Expand Down
1 change: 0 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode
->addDefaultsIfNotSet()
->children()
->integerNode('refresh_token_lifespan')->defaultValue(2592000)->end()
->scalarNode('test_endpoint')->defaultValue('http://127.0.0.1:8080/api/v2/graphql')->cannotBeEmpty()->end()
->end()
->end()
Expand Down
Loading

0 comments on commit 8bfa0b3

Please sign in to comment.