From a9f60bad63a364de343a487d634651b555838c40 Mon Sep 17 00:00:00 2001 From: NghiaLe Date: Tue, 21 Jun 2022 17:17:27 +0700 Subject: [PATCH 1/9] Fix upgrade plugin eccube-api for ec-cube 4.2 --- ApiNav.php | 2 +- Bundle/ApiBundle.php | 6 ++-- Command/DumpSchemaCommand.php | 4 +-- Controller/Admin/GraphiQLController.php | 6 ++-- Controller/Admin/OAuthController.php | 32 ++++++++++--------- Controller/Admin/WebHookController.php | 12 +++---- Controller/ApiController.php | 12 ++++--- DependencyInjection/ApiExtension.php | 9 +++++- .../Compiler/ApiCompilerPass.php | 22 ++++++------- Doctrine/EventSubscriber/EntityListener.php | 6 ++-- Entity/WebHook.php | 4 +-- .../AuthorizationRequestResolveListener.php | 19 ++++------- EventListener/UserResolveListener.php | 4 +-- Form/Type/Admin/ClientType.php | 4 +-- Form/Type/Admin/OAuth2AuthorizationType.php | 2 +- Form/Type/Admin/WebHookType.php | 2 +- GraphQL/AllowList.php | 2 +- GraphQL/Error/InvalidArgumentException.php | 2 +- GraphQL/Mutation.php | 2 +- .../Mutation/UpdateProductStockMutation.php | 8 ++--- GraphQL/Mutation/UpdateShippedMutation.php | 10 +++--- GraphQL/Query.php | 2 +- GraphQL/Query/CustomerQuery.php | 2 +- GraphQL/Query/CustomersQuery.php | 2 +- GraphQL/Query/OrderQuery.php | 2 +- GraphQL/Query/OrdersQuery.php | 2 +- GraphQL/Query/ProductQuery.php | 2 +- GraphQL/Query/ProductsQuery.php | 2 +- GraphQL/Query/SearchFormQuery.php | 13 ++++---- GraphQL/Query/SingleResultQuery.php | 6 ++-- GraphQL/Schema.php | 2 +- GraphQL/ScopeValidationRule.php | 2 +- GraphQL/Type/ConnectionType.php | 4 +-- GraphQL/Type/Definition/DateTimeType.php | 4 +-- GraphQL/Type/EdgeType.php | 4 +-- GraphQL/Type/PageInfoType.php | 2 +- GraphQL/Types.php | 4 +-- PluginManager.php | 2 +- Repository/WebHookRepository.php | 6 ++-- Resource/config/bundles.php | 3 +- Resource/config/routes.php | 16 ++++++++++ Resource/config/services.yaml | 27 +++++++++------- Resource/template/admin/OAuth/index.twig | 2 +- Security/Core/Encoder/UserPasswordEncoder.php | 10 +++++- Service/CoreEntityTrigger.php | 2 +- Service/WebHookEvents.php | 2 +- Service/WebHookService.php | 10 +++--- Service/WebHookTrigger.php | 2 +- Tests/GraphQL/AllowListTest.php | 4 +-- .../UpdateProductStockMutationTest.php | 16 +++++----- .../Mutation/UpdateShippedMutationTest.php | 18 +++++------ Tests/GraphQL/SchemaTest.php | 8 ++--- Tests/GraphQL/TypesTest.php | 6 ++-- Tests/Service/WebHookServiceTest.php | 8 ++--- Tests/Web/Admin/LoginControllerTest.php | 2 +- .../AuthorizationControllerTest.php | 6 ++-- Tests/Web/Admin/OAuthControllerTest.php | 18 +++++------ Tests/Web/ApiControllerTest.php | 14 ++++---- composer.json | 12 +++---- docs/_pages/customize/query.md | 6 ++-- docs/_pages/quickstart.md | 4 +-- docs/_pages/webhook.md | 2 +- phpunit.xml.dist | 1 + 63 files changed, 232 insertions(+), 200 deletions(-) create mode 100644 Resource/config/routes.php diff --git a/ApiNav.php b/ApiNav.php index 7302a01..2ba3451 100644 --- a/ApiNav.php +++ b/ApiNav.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api; +namespace Plugin\Api42; use Eccube\Common\EccubeNav; diff --git a/Bundle/ApiBundle.php b/Bundle/ApiBundle.php index 0b8535f..76e0657 100644 --- a/Bundle/ApiBundle.php +++ b/Bundle/ApiBundle.php @@ -11,10 +11,10 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Bundle; +namespace Plugin\Api42\Bundle; -use Plugin\Api\DependencyInjection\ApiExtension; -use Plugin\Api\DependencyInjection\Compiler\ApiCompilerPass; +use Plugin\Api42\DependencyInjection\ApiExtension; +use Plugin\Api42\DependencyInjection\Compiler\ApiCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/Command/DumpSchemaCommand.php b/Command/DumpSchemaCommand.php index 2cef295..df81e9e 100644 --- a/Command/DumpSchemaCommand.php +++ b/Command/DumpSchemaCommand.php @@ -11,10 +11,10 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Command; +namespace Plugin\Api42\Command; use GraphQL\Utils\SchemaPrinter; -use Plugin\Api\GraphQL\Schema; +use Plugin\Api42\GraphQL\Schema; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/Controller/Admin/GraphiQLController.php b/Controller/Admin/GraphiQLController.php index 8b93bbb..00fe42e 100644 --- a/Controller/Admin/GraphiQLController.php +++ b/Controller/Admin/GraphiQLController.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Controller\Admin; +namespace Plugin\Api42\Controller\Admin; use Eccube\Controller\AbstractController; use GraphQL\Error\DebugFlag; use GraphQL\GraphQL; -use Plugin\Api\GraphQL\Schema; +use Plugin\Api42\GraphQL\Schema; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -46,7 +46,7 @@ public function __construct( /** * @Route("/%eccube_admin_route%/graphiql", name="admin_api_graphiql", methods={"GET"}) - * @Template("@Api/admin/OAuth/graphiql.twig") + * @Template("@Api42/admin/OAuth/graphiql.twig") * * @return array */ diff --git a/Controller/Admin/OAuthController.php b/Controller/Admin/OAuthController.php index 9f70ae7..ab49663 100644 --- a/Controller/Admin/OAuthController.php +++ b/Controller/Admin/OAuthController.php @@ -11,26 +11,26 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Controller\Admin; +namespace Plugin\Api42\Controller\Admin; use Eccube\Controller\AbstractController; use Exception; -use Plugin\Api\Form\Type\Admin\ClientType; +use Plugin\Api42\Form\Type\Admin\ClientType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -use Trikoder\Bundle\OAuth2Bundle\Manager\AccessTokenManagerInterface; -use Trikoder\Bundle\OAuth2Bundle\Manager\ClientFilter; -use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface; -use Trikoder\Bundle\OAuth2Bundle\Manager\RefreshTokenManagerInterface; -use Trikoder\Bundle\OAuth2Bundle\Model\AuthorizationCode; -use Trikoder\Bundle\OAuth2Bundle\Model\Client; -use Trikoder\Bundle\OAuth2Bundle\Model\Grant; -use Trikoder\Bundle\OAuth2Bundle\Model\RedirectUri; -use Trikoder\Bundle\OAuth2Bundle\Model\Scope; -use Trikoder\Bundle\OAuth2Bundle\OAuth2Grants; +use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface; +use League\Bundle\OAuth2ServerBundle\Manager\ClientFilter; +use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface; +use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface; +use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode; +use League\Bundle\OAuth2ServerBundle\Model\Client; +use League\Bundle\OAuth2ServerBundle\Model\Grant; +use League\Bundle\OAuth2ServerBundle\Model\RedirectUri; +use League\Bundle\OAuth2ServerBundle\Model\Scope; +use League\Bundle\OAuth2ServerBundle\OAuth2Grants; class OAuthController extends AbstractController { @@ -67,7 +67,7 @@ public function __construct( /** * @Route("/%eccube_admin_route%/api/config", name="admin_api_config", methods={"GET"}) * @Route("/%eccube_admin_route%/api/oauth", name="admin_api_oauth", methods={"GET"}) - * @Template("@Api/admin/OAuth/index.twig") + * @Template("@Api42/admin/OAuth/index.twig") * * @param Request $request * @@ -85,7 +85,7 @@ public function index(Request $request) /** * @Route("/%eccube_admin_route%/api/oauth/new", name="admin_api_oauth_new", methods={"GET", "POST"}) - * @Template("@Api/admin/OAuth/edit.twig") + * @Template("@Api42/admin/OAuth/edit.twig") * * @param Request $request * @@ -95,6 +95,8 @@ public function index(Request $request) */ public function create(Request $request) { + $name = ''; + $builder = $this->formFactory ->createBuilder(ClientType::class); @@ -106,7 +108,7 @@ public function create(Request $request) $secret = $form->get('secret')->getData(); try { - $client = new Client($identifier, $secret); + $client = new Client($name, $identifier, $secret); $client = $this->updateClientFromForm($client, $form); $this->clientManager->save($client); diff --git a/Controller/Admin/WebHookController.php b/Controller/Admin/WebHookController.php index 7282d26..edf7489 100644 --- a/Controller/Admin/WebHookController.php +++ b/Controller/Admin/WebHookController.php @@ -11,13 +11,13 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Controller\Admin; +namespace Plugin\Api42\Controller\Admin; use Eccube\Controller\AbstractController; use Exception; -use Plugin\Api\Entity\WebHook; -use Plugin\Api\Form\Type\Admin\WebHookType; -use Plugin\Api\Repository\WebHookRepository; +use Plugin\Api42\Entity\WebHook; +use Plugin\Api42\Form\Type\Admin\WebHookType; +use Plugin\Api42\Repository\WebHookRepository; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -41,7 +41,7 @@ public function __construct(WebHookRepository $webHookRepository) /** * @Route("/%eccube_admin_route%/api/webhook", name="admin_api_webhook", methods={"GET"}) - * @Template("@Api/admin/WebHook/index.twig") + * @Template("@Api42/admin/WebHook/index.twig") */ public function index() { @@ -55,7 +55,7 @@ public function index() /** * @Route("/%eccube_admin_route%/api/webhook/new", name="admin_api_webhook_new", methods={"GET", "POST"}) * @Route("/%eccube_admin_route%/api/webhook/edit/{id}", requirements={"id" = "\d+"}, name="admin_api_webhook_edit", methods={"GET", "POST"}) - * @Template("@Api/admin/WebHook/edit.twig") + * @Template("@Api42/admin/WebHook/edit.twig") * * @param Request $request * @param WebHook|null $WebHook diff --git a/Controller/ApiController.php b/Controller/ApiController.php index bee6cda..ee9faa9 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -11,20 +11,21 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Controller; +namespace Plugin\Api42\Controller; use Eccube\Controller\AbstractController; use GraphQL\Error\DebugFlag; use GraphQL\GraphQL; use GraphQL\Validator\DocumentValidator; -use Plugin\Api\GraphQL\Schema; -use Plugin\Api\GraphQL\ScopeValidationRule; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Schema; +use Plugin\Api42\GraphQL\ScopeValidationRule; +use Plugin\Api42\GraphQL\Types; use RuntimeException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\Annotation\Route; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; class ApiController extends AbstractController { @@ -62,8 +63,9 @@ public function __construct( /** * @Route("/api", name="api", methods={"GET", "POST"}) - * @Security("has_role('ROLE_OAUTH2_READ') or has_role('ROLE_OAUTH2_WRITE')") + * @IsGranted("ROLE_OAUTH2_READ", "ROLE_OAUTH2_WRITE") */ + public function index(Request $request) { switch ($request->getMethod()) { diff --git a/DependencyInjection/ApiExtension.php b/DependencyInjection/ApiExtension.php index 40f2c5e..8a6c9c9 100644 --- a/DependencyInjection/ApiExtension.php +++ b/DependencyInjection/ApiExtension.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\DependencyInjection; +namespace Plugin\Api42\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -39,6 +39,13 @@ public function prepend(ContainerBuilder $container) 'oauth2' => true, 'provider' => 'member_provider' ]; + unset($security["firewalls"]["admin"]["form_login"]["csrf_token_generator"]); + unset($security["firewalls"]["admin"]["anonymous"]); + } + + if ($name === 'customer') { + unset($security["firewalls"]["customer"]["form_login"]["csrf_token_generator"]); + unset($security["firewalls"]["customer"]["anonymous"]); } $replaced[$name] = $security["firewalls"][$name]; } diff --git a/DependencyInjection/Compiler/ApiCompilerPass.php b/DependencyInjection/Compiler/ApiCompilerPass.php index 14c1b33..1104807 100644 --- a/DependencyInjection/Compiler/ApiCompilerPass.php +++ b/DependencyInjection/Compiler/ApiCompilerPass.php @@ -11,15 +11,15 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\DependencyInjection\Compiler; +namespace Plugin\Api42\DependencyInjection\Compiler; use League\OAuth2\Server\CryptKey; -use Plugin\Api\GraphQL\AllowList; -use Plugin\Api\GraphQL\Mutation; -use Plugin\Api\GraphQL\Query; -use Plugin\Api\GraphQL\Types; -use Plugin\Api\Service\WebHookEvents; -use Plugin\Api\Service\WebHookTrigger; +use Plugin\Api42\GraphQL\AllowList; +use Plugin\Api42\GraphQL\Mutation; +use Plugin\Api42\GraphQL\Query; +use Plugin\Api42\GraphQL\Types; +use Plugin\Api42\Service\WebHookEvents; +use Plugin\Api42\Service\WebHookTrigger; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -34,9 +34,9 @@ public function process(ContainerBuilder $container) $this->configureSchema($container); $plugins = $container->getParameter('eccube.plugins.enabled'); - if (!in_array('Api', $plugins)) { - if ($container->hasDefinition('Trikoder\Bundle\OAuth2Bundle\EventListener\ConvertExceptionToResponseListener')) { - $def = $container->getDefinition('Trikoder\Bundle\OAuth2Bundle\EventListener\ConvertExceptionToResponseListener'); + if (!in_array('Api42', $plugins)) { + if ($container->hasDefinition('League\Bundle\OAuth2ServerBundle\EventListener\AddClientDefaultScopesListener')) { + $def = $container->getDefinition('League\Bundle\OAuth2ServerBundle\EventListener\AddClientDefaultScopesListener'); $def->clearTags(); } } @@ -80,7 +80,7 @@ private function configureAllowList(ContainerBuilder $container) private function configureKeyPair(ContainerBuilder $container) { $projectDir = $container->getParameter('kernel.project_dir'); - $oauthConfig = $container->getExtensionConfig('trikoder_oauth2'); + $oauthConfig = $container->getExtensionConfig('league_oauth2_server'); $oauthConfig = $container->resolveEnvPlaceholders($oauthConfig, true); $privateKey = str_replace('%%kernel.project_dir%%', $projectDir, $oauthConfig[0]['authorization_server']['private_key']); $publicKey = str_replace('%%kernel.project_dir%%', $projectDir, $oauthConfig[0]['resource_server']['public_key']); diff --git a/Doctrine/EventSubscriber/EntityListener.php b/Doctrine/EventSubscriber/EntityListener.php index c33df0d..e13de44 100644 --- a/Doctrine/EventSubscriber/EntityListener.php +++ b/Doctrine/EventSubscriber/EntityListener.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Doctrine\EventSubscriber; +namespace Plugin\Api42\Doctrine\EventSubscriber; use Doctrine\Common\EventSubscriber; -use Doctrine\Common\Persistence\Event\LifecycleEventArgs; +use Doctrine\Persistence\Event\LifecycleEventArgs; use Doctrine\ORM\Events; -use Plugin\Api\Service\WebHookEvents; +use Plugin\Api42\Service\WebHookEvents; class EntityListener implements EventSubscriber { diff --git a/Entity/WebHook.php b/Entity/WebHook.php index 2ab0439..48beae0 100644 --- a/Entity/WebHook.php +++ b/Entity/WebHook.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Entity; +namespace Plugin\Api42\Entity; use DateTime; use Doctrine\ORM\Mapping as ORM; @@ -23,7 +23,7 @@ * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255) * @ORM\HasLifecycleCallbacks() - * @ORM\Entity(repositoryClass="Plugin\Api\Repository\WebHookRepository") + * @ORM\Entity(repositoryClass="Plugin\Api42\Repository\WebHookRepository") */ class WebHook { diff --git a/EventListener/AuthorizationRequestResolveListener.php b/EventListener/AuthorizationRequestResolveListener.php index 5cf6ac7..93b9bdb 100644 --- a/EventListener/AuthorizationRequestResolveListener.php +++ b/EventListener/AuthorizationRequestResolveListener.php @@ -11,19 +11,18 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\EventListener; +namespace Plugin\Api42\EventListener; use Eccube\Entity\Master\Authority; use Eccube\Entity\Member; use League\OAuth2\Server\Exception\OAuthServerException; -use Plugin\Api\Form\Type\Admin\OAuth2AuthorizationType; -use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; +use Plugin\Api42\Form\Type\Admin\OAuth2AuthorizationType; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; -use Trikoder\Bundle\OAuth2Bundle\Event\AuthorizationRequestResolveEvent; -use Trikoder\Bundle\OAuth2Bundle\OAuth2Events; +use League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEvent; +use League\Bundle\OAuth2ServerBundle\OAuth2Events; use Twig\Environment as Twig; final class AuthorizationRequestResolveListener implements EventSubscriberInterface @@ -31,9 +30,6 @@ final class AuthorizationRequestResolveListener implements EventSubscriberInterf /** @var Twig */ protected $twig; - /** @var PsrHttpFactory */ - protected $psr7Factory; - /** @var FormFactoryInterface */ protected $formFactory; @@ -42,12 +38,10 @@ final class AuthorizationRequestResolveListener implements EventSubscriberInterf public function __construct( Twig $twig, - PsrHttpFactory $psr7Factory, FormFactoryInterface $formFactory, RequestStack $requestStack ) { $this->twig = $twig; - $this->psr7Factory = $psr7Factory; $this->formFactory = $formFactory; $this->requestStack = $requestStack; } @@ -87,7 +81,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $ $form['state']->setData($event->getState()); $form['scope']->setData(join(' ', $event->getScopes())); $content = $this->twig->render( - '@Api/admin/OAuth/authorization.twig', + '@Api42/admin/OAuth/authorization.twig', [ 'scopes' => $event->getScopes(), 'form' => $form->createView(), @@ -104,8 +98,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $ $event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_DENIED); } } else { - $Response = $this->psr7Factory->createResponse(Response::create($content)); - $event->setResponse($Response); + $event->setResponse(Response::create($content)); } } } diff --git a/EventListener/UserResolveListener.php b/EventListener/UserResolveListener.php index a374192..58a446b 100644 --- a/EventListener/UserResolveListener.php +++ b/EventListener/UserResolveListener.php @@ -11,11 +11,11 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\EventListener; +namespace Plugin\Api42\EventListener; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; -use Trikoder\Bundle\OAuth2Bundle\Event\UserResolveEvent; +use League\Bundle\OAuth2ServerBundle\Event\UserResolveEvent; final class UserResolveListener { diff --git a/Form/Type/Admin/ClientType.php b/Form/Type/Admin/ClientType.php index 313896f..596d50a 100644 --- a/Form/Type/Admin/ClientType.php +++ b/Form/Type/Admin/ClientType.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Form\Type\Admin; +namespace Plugin\Api42\Form\Type\Admin; use Eccube\Common\EccubeConfig; use Exception; @@ -20,7 +20,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints as Assert; -use Trikoder\Bundle\OAuth2Bundle\OAuth2Grants; +use League\Bundle\OAuth2ServerBundle\OAuth2Grants; class ClientType extends AbstractType { diff --git a/Form/Type/Admin/OAuth2AuthorizationType.php b/Form/Type/Admin/OAuth2AuthorizationType.php index 5d62f99..081aafc 100644 --- a/Form/Type/Admin/OAuth2AuthorizationType.php +++ b/Form/Type/Admin/OAuth2AuthorizationType.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Form\Type\Admin; +namespace Plugin\Api42\Form\Type\Admin; use Eccube\Common\EccubeConfig; use Symfony\Component\Form\AbstractType; diff --git a/Form/Type/Admin/WebHookType.php b/Form/Type/Admin/WebHookType.php index b37b68e..bc657fe 100644 --- a/Form/Type/Admin/WebHookType.php +++ b/Form/Type/Admin/WebHookType.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Form\Type\Admin; +namespace Plugin\Api42\Form\Type\Admin; use Eccube\Form\Type\ToggleSwitchType; use Symfony\Component\Form\AbstractType; diff --git a/GraphQL/AllowList.php b/GraphQL/AllowList.php index 4ea30c7..b23c589 100644 --- a/GraphQL/AllowList.php +++ b/GraphQL/AllowList.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; class AllowList { diff --git a/GraphQL/Error/InvalidArgumentException.php b/GraphQL/Error/InvalidArgumentException.php index b20e0a1..d8bd00c 100644 --- a/GraphQL/Error/InvalidArgumentException.php +++ b/GraphQL/Error/InvalidArgumentException.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Error; +namespace Plugin\Api42\GraphQL\Error; use GraphQL\Error\ClientAware; diff --git a/GraphQL/Mutation.php b/GraphQL/Mutation.php index eab18d0..a25866e 100644 --- a/GraphQL/Mutation.php +++ b/GraphQL/Mutation.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; interface Mutation { diff --git a/GraphQL/Mutation/UpdateProductStockMutation.php b/GraphQL/Mutation/UpdateProductStockMutation.php index bafe0fa..12dd9a7 100644 --- a/GraphQL/Mutation/UpdateProductStockMutation.php +++ b/GraphQL/Mutation/UpdateProductStockMutation.php @@ -11,15 +11,15 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Mutation; +namespace Plugin\Api42\GraphQL\Mutation; use Doctrine\ORM\EntityManagerInterface; use Eccube\Entity\ProductClass; use Eccube\Repository\ProductClassRepository; use GraphQL\Type\Definition\Type; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; -use Plugin\Api\GraphQL\Mutation; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Mutation; +use Plugin\Api42\GraphQL\Types; class UpdateProductStockMutation implements Mutation { diff --git a/GraphQL/Mutation/UpdateShippedMutation.php b/GraphQL/Mutation/UpdateShippedMutation.php index f83fc87..1d6f6ac 100644 --- a/GraphQL/Mutation/UpdateShippedMutation.php +++ b/GraphQL/Mutation/UpdateShippedMutation.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Mutation; +namespace Plugin\Api42\GraphQL\Mutation; use Doctrine\ORM\EntityManagerInterface; use Eccube\Common\EccubeConfig; @@ -23,10 +23,10 @@ use Eccube\Service\MailService; use Eccube\Service\OrderStateMachine; use GraphQL\Type\Definition\Type; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; -use Plugin\Api\GraphQL\Mutation; -use Plugin\Api\GraphQL\Type\Definition\DateTimeType; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Mutation; +use Plugin\Api42\GraphQL\Type\Definition\DateTimeType; +use Plugin\Api42\GraphQL\Types; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ConstraintViolationInterface; diff --git a/GraphQL/Query.php b/GraphQL/Query.php index e55b7a5..0853788 100644 --- a/GraphQL/Query.php +++ b/GraphQL/Query.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; interface Query { diff --git a/GraphQL/Query/CustomerQuery.php b/GraphQL/Query/CustomerQuery.php index 18fe50a..23c59df 100644 --- a/GraphQL/Query/CustomerQuery.php +++ b/GraphQL/Query/CustomerQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Customer; diff --git a/GraphQL/Query/CustomersQuery.php b/GraphQL/Query/CustomersQuery.php index 47b5348..5a01910 100644 --- a/GraphQL/Query/CustomersQuery.php +++ b/GraphQL/Query/CustomersQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Customer; use Eccube\Form\Type\Admin\SearchCustomerType; diff --git a/GraphQL/Query/OrderQuery.php b/GraphQL/Query/OrderQuery.php index d451547..aa592fa 100644 --- a/GraphQL/Query/OrderQuery.php +++ b/GraphQL/Query/OrderQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Order; diff --git a/GraphQL/Query/OrdersQuery.php b/GraphQL/Query/OrdersQuery.php index c68e9d9..1e6d3cf 100644 --- a/GraphQL/Query/OrdersQuery.php +++ b/GraphQL/Query/OrdersQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Order; use Eccube\Form\Type\Admin\SearchOrderType; diff --git a/GraphQL/Query/ProductQuery.php b/GraphQL/Query/ProductQuery.php index aaafe12..8db9024 100644 --- a/GraphQL/Query/ProductQuery.php +++ b/GraphQL/Query/ProductQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Product; diff --git a/GraphQL/Query/ProductsQuery.php b/GraphQL/Query/ProductsQuery.php index 4dfdb39..85b997a 100644 --- a/GraphQL/Query/ProductsQuery.php +++ b/GraphQL/Query/ProductsQuery.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Entity\Product; use Eccube\Form\Type\Admin\SearchProductType; diff --git a/GraphQL/Query/SearchFormQuery.php b/GraphQL/Query/SearchFormQuery.php index f13090e..2c5453d 100644 --- a/GraphQL/Query/SearchFormQuery.php +++ b/GraphQL/Query/SearchFormQuery.php @@ -11,16 +11,16 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Eccube\Common\EccubeConfig; use Eccube\Util\StringUtil; use GraphQL\Type\Definition\Type; use Knp\Component\Pager\PaginatorInterface; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; -use Plugin\Api\GraphQL\Query; -use Plugin\Api\GraphQL\Type\ConnectionType; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Query; +use Plugin\Api42\GraphQL\Type\ConnectionType; +use Plugin\Api42\GraphQL\Types; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormBuilderInterface; @@ -97,7 +97,7 @@ protected function createQuery($entityClass, $searchFormType, $resolver) $type = Type::int(); break; case DateTimeType::class: - $type = \Plugin\Api\GraphQL\Type\Definition\DateTimeType::dateTime(); + $type = \Plugin\Api42\GraphQL\Type\Definition\DateTimeType::dateTime(); break; default: $type = Type::string(); @@ -166,6 +166,7 @@ private function overrideDateTimeFormat(FormBuilderInterface $builder) if ($type instanceof DateTimeType) { $options = $field->getOptions(); $options['format'] = "yyyy-MM-dd'T'HH:mm:ssZ"; + $options['html5'] = false; $builder->add($field->getName(), get_class($type), $options); } } diff --git a/GraphQL/Query/SingleResultQuery.php b/GraphQL/Query/SingleResultQuery.php index 1510464..30970e2 100644 --- a/GraphQL/Query/SingleResultQuery.php +++ b/GraphQL/Query/SingleResultQuery.php @@ -11,13 +11,13 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Query; +namespace Plugin\Api42\GraphQL\Query; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use GraphQL\Type\Definition\Type; -use Plugin\Api\GraphQL\Query; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Query; +use Plugin\Api42\GraphQL\Types; abstract class SingleResultQuery implements Query { diff --git a/GraphQL/Schema.php b/GraphQL/Schema.php index 760bd8b..a30bc46 100644 --- a/GraphQL/Schema.php +++ b/GraphQL/Schema.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; use ArrayObject; use GraphQL\Type\Definition\ObjectType; diff --git a/GraphQL/ScopeValidationRule.php b/GraphQL/ScopeValidationRule.php index d2f0f07..db80b17 100644 --- a/GraphQL/ScopeValidationRule.php +++ b/GraphQL/ScopeValidationRule.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; use GraphQL\Error\Error; use GraphQL\Language\AST\NodeKind; diff --git a/GraphQL/Type/ConnectionType.php b/GraphQL/Type/ConnectionType.php index 712f8ad..4ec2305 100644 --- a/GraphQL/Type/ConnectionType.php +++ b/GraphQL/Type/ConnectionType.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Type; +namespace Plugin\Api42\GraphQL\Type; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use Knp\Component\Pager\Pagination\PaginationInterface; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Types; class ConnectionType extends ObjectType { diff --git a/GraphQL/Type/Definition/DateTimeType.php b/GraphQL/Type/Definition/DateTimeType.php index cf1b689..965145a 100644 --- a/GraphQL/Type/Definition/DateTimeType.php +++ b/GraphQL/Type/Definition/DateTimeType.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Type\Definition; +namespace Plugin\Api42\GraphQL\Type\Definition; use DateTime; use DateTimeInterface; @@ -20,7 +20,7 @@ use GraphQL\Language\AST\StringValueNode; use GraphQL\Type\Definition\ScalarType; use GraphQL\Utils\Utils; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; class DateTimeType extends ScalarType { diff --git a/GraphQL/Type/EdgeType.php b/GraphQL/Type/EdgeType.php index 4a0f1e3..9b78bfd 100644 --- a/GraphQL/Type/EdgeType.php +++ b/GraphQL/Type/EdgeType.php @@ -11,10 +11,10 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Type; +namespace Plugin\Api42\GraphQL\Type; use GraphQL\Type\Definition\ObjectType; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Types; class EdgeType extends ObjectType { diff --git a/GraphQL/Type/PageInfoType.php b/GraphQL/Type/PageInfoType.php index f66c697..6ee194d 100644 --- a/GraphQL/Type/PageInfoType.php +++ b/GraphQL/Type/PageInfoType.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL\Type; +namespace Plugin\Api42\GraphQL\Type; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; diff --git a/GraphQL/Types.php b/GraphQL/Types.php index 933a69c..78589eb 100644 --- a/GraphQL/Types.php +++ b/GraphQL/Types.php @@ -11,13 +11,13 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\GraphQL; +namespace Plugin\Api42\GraphQL; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; -use Plugin\Api\GraphQL\Type\Definition\DateTimeType; +use Plugin\Api42\GraphQL\Type\Definition\DateTimeType; /** * DoctrineのEntityからGraphQLのObjectTypeを変換するクラス. diff --git a/PluginManager.php b/PluginManager.php index 90e4c2b..30c80e5 100644 --- a/PluginManager.php +++ b/PluginManager.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api; +namespace Plugin\Api42; use Doctrine\ORM\EntityManager; use Eccube\Entity\AuthorityRole; diff --git a/Repository/WebHookRepository.php b/Repository/WebHookRepository.php index 0ff649d..9216e38 100644 --- a/Repository/WebHookRepository.php +++ b/Repository/WebHookRepository.php @@ -11,11 +11,11 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Repository; +namespace Plugin\Api42\Repository; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Eccube\Repository\AbstractRepository; -use Plugin\Api\Entity\WebHook; +use Plugin\Api42\Entity\WebHook; class WebHookRepository extends AbstractRepository { diff --git a/Resource/config/bundles.php b/Resource/config/bundles.php index e82d3b7..8e08335 100644 --- a/Resource/config/bundles.php +++ b/Resource/config/bundles.php @@ -12,6 +12,5 @@ */ return [ - Plugin\Api\Bundle\ApiBundle::class => ['all' => true], - Trikoder\Bundle\OAuth2Bundle\TrikoderOAuth2Bundle::class => ['all' => true], + Plugin\Api42\Bundle\ApiBundle::class => ['all' => true], ]; diff --git a/Resource/config/routes.php b/Resource/config/routes.php new file mode 100644 index 0000000..c7a50f5 --- /dev/null +++ b/Resource/config/routes.php @@ -0,0 +1,16 @@ +add('oauth2_authorize', '/%eccube_admin_route%/authorize') + ->controller(['league.oauth2_server.controller.authorization', 'indexAction']) + + ->add('oauth2_token', '/token') + ->controller(['league.oauth2_server.controller.token', 'indexAction']) + ->methods(['POST']) + ; +}; diff --git a/Resource/config/services.yaml b/Resource/config/services.yaml index 644920b..7f8f271 100644 --- a/Resource/config/services.yaml +++ b/Resource/config/services.yaml @@ -1,9 +1,12 @@ +security: + enable_authenticator_manager: true parameters: env(ECCUBE_OAUTH2_AUTHORIZATION_SERVER_PRIVATE_KEY): '%kernel.project_dir%/app/PluginData/Api/oauth/private.key' env(ECCUBE_OAUTH2_RESOURCE_SERVER_PUBLIC_KEY): '%kernel.project_dir%/app/PluginData/Api/oauth/public.key' env(ECCUBE_OAUTH2_ENCRYPTION_KEY): '' -trikoder_oauth2: +league_oauth2_server: + role_prefix: ROLE_OAUTH2_ authorization_server: private_key: '%env(ECCUBE_OAUTH2_AUTHORIZATION_SERVER_PRIVATE_KEY)%' @@ -28,21 +31,24 @@ trikoder_oauth2: resource_server: public_key: '%env(ECCUBE_OAUTH2_RESOURCE_SERVER_PUBLIC_KEY)%' - scopes: ['read', 'write'] +# scopes: ['read', 'write'] + scopes: + available: ['read', 'write'] + default: ['read'] persistence: doctrine: null services: - Plugin\Api\EventListener\UserResolveListener: + Plugin\Api42\EventListener\UserResolveListener: arguments: - '@Eccube\Security\Core\User\MemberProvider' - - '@Plugin\Api\Security\Core\Encoder\UserPasswordEncoder' + - '@Plugin\Api42\Security\Core\Encoder\UserPasswordEncoder' tags: - - { name: kernel.event_listener, event: trikoder.oauth2.user_resolve, method: onUserResolve } + - { name: kernel.event_listener, event: league.oauth2_server.event.user_resolve, method: onUserResolve } - Plugin\Api\GraphQL\Types: - class: Plugin\Api\GraphQL\Types + Plugin\Api42\GraphQL\Types: + class: Plugin\Api42\GraphQL\Types arguments: ["@doctrine.orm.entity_manager"] lazy: true @@ -68,9 +74,6 @@ services: nyholm.psr7.httplug_factory: class: Nyholm\Psr7\Factory\HttplugFactory - - Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory: '@sensio_framework_extra.psr7.http_message_factory' - core.api.allow_list: class: ArrayObject tags: ['eccube.api.allow_list'] @@ -144,8 +147,8 @@ services: api.mutations: class: ArrayObject - Plugin\Api\GraphQL\Schema: + Plugin\Api42\GraphQL\Schema: arguments: - - '@Plugin\Api\GraphQL\Types' + - '@Plugin\Api42\GraphQL\Types' - '@api.queries' - '@api.mutations' diff --git a/Resource/template/admin/OAuth/index.twig b/Resource/template/admin/OAuth/index.twig index 8f1e168..27ffbe2 100644 --- a/Resource/template/admin/OAuth/index.twig +++ b/Resource/template/admin/OAuth/index.twig @@ -123,7 +123,7 @@ file that was distributed with this source code. {% endfor %} - {% for grant in client.grants if grant != 'refresh_token' %} + {% for grant in client.grants|filter(grant => grant != 'refresh_token') %} {{ grant }}
{% endfor %} diff --git a/Security/Core/Encoder/UserPasswordEncoder.php b/Security/Core/Encoder/UserPasswordEncoder.php index deedf01..99ccdd5 100644 --- a/Security/Core/Encoder/UserPasswordEncoder.php +++ b/Security/Core/Encoder/UserPasswordEncoder.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Security\Core\Encoder; +namespace Plugin\Api42\Security\Core\Encoder; use Eccube\Security\Core\Encoder\PasswordEncoder; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; @@ -49,4 +49,12 @@ public function isPasswordValid(UserInterface $user, $raw) return $this->passwordEncoder->isPasswordValid($user->getPassword(), $raw, $user->getSalt()); } + + /** + * @inheritDoc + */ + public function needsRehash(UserInterface $user): bool + { + // TODO: Implement needsRehash() method. + } } diff --git a/Service/CoreEntityTrigger.php b/Service/CoreEntityTrigger.php index f63050f..d65081d 100644 --- a/Service/CoreEntityTrigger.php +++ b/Service/CoreEntityTrigger.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Service; +namespace Plugin\Api42\Service; use Eccube\Entity\Customer; use Eccube\Entity\CustomerAddress; diff --git a/Service/WebHookEvents.php b/Service/WebHookEvents.php index c0d92af..90905ef 100644 --- a/Service/WebHookEvents.php +++ b/Service/WebHookEvents.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Service; +namespace Plugin\Api42\Service; use Eccube\Entity\Customer; use Eccube\Entity\Order; diff --git a/Service/WebHookService.php b/Service/WebHookService.php index f209cfb..16c0cc2 100644 --- a/Service/WebHookService.php +++ b/Service/WebHookService.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Service; +namespace Plugin\Api42\Service; use Eccube\Util\StringUtil; use GuzzleHttp\Client; @@ -19,10 +19,10 @@ use GuzzleHttp\Pool; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use Plugin\Api\Entity\WebHook; -use Plugin\Api\Repository\WebHookRepository; +use Plugin\Api42\Entity\WebHook; +use Plugin\Api42\Repository\WebHookRepository; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent ; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Routing\RouterInterface; @@ -60,7 +60,7 @@ public static function getSubscribedEvents() ]; } - public function fire(FilterResponseEvent $event) + public function fire(ResponseEvent $event) { if (!$event->isMasterRequest()) { return; diff --git a/Service/WebHookTrigger.php b/Service/WebHookTrigger.php index 7546e2f..7071396 100644 --- a/Service/WebHookTrigger.php +++ b/Service/WebHookTrigger.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Service; +namespace Plugin\Api42\Service; interface WebHookTrigger { diff --git a/Tests/GraphQL/AllowListTest.php b/Tests/GraphQL/AllowListTest.php index b9bb534..7165701 100644 --- a/Tests/GraphQL/AllowListTest.php +++ b/Tests/GraphQL/AllowListTest.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\GraphQL; +namespace Plugin\Api42\Tests\GraphQL; use Eccube\Entity\Customer; use Eccube\Entity\Product; use PHPUnit\Framework\TestCase; -use Plugin\Api\GraphQL\AllowList; +use Plugin\Api42\GraphQL\AllowList; class AllowListTest extends TestCase { diff --git a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php index 836c683..b21d5c7 100644 --- a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php @@ -11,14 +11,14 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\GraphQL\Mutation; +namespace Plugin\Api42\Tests\GraphQL\Mutation; use Eccube\Entity\ProductClass; use Eccube\Repository\ProductClassRepository; use Eccube\Tests\EccubeTestCase; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; -use Plugin\Api\GraphQL\Mutation\UpdateProductStockMutation; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Mutation\UpdateProductStockMutation; +use Plugin\Api42\GraphQL\Types; class UpdateProductStockMutationTest extends EccubeTestCase { @@ -28,7 +28,7 @@ class UpdateProductStockMutationTest extends EccubeTestCase /** @var UpdateProductStockMutation */ private $updateProductStockMutation; - public function setUp() + public function setUp(): void { parent::setUp(); $types = self::$container->get(Types::class); @@ -75,7 +75,7 @@ public function testUpdateProductStock($args, $expectStockUnlimited, $expectStoc self::assertEquals($expectStock, $ProductClass->getProductStock()->getStock()); } catch (InvalidArgumentException $e) { // エラーの確認 - self::assertRegExp($expectExeption, $e->getMessage()); + self::assertMatchesRegularExpression($expectExeption, $e->getMessage()); } // DBの確認 @@ -120,7 +120,7 @@ public function testUpdateProductStockMultiple() // 通らない self::assertTrue(false); } catch (InvalidArgumentException $e) { - self::assertRegExp('/Multiple ProductClass found/', $e->getMessage()); + self::assertMatchesRegularExpression('/Multiple ProductClass found/', $e->getMessage()); } } @@ -134,7 +134,7 @@ public function testUpdateProductStockNoData() // 通らない self::assertTrue(false); } catch (InvalidArgumentException $e) { - self::assertRegExp('/No ProductClass found/', $e->getMessage()); + self::assertMatchesRegularExpression('/No ProductClass found/', $e->getMessage()); } } } diff --git a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php index 823bb06..201b8b2 100644 --- a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\GraphQL\Mutation; +namespace Plugin\Api42\Tests\GraphQL\Mutation; use DateTime; use Eccube\Entity\Master\OrderStatus; @@ -22,9 +22,9 @@ use Eccube\Service\MailService; use Eccube\Service\OrderStateMachine; use Eccube\Tests\EccubeTestCase; -use Plugin\Api\GraphQL\Error\InvalidArgumentException; -use Plugin\Api\GraphQL\Mutation\UpdateShippedMutation; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Error\InvalidArgumentException; +use Plugin\Api42\GraphQL\Mutation\UpdateShippedMutation; +use Plugin\Api42\GraphQL\Types; class UpdateShippedMutationTest extends EccubeTestCase { @@ -38,7 +38,7 @@ class UpdateShippedMutationTest extends EccubeTestCase */ private $Order; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -119,7 +119,7 @@ public function testValidateArgs($args = [], string $message = null) } catch (InvalidArgumentException $e) { // エラーの確認 self::assertEquals('Invalid argument', $e->getCategory()); - self::assertRegExp($message, $e->getMessage()); + self::assertMatchesRegularExpression($message, $e->getMessage()); // Shipping が出荷済みになっていない self::assertNull($this->Order->getShippings()->current()->getShippingDate()); } @@ -164,7 +164,7 @@ public function testNoShippingFound() } catch (InvalidArgumentException $e) { // エラーの確認 self::assertEquals('Invalid argument', $e->getCategory()); - self::assertRegExp('/No Shipping found/', $e->getMessage()); + self::assertMatchesRegularExpression('/No Shipping found/', $e->getMessage()); } } @@ -188,7 +188,7 @@ public function testAlreadyShipped() } catch (InvalidArgumentException $e) { // エラーの確認 self::assertEquals('Invalid argument', $e->getCategory()); - self::assertRegExp('/Already shipped/', $e->getMessage()); + self::assertMatchesRegularExpression('/Already shipped/', $e->getMessage()); } } @@ -211,7 +211,7 @@ public function testOrderCannotBeShipped() } catch (InvalidArgumentException $e) { // エラーの確認 self::assertEquals('Invalid argument', $e->getCategory()); - self::assertRegExp('/order cannot be shipped/', $e->getMessage()); + self::assertMatchesRegularExpression('/order cannot be shipped/', $e->getMessage()); } } diff --git a/Tests/GraphQL/SchemaTest.php b/Tests/GraphQL/SchemaTest.php index 5c8481f..969a663 100644 --- a/Tests/GraphQL/SchemaTest.php +++ b/Tests/GraphQL/SchemaTest.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\GraphQL; +namespace Plugin\Api42\Tests\GraphQL; use Eccube\Entity\Master\OrderStatus; use Eccube\Tests\EccubeTestCase; @@ -20,7 +20,7 @@ use GraphQL\Server\Helper; use GraphQL\Server\OperationParams; use GraphQL\Server\ServerConfig; -use Plugin\Api\GraphQL\Schema; +use Plugin\Api42\GraphQL\Schema; class SchemaTest extends EccubeTestCase { @@ -264,7 +264,7 @@ public function testQueryWithPagination($page, $limit, $expectedErrorMessage = n $result = $this->executeQuery($query); if ($expectedErrorMessage) { - self::assertRegExp($expectedErrorMessage, $result['errors'][0]['message']); + self::assertMatchesRegularExpression($expectedErrorMessage, $result['errors'][0]['message']); } else { self::assertFalse(isset($result['errors'])); } @@ -289,7 +289,7 @@ public function testQueryWithDateTime($dateTime, $expectedErrorMessage = null) $result = $this->executeQuery($query); if ($expectedErrorMessage) { - self::assertRegExp($expectedErrorMessage, $result['errors'][0]['message']); + self::assertMatchesRegularExpression($expectedErrorMessage, $result['errors'][0]['message']); } else { self::assertFalse(isset($result['errors'])); } diff --git a/Tests/GraphQL/TypesTest.php b/Tests/GraphQL/TypesTest.php index 262f32e..c1293f7 100644 --- a/Tests/GraphQL/TypesTest.php +++ b/Tests/GraphQL/TypesTest.php @@ -11,21 +11,21 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\GraphQL; +namespace Plugin\Api42\Tests\GraphQL; use Eccube\Entity\BaseInfo; use Eccube\Entity\Customer; use Eccube\Entity\Member; use Eccube\Entity\Product; use Eccube\Tests\EccubeTestCase; -use Plugin\Api\GraphQL\Types; +use Plugin\Api42\GraphQL\Types; class TypesTest extends EccubeTestCase { /** @var Types */ private $types; - public function setUp() + public function setUp(): void { parent::setUp(); $this->types = self::$container->get(Types::class); diff --git a/Tests/Service/WebHookServiceTest.php b/Tests/Service/WebHookServiceTest.php index e3a93eb..ad281b5 100644 --- a/Tests/Service/WebHookServiceTest.php +++ b/Tests/Service/WebHookServiceTest.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\Service; +namespace Plugin\Api42\Tests\Service; use Eccube\Tests\EccubeTestCase; use Nyholm\Psr7\Request; -use Plugin\Api\Entity\WebHook; -use Plugin\Api\Service\WebHookService; +use Plugin\Api42\Entity\WebHook; +use Plugin\Api42\Service\WebHookService; use ReflectionClass; use ReflectionException; @@ -25,7 +25,7 @@ class WebHookServiceTest extends EccubeTestCase /** @var WebHookService */ private $service; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/Tests/Web/Admin/LoginControllerTest.php b/Tests/Web/Admin/LoginControllerTest.php index 0d44cae..4bafe9f 100644 --- a/Tests/Web/Admin/LoginControllerTest.php +++ b/Tests/Web/Admin/LoginControllerTest.php @@ -11,7 +11,7 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\Web\Admin; +namespace Plugin\Api42\Tests\Web\Admin; use Eccube\Tests\Web\AbstractWebTestCase; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; diff --git a/Tests/Web/Admin/OAuth2Bundle/AuthorizationControllerTest.php b/Tests/Web/Admin/OAuth2Bundle/AuthorizationControllerTest.php index 4087428..1f04625 100644 --- a/Tests/Web/Admin/OAuth2Bundle/AuthorizationControllerTest.php +++ b/Tests/Web/Admin/OAuth2Bundle/AuthorizationControllerTest.php @@ -11,16 +11,16 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\Web\Admin\OAuth2Bundle; +namespace Plugin\Api42\Tests\Web\Admin\OAuth2Bundle; use Eccube\Common\Constant; use Eccube\Tests\Web\Admin\AbstractAdminWebTestCase; use Symfony\Component\HttpFoundation\Response; -use Trikoder\Bundle\OAuth2Bundle\Model\Client; +use League\Bundle\OAuth2ServerBundle\Model\Client; class AuthorizationControllerTest extends AbstractAdminWebTestCase { - public function setUp() + public function setUp(): void { parent::setUp(); } diff --git a/Tests/Web/Admin/OAuthControllerTest.php b/Tests/Web/Admin/OAuthControllerTest.php index ded8e05..36b3866 100644 --- a/Tests/Web/Admin/OAuthControllerTest.php +++ b/Tests/Web/Admin/OAuthControllerTest.php @@ -11,12 +11,12 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\Web\Admin; +namespace Plugin\Api42\Tests\Web\Admin; use Eccube\Tests\Web\Admin\AbstractAdminWebTestCase; -use Trikoder\Bundle\OAuth2Bundle\Manager\Doctrine\ClientManager; -use Trikoder\Bundle\OAuth2Bundle\Model\Client; -use Trikoder\Bundle\OAuth2Bundle\OAuth2Grants; +use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager; +use League\Bundle\OAuth2ServerBundle\Model\Client; +use League\Bundle\OAuth2ServerBundle\OAuth2Grants; class OAuthControllerTest extends AbstractAdminWebTestCase { @@ -28,7 +28,7 @@ class OAuthControllerTest extends AbstractAdminWebTestCase /** * @{@inheritdoc} */ - public function setUp() + public function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ public function testRoutingAdminSettingSystemOAuth2ClientDelete() $this->assertNull($this->clientManager->find($identifier)); $crawler = $this->client->followRedirect(); - $this->assertRegExp('/削除しました/u', $crawler->filter('div.alert-success')->text()); + $this->assertMatchesRegularExpression('/削除しました/u', $crawler->filter('div.alert-success')->text()); } public function testOAuth2ClientCreateSubmit() @@ -99,7 +99,7 @@ public function testOAuth2ClientCreateSubmit() $this->assertTrue(in_array(OAuth2Grants::REFRESH_TOKEN, $grants)); $crawler = $this->client->followRedirect(); - $this->assertRegExp('/保存しました/u', $crawler->filter('div.alert-success')->text()); + $this->assertMatchesRegularExpression('/保存しました/u', $crawler->filter('div.alert-success')->text()); } public function testOAuth2ClientCreateSubmitFail() @@ -118,7 +118,7 @@ public function testOAuth2ClientCreateSubmitFail() $this->assertTrue($this->client->getResponse()->isSuccessful()); - $this->assertRegExp('/入力されていません。/u', $crawler->filter('span.form-error-message')->text()); + $this->assertMatchesRegularExpression('/入力されていません。/u', $crawler->filter('span.form-error-message')->text()); } public function testOAuth2ClientDeleteIdentifierNotFound() @@ -135,7 +135,7 @@ public function testOAuth2ClientDeleteIdentifierNotFound() $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl)); $crawler = $this->client->followRedirect(); - $this->assertRegExp('/既に削除されています/u', $crawler->filter('div.alert-danger')->text()); + $this->assertMatchesRegularExpression('/既に削除されています/u', $crawler->filter('div.alert-danger')->text()); } protected function createFormData() diff --git a/Tests/Web/ApiControllerTest.php b/Tests/Web/ApiControllerTest.php index a445601..107669b 100644 --- a/Tests/Web/ApiControllerTest.php +++ b/Tests/Web/ApiControllerTest.php @@ -11,17 +11,17 @@ * file that was distributed with this source code. */ -namespace Plugin\Api\Tests\Web; +namespace Plugin\Api42\Tests\Web; use DateTime; use Eccube\Tests\Web\AbstractWebTestCase; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; -use Trikoder\Bundle\OAuth2Bundle\League\Entity\AccessToken; -use Trikoder\Bundle\OAuth2Bundle\League\Entity\Scope; -use Trikoder\Bundle\OAuth2Bundle\Manager\Doctrine\ClientManager; -use Trikoder\Bundle\OAuth2Bundle\Model\Client; +use League\Bundle\OAuth2ServerBundle\Entity\AccessToken; +use League\Bundle\OAuth2ServerBundle\Entity\Scope; +use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager; +use League\Bundle\OAuth2ServerBundle\Model\Client; class ApiControllerTest extends AbstractWebTestCase { @@ -37,7 +37,7 @@ class ApiControllerTest extends AbstractWebTestCase /** @var AuthorizationServer */ private $authorizationServer; - public function setUp() + public function setUp(): void { parent::setUp(); $this->clientManager = self::$container->get(ClientManager::class); @@ -89,7 +89,7 @@ private function newAccessToken($scopes) $client = new Client($identifier, $secret); $client->setScopes(...array_map(function ($s) { - return new \Trikoder\Bundle\OAuth2Bundle\Model\Scope($s); + return new League\Bundle\OAuth2ServerBundle\ValueObject\Scope($s); }, $scopes)); $this->clientManager->save($client); $clientEntity = $this->clientRepository->getClientEntity($identifier, 'authorization_code', $secret); diff --git a/composer.json b/composer.json index 029e3c9..a2ef62f 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,16 @@ { - "name": "ec-cube/api", - "version": "2.1.3", + "name": "ec-cube/api42", + "version": "4.2.0", "description": "Web API", "type": "eccube-plugin", "require": { - "ec-cube/plugin-installer": "~0.0.6 || ^2.0", - "trikoder/oauth2-bundle": "^2.1", + "ec-cube/plugin-installer": "^2.0", + "league/oauth2-server-bundle": "^0.3", "nyholm/psr7": "^1.2", "webonyx/graphql-php": "^14.0" }, "extra": { - "code": "Api", - "entity-namespaces": ["Trikoder\\Bundle\\OAuth2Bundle\\Model"] + "code": "Api42", + "entity-namespaces": ["League\\Bundle\\OAuth2ServerBundle\\Model"] } } diff --git a/docs/_pages/customize/query.md b/docs/_pages/customize/query.md index 1c9cc25..a63877e 100644 --- a/docs/_pages/customize/query.md +++ b/docs/_pages/customize/query.md @@ -4,7 +4,7 @@ permalink: /customize/query ## Query/Mutationの追加 -Query は `Plugin\Api\GraphQL\Query` インタフェースを、 Mutation は `Plugin\Api\GraphQL\Mutation` インタフェースを実装したクラスを作成することで Query/Mutation の追加が可能です。 +Query は `Plugin\Api42\GraphQL\Query` インタフェースを、 Mutation は `Plugin\Api42\GraphQL\Mutation` インタフェースを実装したクラスを作成することで Query/Mutation の追加が可能です。 `Hello Query!` の文字列を返す最小のQueryの実装例は以下です。 @@ -14,7 +14,7 @@ Query は `Plugin\Api\GraphQL\Query` インタフェースを、 Mutation は `P namespace Customize\GraphQL\Query; use GraphQL\Type\Definition\Type; -use Plugin\Api\GraphQL\Query; +use Plugin\Api42\GraphQL\Query; class HelloQuery implements Query { @@ -57,4 +57,4 @@ query { ### 参考 -プラグインのデフォルトの Query および Mutation の実装は `Api/GraphQL/Query` および `Api/GraphQL/Mutation` にあります。 +プラグインのデフォルトの Query および Mutation の実装は `Api42/GraphQL/Query` および `Api42/GraphQL/Mutation` にあります。 diff --git a/docs/_pages/quickstart.md b/docs/_pages/quickstart.md index 010029e..9128ad1 100644 --- a/docs/_pages/quickstart.md +++ b/docs/_pages/quickstart.md @@ -55,8 +55,8 @@ permalink: /quickstart 1. プラグインをインストールします。 ```sh - bin/console eccube:composer:require ec-cube/Api - bin/console eccube:plugin:enable --code=Api + bin/console eccube:composer:require ec-cube/Api42 + bin/console eccube:plugin:enable --code=Api42 ``` - 管理画面→オーナーズストア→プラグイン→ **プラグインを探す** からでもプラグインをインストールできます。 diff --git a/docs/_pages/webhook.md b/docs/_pages/webhook.md index 6f03910..c13a12f 100644 --- a/docs/_pages/webhook.md +++ b/docs/_pages/webhook.md @@ -53,7 +53,7 @@ curl \ #### 上記以外のEntityで発火させるカスタマイズ -プラグインやカスタマイズで上記以外の Entity で発火させたい場合は、 `Plugin\Api\Service\WebHookTrigger` インターフェイスを実装したクラスを定義します。 +プラグインやカスタマイズで上記以外の Entity で発火させたい場合は、 `Plugin\Api42\Service\WebHookTrigger` インターフェイスを実装したクラスを定義します。 ### 対象のアクション diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f94f8ee..c77d321 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,6 +13,7 @@ + From 8e7b5c3a007000e9ec2c1df783f261470d8772b7 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:36:44 +0900 Subject: [PATCH 2/9] =?UTF-8?q?DateTime=20=E3=81=AE=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AF=E6=98=8E=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E3=81=AB=E3=82=AD=E3=83=A3=E3=82=B9=E3=83=88=E3=81=99=E3=82=8B?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=8C=E3=81=82=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GraphQL/Mutation/UpdateShippedMutation.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GraphQL/Mutation/UpdateShippedMutation.php b/GraphQL/Mutation/UpdateShippedMutation.php index 1d6f6ac..1c66f02 100644 --- a/GraphQL/Mutation/UpdateShippedMutation.php +++ b/GraphQL/Mutation/UpdateShippedMutation.php @@ -129,6 +129,11 @@ public function getMutation() public function updateShipped($root, $args) { + // XXX Validate with string + if (array_key_exists('shipping_date', $args) && $args['shipping_date'] instanceof \DateTime) { + $args['shipping_date'] = $args['shipping_date']->format(\DateTime::ATOM); + } + // 引数の検証 $this->validateArgs($args); @@ -180,7 +185,7 @@ private function getConstraint(): Constraint return new Assert\Collection([ 'fields' => [ 'id' => new Assert\GreaterThan(0), - 'shipping_date' => new Assert\DateTime(), + 'shipping_date' => new Assert\DateTime('Y-m-d\TH:i:sP'), 'shipping_delivery_name' => new Assert\Length([ 'max' => $this->eccubeConfig['eccube_mtext_len'], ]), @@ -227,6 +232,10 @@ private function validateShippable(?Shipping $Shipping): void */ private function updateShippingShippedWithArgs(Shipping $Shipping, array $args): void { + // XXX shipping_date may be a string. + if (array_key_exists('shipping_date', $args) && !$args['shipping_date'] instanceof \DateTime) { + $args['shipping_date'] = new \DateTime($args['shipping_date']); + } // Shipping を出荷済みに変更 $Shipping->setShippingDate($args['shipping_date'] ?? new \DateTime()); From 5e11914c93ec4a490d1307955e9b15d62e02a95a Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:39:21 +0900 Subject: [PATCH 3/9] =?UTF-8?q?read=20&=20write=20=E3=81=AE=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AF=E9=85=8D=E5=88=97=E3=81=AF=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GraphQL/ScopeValidationRule.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GraphQL/ScopeValidationRule.php b/GraphQL/ScopeValidationRule.php index db80b17..85a0063 100644 --- a/GraphQL/ScopeValidationRule.php +++ b/GraphQL/ScopeValidationRule.php @@ -41,7 +41,8 @@ public function getVisitor(ValidationContext $context) NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $def) use ($context) { if ($def->operation === 'query' && !$this->authorizationChecker->isGranted('ROLE_OAUTH2_READ')) { $context->reportError(new Error('Insufficient permission. (read)')); - } elseif ($def->operation === 'mutation' && !$this->authorizationChecker->isGranted(['ROLE_OAUTH2_READ', 'ROLE_OAUTH2_WRITE'])) { + } elseif ($def->operation === 'mutation' + && !($this->authorizationChecker->isGranted('ROLE_OAUTH2_READ') && $this->authorizationChecker->isGranted('ROLE_OAUTH2_WRITE'))) { $context->reportError(new Error('Insufficient permission. (read,write)')); } }, From ab40980641170a71e56565dcfb0129ec684cde23 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:41:29 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=A2=E3=83=83=E3=83=97=E3=81=AB=E4=BC=B4=E3=81=86?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resource/config/routes.yaml | 8 -------- Resource/config/services.yaml | 5 ++--- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 Resource/config/routes.yaml diff --git a/Resource/config/routes.yaml b/Resource/config/routes.yaml deleted file mode 100644 index 1d1656a..0000000 --- a/Resource/config/routes.yaml +++ /dev/null @@ -1,8 +0,0 @@ -oauth2_authorize: - path: /%eccube_admin_route%/authorize - defaults: { _controller: Trikoder\Bundle\OAuth2Bundle\Controller\AuthorizationController::indexAction } - -oauth2_token: - path: /token - defaults: { _controller: Trikoder\Bundle\OAuth2Bundle\Controller\TokenController::indexAction } - methods: [POST] diff --git a/Resource/config/services.yaml b/Resource/config/services.yaml index 7f8f271..b5d6348 100644 --- a/Resource/config/services.yaml +++ b/Resource/config/services.yaml @@ -1,8 +1,8 @@ security: enable_authenticator_manager: true parameters: - env(ECCUBE_OAUTH2_AUTHORIZATION_SERVER_PRIVATE_KEY): '%kernel.project_dir%/app/PluginData/Api/oauth/private.key' - env(ECCUBE_OAUTH2_RESOURCE_SERVER_PUBLIC_KEY): '%kernel.project_dir%/app/PluginData/Api/oauth/public.key' + env(ECCUBE_OAUTH2_AUTHORIZATION_SERVER_PRIVATE_KEY): '%kernel.project_dir%/app/PluginData/Api42/oauth/private.key' + env(ECCUBE_OAUTH2_RESOURCE_SERVER_PUBLIC_KEY): '%kernel.project_dir%/app/PluginData/Api42/oauth/public.key' env(ECCUBE_OAUTH2_ENCRYPTION_KEY): '' league_oauth2_server: @@ -31,7 +31,6 @@ league_oauth2_server: resource_server: public_key: '%env(ECCUBE_OAUTH2_RESOURCE_SERVER_PUBLIC_KEY)%' -# scopes: ['read', 'write'] scopes: available: ['read', 'write'] default: ['read'] From 5991ae5478d0ac217f83390abaa931baa6cde1a5 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:42:01 +0900 Subject: [PATCH 5/9] =?UTF-8?q?ConnectionException=20=E3=82=92=E3=82=B9?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=81=99=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8B=E3=81=9F=E3=82=81=E8=A6=AA=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/WebHookService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/WebHookService.php b/Service/WebHookService.php index 16c0cc2..0036d89 100644 --- a/Service/WebHookService.php +++ b/Service/WebHookService.php @@ -15,7 +15,7 @@ use Eccube\Util\StringUtil; use GuzzleHttp\Client; -use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Pool; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; @@ -89,7 +89,7 @@ public function fire(ResponseEvent $event) 'fulfilled' => function (Response $reason, $index) use ($availableWebHooks) { log_info('WebHook request successful.', ['Payload URL' => $availableWebHooks[$index]->getPayloadUrl()]); }, - 'rejected' => function (RequestException $e, $index) use ($availableWebHooks) { + 'rejected' => function (TransferException $e, $index) use ($availableWebHooks) { log_error($e->getMessage(), ['Payload URL' => $availableWebHooks[$index]->getPayloadUrl()]); }, ]); From 9cf42673addd1fbf1ddb3742493ffb13565fcdc2 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:42:44 +0900 Subject: [PATCH 6/9] =?UTF-8?q?EC-CUBE4.1.2=20=E3=81=A7=E3=82=BD=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=AE=E4=BB=95=E6=A7=98=E3=81=8C=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E3=81=9F=E3=82=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 4.1.1 以前は update_date DESC - 4.1.2 以降は update_date DESC, id DESC --- Tests/GraphQL/SchemaTest.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/GraphQL/SchemaTest.php b/Tests/GraphQL/SchemaTest.php index 969a663..a694bd6 100644 --- a/Tests/GraphQL/SchemaTest.php +++ b/Tests/GraphQL/SchemaTest.php @@ -51,8 +51,8 @@ public function testQueryProducts() 'data' => [ 'products' => [ 'nodes' => [ - ['id' => '1'], - ['id' => '2'] + ['id' => '2'], + ['id' => '1'] ] ], ], @@ -86,8 +86,8 @@ public function testQueryProducts_withVariables() 'data' => [ 'products' => [ 'nodes' => [ - ['id' => '1'], - ['id' => '2'] + ['id' => '2'], + ['id' => '1'] ] ], ], @@ -112,12 +112,12 @@ public function testQueryConnection_withEdges() 'edges' => [ [ 'node' => [ - 'id' => '1', + 'id' => '2', ], ], [ 'node' => [ - 'id' => '2', + 'id' => '1', ], ], ], @@ -141,10 +141,10 @@ public function testQueryConnection_withNodes() 'products' => [ 'nodes' => [ [ - 'id' => '1', + 'id' => '2', ], [ - 'id' => '2', + 'id' => '1', ], ], ], @@ -172,10 +172,10 @@ public function testQueryPageInfo() 'products' => [ 'nodes' => [ [ - 'id' => '1', + 'id' => '2', ], [ - 'id' => '2', + 'id' => '1', ], ], 'totalCount' => 2, @@ -208,7 +208,7 @@ public function testQueryPageInfo_firstPage() 'products' => [ 'nodes' => [ [ - 'id' => '1', + 'id' => '2', ], ], 'totalCount' => 2, @@ -241,7 +241,7 @@ public function testQueryPageInfo_LastPage() 'products' => [ 'nodes' => [ [ - 'id' => '2', + 'id' => '1', ], ], 'totalCount' => 2, From ed8148eac6f21e94ae001500cf4b2a4761a278ad Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 16:44:38 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=8C?= =?UTF-8?q?=E9=80=9A=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mutation/UpdateShippedMutationTest.php | 12 +++++++----- Tests/Web/Admin/OAuthControllerTest.php | 2 +- Tests/Web/ApiControllerTest.php | 16 +++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php index 201b8b2..6d2034b 100644 --- a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php @@ -91,7 +91,7 @@ public function testResponseAndDB() self::assertEquals('notes_0123456789', $Shipping->getNote()); } catch (InvalidArgumentException $e) { // 通らない - self::assertTrue(false); + self::assertTrue(false, $e->getMessage()); } // DB の確認 @@ -119,7 +119,9 @@ public function testValidateArgs($args = [], string $message = null) } catch (InvalidArgumentException $e) { // エラーの確認 self::assertEquals('Invalid argument', $e->getCategory()); - self::assertMatchesRegularExpression($message, $e->getMessage()); + if ($message !== null) { + self::assertStringContainsString($message, $e->getMessage()); + } // Shipping が出荷済みになっていない self::assertNull($this->Order->getShippings()->current()->getShippingDate()); } @@ -141,11 +143,11 @@ public function validateArgsProvider() [['id' => -1], '/id/'], [['shipping_date' => $dateTime]], [['shipping_delivery_name' => $str_eccube_mtext_len]], - [['shipping_delivery_name' => $str_eccube_mtext_len_plus], '/shipping_delivery_name/'], + [['shipping_delivery_name' => $str_eccube_mtext_len_plus], 'shipping_delivery_name'], [['tracking_number' => $str_eccube_mtext_len]], - [['tracking_number' => $str_eccube_mtext_len_plus], '/tracking_number/'], + [['tracking_number' => $str_eccube_mtext_len_plus], 'tracking_number'], [['note' => $str_eccube_ltext_len]], - [['note' => $str_eccube_ltext_len_plus], '/note/'], + [['note' => $str_eccube_ltext_len_plus], 'note'], [['is_send_mail' => false]], ]; } diff --git a/Tests/Web/Admin/OAuthControllerTest.php b/Tests/Web/Admin/OAuthControllerTest.php index 36b3866..bc91d8b 100644 --- a/Tests/Web/Admin/OAuthControllerTest.php +++ b/Tests/Web/Admin/OAuthControllerTest.php @@ -52,7 +52,7 @@ public function testRoutingAdminSettingSystemOAuth2ClientDelete() // before $identifier = hash('md5', random_bytes(16)); $secret = hash('sha512', random_bytes(32)); - $client = new Client($identifier, $secret); + $client = new Client('', $identifier, $secret); $this->clientManager->save($client); // main diff --git a/Tests/Web/ApiControllerTest.php b/Tests/Web/ApiControllerTest.php index 107669b..5bd4764 100644 --- a/Tests/Web/ApiControllerTest.php +++ b/Tests/Web/ApiControllerTest.php @@ -13,9 +13,9 @@ namespace Plugin\Api42\Tests\Web; -use DateTime; use Eccube\Tests\Web\AbstractWebTestCase; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\Bundle\OAuth2ServerBundle\Entity\AccessToken; @@ -87,9 +87,9 @@ private function newAccessToken($scopes) $identifier = hash('md5', random_bytes(16)); $secret = hash('sha512', random_bytes(32)); - $client = new Client($identifier, $secret); + $client = new Client('', $identifier, $secret); $client->setScopes(...array_map(function ($s) { - return new League\Bundle\OAuth2ServerBundle\ValueObject\Scope($s); + return new \League\Bundle\OAuth2ServerBundle\Model\Scope($s); }, $scopes)); $this->clientManager->save($client); $clientEntity = $this->clientRepository->getClientEntity($identifier, 'authorization_code', $secret); @@ -97,8 +97,10 @@ private function newAccessToken($scopes) $accessTokenEntity = new AccessToken(); $accessTokenEntity->setIdentifier($identifier); $accessTokenEntity->setClient($clientEntity); - $accessTokenEntity->setExpiryDateTime(new DateTime('+1 hour')); + $accessTokenEntity->setExpiryDateTime(new \DateTimeImmutable('+1 days', new \DateTimeZone('Asia/Tokyo'))); $accessTokenEntity->setUserIdentifier('admin'); + $accessTokenEntity->setPrivateKey(new CryptKey(self::$container->getParameter('kernel.project_dir').'/app/PluginData/Api42/oauth/private.key')); + array_walk($scopes, function ($s) use ($accessTokenEntity) { $scope = new Scope(); $scope->setIdentifier($s); @@ -106,10 +108,6 @@ private function newAccessToken($scopes) }); $this->accessTokenRepository->persistNewAccessToken($accessTokenEntity); - $rc = new \ReflectionClass($this->authorizationServer); - $property = $rc->getProperty('privateKey'); - $property->setAccessible(true); - - return $accessTokenEntity->convertToJWT($property->getValue($this->authorizationServer)); + return $accessTokenEntity->__toString(); } } From 7bf6764c470a2ad598705f8767c3b34c23cc7d9e Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 24 Jun 2022 17:01:17 +0900 Subject: [PATCH 8/9] =?UTF-8?q?EC-CUBE4.2=E5=90=91=E3=81=91=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 126 ++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8d8c90f..e617397 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,38 +22,42 @@ jobs: fail-fast: false matrix: operating-system: [ ubuntu-18.04 ] - php: [ '7.2', '7.3', '7.4' ] - db: [ mysql, pgsql ] - eccube_version: [ '4.0.6-p1', '4.1' ] - plugin_code: [ 'Api' ] + php: [ '7.4', '8.0', '8.1' ] + db: [ 'mysql', 'mysql8', 'pgsql' ] + eccube_version: [ '4.2' ] + plugin_code: [ 'Api42' ] include: - - eccube_version: '4.0.6-p1' - composer: 'v1' - - eccube_version: '4.1' - composer: 'v2' - db: mysql - dbport: '3306' - dbuser: 'root' - dbpass: 'root' - dbname: 'myapp_test' - dbversion: 5.7 + database_url: mysql://root:password@127.0.0.1:3306/eccube_db + database_server_version: 5.7 + database_charset: utf8mb4 + - db: mysql8 + database_url: mysql://root:password@127.0.0.1:3308/eccube_db + database_server_version: 8 + database_charset: utf8mb4 - db: pgsql - dbport: '5432' - dbuser: 'postgres' - dbpass: 'password' - dbname: 'myapp_test' - dbversion: 9.5 + database_url: postgres://postgres:password@127.0.0.1:5432/eccube_db + database_server_version: 14 + database_charset: utf8 services: mysql: image: mysql:5.7 env: - MYSQL_ROOT_PASSWORD: root + MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: ${{ matrix.dbname }} ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + mysql8: + image: mysql:8 + env: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: ${{ matrix.dbname }} + ports: + - 3308:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 postgres: - image: postgres:9.5 + image: postgres:14 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: password @@ -110,80 +114,84 @@ jobs: restore-keys: | ${{ runner.os }}-composer- - - if: matrix.composer == 'v1' - run: sudo composer selfupdate --1 - - name: Install to composer working-directory: 'ec-cube' run: composer install --no-interaction -o --apcu-autoloader - - if: matrix.composer == 'v1' - working-directory: 'ec-cube' - run: composer require kiy0taka/eccube4-test-fixer "dev-main@dev" - - name: Setup EC-CUBE env: - DB: ${{ matrix.db }} - USER: ${{ matrix.dbuser }} - DBUSER: ${{ matrix.dbuser }} - DBPASS: ${{ matrix.dbpass }} - DBNAME: ${{ matrix.dbname }} - DBPORT: ${{ matrix.dbport }} - DBSERVER: 127.0.0.1 - DBVERSION: ${{ matrix.dbversion }} - ROOT_URLPATH: /ec-cube/html + APP_ENV: 'test' + APP_DEBUG: 0 + DATABASE_URL: ${{ matrix.database_url }} + DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} + DATABASE_CHARSET: ${{ matrix.database_charset }} + ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' + USE_SELFSIGNED_SSL_CERTIFICATE: '1' working-directory: 'ec-cube' run: | - export PGPASSWORD=${DBPASS} - echo "APP_ENV=dev" > .env - echo "APP_DEBUG=1" >> .env - echo "DATABASE_URL=${DB}://${DBUSER}:${DBPASS}@${DBSERVER}/${DBNAME}" >> .env - echo "DATABASE_SERVER_VERSION=${DBVERSION}" >> .env - echo "MAILER_URL=smtp://127.0.0.1:1025" >> .env - echo "ECCUBE_PACKAGE_API_URL=http://127.0.0.1:8080" >> .env - echo "USE_SELFSIGNED_SSL_CERTIFICATE=1" >> .env - cat .env + bin/console doctrine:database:create bin/console doctrine:schema:create bin/console eccube:fixtures:load - name: Setup Plugin env: + APP_ENV: 'test' + APP_DEBUG: 0 + DATABASE_URL: ${{ matrix.database_url }} + DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} + DATABASE_CHARSET: ${{ matrix.database_charset }} PLUGIN_CODE: ${{ matrix.plugin_code }} + ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' + USE_SELFSIGNED_SSL_CERTIFICATE: '1' working-directory: 'ec-cube' run: | bin/console doctrine:query:sql "update dtb_base_info set authentication_key='dummy'" - bin/console eccube:composer:require ec-cube/api + bin/console eccube:composer:require ec-cube/api42 bin/console eccube:plugin:enable --code=${PLUGIN_CODE} bin/console doctrine:schema:update --force --dump-sql - bin/console trikoder:oauth2:create-client --redirect-uri=http://127.0.0.1:8000/ --grant-type=authorization_code --grant-type=client_credentials --grant-type=implicit --grant-type=password --grant-type=refresh_token --scope=read --scope=write + bin/console cache:clear --no-warmup + bin/console league:oauth2-server:create-client --redirect-uri=http://127.0.0.1:8000/ --grant-type=authorization_code --grant-type=client_credentials --grant-type=implicit --grant-type=password --grant-type=refresh_token --scope=read --scope=write test rm codeception/_support/*Tester.php + chmod 600 app/PluginData/Api42/oauth/private.key - name: Run PHPUnit - if: matrix.composer == 'v2' - env: - PLUGIN_CODE: ${{ matrix.plugin_code }} - working-directory: 'ec-cube' - run: bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests - - - name: Run PHPUnit - if: matrix.composer == 'v1' env: + APP_ENV: 'test' + APP_DEBUG: 0 + DATABASE_URL: ${{ matrix.database_url }} + DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} + DATABASE_CHARSET: ${{ matrix.database_charset }} PLUGIN_CODE: ${{ matrix.plugin_code }} + ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' + USE_SELFSIGNED_SSL_CERTIFICATE: '1' working-directory: 'ec-cube' run: | - find app/Plugin/${PLUGIN_CODE}/Tests -name "*Test.php" | while read TESTCASE - do - ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --include-path vendor/kiy0taka/eccube4-test-fixer/src --loader 'Eccube\PHPUnit\Loader\Eccube4CompatTestSuiteLoader' ${TESTCASE} - done + bin/console cache:clear --no-warmup + bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests + - name: Disable Plugin working-directory: 'ec-cube' env: + APP_ENV: 'test' + APP_DEBUG: 0 + DATABASE_URL: ${{ matrix.database_url }} + DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} + DATABASE_CHARSET: ${{ matrix.database_charset }} PLUGIN_CODE: ${{ matrix.plugin_code }} + ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' + USE_SELFSIGNED_SSL_CERTIFICATE: '1' run: bin/console eccube:plugin:disable --code=${PLUGIN_CODE} - name: Uninstall Plugin env: + APP_ENV: 'test' + APP_DEBUG: 0 + DATABASE_URL: ${{ matrix.database_url }} + DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} + DATABASE_CHARSET: ${{ matrix.database_charset }} PLUGIN_CODE: ${{ matrix.plugin_code }} + ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' + USE_SELFSIGNED_SSL_CERTIFICATE: '1' working-directory: 'ec-cube' run: bin/console eccube:plugin:uninstall --code=${PLUGIN_CODE} From 7323a9885ebcd2863fdf15aba73ef3703640c981 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 27 Jun 2022 16:36:41 +0900 Subject: [PATCH 9/9] bootstrap5 support --- Resource/template/admin/OAuth/index.twig | 4 ++-- Resource/template/admin/WebHook/index.twig | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Resource/template/admin/OAuth/index.twig b/Resource/template/admin/OAuth/index.twig index 27ffbe2..91dcecf 100644 --- a/Resource/template/admin/OAuth/index.twig +++ b/Resource/template/admin/OAuth/index.twig @@ -132,8 +132,8 @@ file that was distributed with this source code.
diff --git a/Resource/template/admin/WebHook/index.twig b/Resource/template/admin/WebHook/index.twig index fba3621..93505ec 100644 --- a/Resource/template/admin/WebHook/index.twig +++ b/Resource/template/admin/WebHook/index.twig @@ -66,8 +66,8 @@ file that was distributed with this source code.