Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

命名やディレクトリ構造を整理 #42

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ApiNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function getNav()
'children' => [
'oauth' => [
'name' => 'api.admin.oauth.management',
'url' => 'api_admin_setting_system_oauth',
'url' => 'admin_api_oauth',
],
'webhook' => [
'name' => 'api.admin.webhook.management',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Controller\Admin\Setting\System;
namespace Plugin\Api\Controller\Admin;

use Eccube\Controller\AbstractController;
use Exception;
Expand All @@ -31,7 +31,7 @@
use Trikoder\Bundle\OAuth2Bundle\Model\RedirectUri;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope;

class OAuth2ClientController extends AbstractController
class OAuthController extends AbstractController
{
/**
* @var ClientManagerInterface
Expand Down Expand Up @@ -64,9 +64,9 @@ public function __construct(
}

/**
* @Route("/%eccube_admin_route%/api/config", name="api_admin_config")
* @Route("/%eccube_admin_route%/api/setting/system/oauth", name="api_admin_setting_system_oauth")
* @Template("@Api/admin/Setting/System/oauth.twig")
* @Route("/%eccube_admin_route%/api/config", name="admin_api_config")
* @Route("/%eccube_admin_route%/api/oauth", name="admin_api_oauth")
* @Template("@Api/admin/OAuth/index.twig")
*
* @param Request $request
*
Expand All @@ -83,8 +83,8 @@ public function index(Request $request)
}

/**
* @Route("/%eccube_admin_route%/api/setting/system/oauth/create_client", name="api_admin_setting_oauth_create_client")
* @Template("@Api/admin/Setting/System/oauth_edit.twig")
* @Route("/%eccube_admin_route%/api/oauth/new", name="admin_api_oauth_new")
* @Template("@Api/admin/OAuth/edit.twig")
*
* @param Request $request
*
Expand Down Expand Up @@ -112,7 +112,7 @@ public function create(Request $request)

$this->addSuccess('admin.common.save_complete', 'admin');

return $this->redirectToRoute('api_admin_setting_system_oauth');
return $this->redirectToRoute('admin_api_oauth');
} catch (Exception $e) {
dump($e);
$this->addError(trans('admin.common.save_error'), 'admin');
Expand All @@ -127,9 +127,9 @@ public function create(Request $request)

/**
* @Route(
* "/%eccube_admin_route%/api/setting/system/oauth/delete_client/{identifier}",
* "/%eccube_admin_route%/api/oauth/delete/{identifier}",
* requirements={"identifier" = "\w+"},
* name="api_admin_setting_oauth_delete_client",
* name="admin_api_oauth_delete",
* methods={"DELETE"}
* )
*
Expand All @@ -144,7 +144,7 @@ public function delete(Request $request, string $identifier)
if (null === $client) {
$this->addError('admin.common.delete_error_already_deleted', 'admin');

return $this->redirectToRoute('api_admin_setting_system_oauth');
return $this->redirectToRoute('admin_api_oauth');
}

try {
Expand All @@ -158,13 +158,13 @@ public function delete(Request $request, string $identifier)
log_error('OAuth2 Client 削除エラー', [$e->getMessage()]);
}

return $this->redirectToRoute('api_admin_setting_system_oauth');
return $this->redirectToRoute('admin_api_oauth');
}

/**
* @Route(
* "/%eccube_admin_route%/api/setting/system/oauth/clear_expired_tokens",
* name="api_admin_setting_oauth_clear_expired_tokens",
* "/%eccube_admin_route%/api/oauth/clear_expired_tokens",
* name="admin_api_oauth_clear_expired_tokens",
* methods={"DELETE"}
* )
*
Expand All @@ -184,7 +184,7 @@ public function clearExpiredTokens(Request $request)
log_error('OAuth2 Token 削除エラー', [$e->getMessage()]);
}

return $this->redirectToRoute('api_admin_setting_system_oauth');
return $this->redirectToRoute('admin_api_oauth');
}

/**
Expand Down
1 change: 0 additions & 1 deletion Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Eccube\Repository\OrderRepository;
use Eccube\Repository\ProductRepository;
use GraphQL\Error\DebugFlag;
use GraphQL\Error\InvariantViolation;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
Expand Down
18 changes: 14 additions & 4 deletions EventListener/AuthorizationRequestResolveListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\EventListener;

Expand Down Expand Up @@ -35,8 +45,7 @@ public function __construct(
PsrHttpFactory $psr7Factory,
FormFactoryInterface $formFactory,
RequestStack $requestStack
)
{
) {
$this->twig = $twig;
$this->psr7Factory = $psr7Factory;
$this->formFactory = $formFactory;
Expand All @@ -58,6 +67,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $
// システム管理者以外は承認しない
if (!$user instanceof Member || $user->getAuthority()->getId() !== Authority::ADMIN) {
$event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_DENIED);

return;
}

Expand All @@ -77,10 +87,10 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $
$form['state']->setData($event->getState());
$form['scope']->setData(join(' ', $event->getScopes()));
$content = $this->twig->render(
'@Api/admin/OAuth2/authorization.twig',
'@Api/admin/OAuth/authorization.twig',
[
'scope' => join(' ', $event->getScopes()),
'form' => $form->createView()
'form' => $form->createView(),
]
);

Expand Down
10 changes: 10 additions & 0 deletions EventListener/UserResolveListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\EventListener;

Expand Down
1 change: 1 addition & 0 deletions GraphQL/AllowList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct($allows)
public function isAllowed($entityName, $propertyName)
{
$allowProperties = $this->allows[$entityName] ?? [];

return in_array($propertyName, $allowProperties, true);
}
}
12 changes: 10 additions & 2 deletions GraphQL/Error/FormInvalidException.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Error;


use GraphQL\Error\ClientAware;

class FormInvalidException extends \Exception implements ClientAware
{

public function isClientSafe()
{
return true;
Expand Down
1 change: 0 additions & 1 deletion GraphQL/Type/EdgeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Plugin\Api\GraphQL\Type;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Plugin\Api\GraphQL\Types;

class EdgeType extends ObjectType
Expand Down
1 change: 0 additions & 1 deletion PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\ORM\EntityManager;
use Eccube\Entity\AuthorityRole;
use Eccube\Entity\Master\Authority;
use Eccube\Entity\Member;
use Eccube\Plugin\AbstractPluginManager;
use Eccube\Repository\AuthorityRoleRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file that was distributed with this source code.
#}
{% extends '@admin/default_frame.twig' %}

{% set menus = ['setting', 'system', 'api_oauth'] %}
{% set menus = ['setting', 'api', 'oauth'] %}

{% block title %}{{ 'api.admin.oauth.client_registration'|trans }}{% endblock %}
{% block sub_title %}{{ 'api.admin.management'|trans }}{% endblock %}
Expand Down Expand Up @@ -125,7 +125,7 @@ file that was distributed with this source code.
<div class="col-6">
<div class="c-conversionArea__leftBlockItem">
<a class="c-baseLink"
href="{{ url('api_admin_setting_system_oauth') }}">
href="{{ url('admin_api_oauth') }}">
<i class="fa fa-backward" aria-hidden="true"></i>
<span>{{ 'api.admin.oauth.management'|trans }}</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file that was distributed with this source code.
#}
{% extends '@admin/default_frame.twig' %}

{% set menus = ['setting', 'system', 'api_oauth'] %}
{% set menus = ['setting', 'api', 'oauth'] %}

{% block title %}{{ 'api.admin.oauth.management'|trans }}{% endblock %}
{% block sub_title %}{{ 'api.admin.management'|trans }}{% endblock %}
Expand All @@ -20,7 +20,7 @@ file that was distributed with this source code.
<div class="c-contentsArea__primaryCol">
<div class="c-primaryCol">
<div id="create-client" class="d-block mb-3">
<a class="btn btn-ec-regular" href="{{ url('api_admin_setting_oauth_create_client') }}">{{ 'admin.common.registration__new'|trans }}</a>
<a class="btn btn-ec-regular" href="{{ url('admin_api_oauth_new') }}">{{ 'admin.common.registration__new'|trans }}</a>
</div>
<div class="card rounded border-0 mb-4">
<div class="card-body p-0">
Expand Down Expand Up @@ -98,7 +98,7 @@ file that was distributed with this source code.
<button class="btn btn-ec-sub" type="button" data-dismiss="modal">
{{ 'admin.common.cancel'|trans }}
</button>
<a class="btn btn-ec-delete" href="{{ url('api_admin_setting_oauth_delete_client', {identifier: client.identifier}) }}"
<a class="btn btn-ec-delete" href="{{ url('admin_api_oauth_delete', {identifier: client.identifier}) }}"
{{ csrf_token_for_anchor() }} data-method="delete" data-confirm="false">
{{ 'admin.common.delete'|trans }}
</a>
Expand All @@ -116,7 +116,7 @@ file that was distributed with this source code.
</div>
</div>
<div class="card rounded border-0 mb-4">
<a class="btn btn-ec-conversion ladda-button" href="{{ url('api_admin_setting_oauth_clear_expired_tokens') }}"
<a class="btn btn-ec-conversion ladda-button" href="{{ url('admin_api_oauth_clear_expired_tokens') }}"
{{ csrf_token_for_anchor() }} data-method="delete" data-confirm="false">
{{ 'api.admin.oauth.clear_expired_tokens'|trans }}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\Tests\Web\Admin\OAuth2;
namespace Plugin\Api\Tests\Web\Admin\OAuth2Bundle;

use Eccube\Common\Constant;
use Eccube\Tests\Web\Admin\AbstractAdminWebTestCase;
use Trikoder\Bundle\OAuth2Bundle\Model\Client;

class OAuth2ControllerTest extends AbstractAdminWebTestCase
class AuthorizationControllerTest extends AbstractAdminWebTestCase
{
public function setUp()
{
Expand All @@ -37,7 +37,7 @@ public function testRoutingAdminOauth2Authorize_ログインしている場合
'redirect_uri' => (string) current($Client->getRedirectUris()),
'response_type' => 'code',
'scope' => 'read',
'state' => 'xxx'
'state' => 'xxx',
]
)
);
Expand All @@ -60,7 +60,7 @@ public function testRoutingAdminOauth2Authorize_権限移譲を許可()
'redirect_uri' => (string) current($Client->getRedirectUris()),
'response_type' => 'code',
'scope' => 'read',
'state' => 'xxx'
'state' => 'xxx',
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* file that was distributed with this source code.
*/

namespace Api\Tests\Web\Admin\Setting\System;
namespace Plugin\Api\Tests\Web\Admin;

use Eccube\Tests\Web\Admin\AbstractAdminWebTestCase;
use Trikoder\Bundle\OAuth2Bundle\Manager\Doctrine\ClientManager;
use Trikoder\Bundle\OAuth2Bundle\Model\Client;

class OAuth2ClientControllerTest extends AbstractAdminWebTestCase
class OAuthControllerTest extends AbstractAdminWebTestCase
{
/**
* @var ClientManager
Expand All @@ -36,13 +36,13 @@ public function setUp()

public function testRoutingAdminSettingSystemOAuth2Client()
{
$this->client->request('GET', $this->generateUrl('api_admin_setting_system_oauth'));
$this->client->request('GET', $this->generateUrl('admin_api_oauth'));
$this->assertTrue($this->client->getResponse()->isSuccessful());
}

public function testRoutingAdminSettingSystemOAuth2ClientCreate()
{
$this->client->request('GET', $this->generateUrl('api_admin_setting_oauth_create_client'));
$this->client->request('GET', $this->generateUrl('admin_api_oauth_new'));
$this->assertTrue($this->client->getResponse()->isSuccessful());
}

Expand All @@ -55,9 +55,9 @@ public function testRoutingAdminSettingSystemOAuth2ClientDelete()
$this->clientManager->save($client);

// main
$redirectUrl = $this->generateUrl('api_admin_setting_system_oauth');
$redirectUrl = $this->generateUrl('admin_api_oauth');
$this->client->request('DELETE',
$this->generateUrl('api_admin_setting_oauth_delete_client', ['identifier' => $identifier])
$this->generateUrl('admin_api_oauth_delete', ['identifier' => $identifier])
);
$this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl));
$this->assertNull($this->clientManager->find($identifier));
Expand All @@ -73,15 +73,15 @@ public function testOAuth2ClientCreateSubmit()

// main
$this->client->request('POST',
$this->generateUrl('api_admin_setting_oauth_create_client'),
$this->generateUrl('admin_api_oauth_new'),
[
'api_admin_client' => $formData,
]
);

$client = $this->clientManager->find($formData['identifier']);

$redirectUrl = $this->generateUrl('api_admin_setting_system_oauth');
$redirectUrl = $this->generateUrl('admin_api_oauth');
$this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl));

$this->actual = $client->getIdentifier();
Expand All @@ -100,7 +100,7 @@ public function testOAuth2ClientCreateSubmitFail()

// main
$crawler = $this->client->request('POST',
$this->generateUrl('api_admin_setting_oauth_create_client'),
$this->generateUrl('admin_api_oauth_new'),
[
'api_admin_client' => $formData,
]
Expand All @@ -117,9 +117,9 @@ public function testOAuth2ClientDeleteIdentifierNotFound()
$identifier = hash('md5', random_bytes(16));

// main
$redirectUrl = $this->generateUrl('api_admin_setting_system_oauth');
$redirectUrl = $this->generateUrl('admin_api_oauth');
$this->client->request('DELETE',
$this->generateUrl('api_admin_setting_oauth_delete_client', ['identifier' => $identifier])
$this->generateUrl('admin_api_oauth_delete', ['identifier' => $identifier])
);

$this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl));
Expand Down