Skip to content

Commit

Permalink
Merge pull request #5233 from nanasess/feature/traverse-maintenance
Browse files Browse the repository at this point in the history
管理者はメンテナンスモードを回避可能に変更
  • Loading branch information
chihiro-adachi authored Jan 27, 2022
2 parents 0e60516 + 8ff8719 commit 4a202ca
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/config/eccube/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ security:
failure_handler: eccube.security.failure_handler
logout:
path: admin_logout
target: admin_login
success_handler: eccube.security.logout.success_handler
customer:
pattern: ^/
anonymous: true
Expand Down
7 changes: 7 additions & 0 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ services:
eccube.security.failure_handler:
class: Eccube\Security\Http\Authentication\EccubeAuthenticationFailureHandler

eccube.security.logout.success_handler:
class: Eccube\Security\Http\Authentication\EccubeLogoutSuccessHandler
arguments:
- '@security.http_utils'
- '@Eccube\Request\Context'
- 'admin_login'

# Autowiring can't guess the constructor arguments that are not type-hinted with
# classes (e.g. container parameters) so you must define those arguments explicitly
# Eccube\Command\ListUsersCommand:
Expand Down
41 changes: 41 additions & 0 deletions codeception/_support/Page/Admin/MaintenanceManagePage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 Page\Admin;

class MaintenanceManagePage extends AbstractAdminPageStyleGuide
{
public static $完了メッセージ = '#page_admin_content_maintenance > div.c-container > div.c-contentsArea > div.alert.alert-success.alert-dismissible.fade.show.m-3 > span';

/**
* MaintenanceManagePage constructor.
*/
public function __construct(\AcceptanceTester $I)
{
parent::__construct($I);
}

public static function go($I)
{
$page = new self($I);

return $page->goPage('/content/maintenance', 'メンテナンス管理コンテンツ管理');
}

public function メンテナンス有効無効()
{
$this->tester->click('#page_admin_content_maintenance > div.c-container > div.c-contentsArea > form > div > div > div > div > div.card-body > div:nth-child(2) > div > button');

return $this;
}
}
45 changes: 45 additions & 0 deletions codeception/acceptance/EA06ContentsManagementCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
use Page\Admin\LayoutManagePage;
use Page\Admin\NewsEditPage;
use Page\Admin\NewsManagePage;
use Page\Admin\MaintenanceManagePage;
use Page\Admin\PageEditPage;
use Page\Admin\PageManagePage;
use Page\Front\TopPage;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

Expand Down Expand Up @@ -367,4 +369,47 @@ public function contentsmanagement_ブロック管理(AcceptanceTester $I)
$I->amOnPage('/');
$I->dontSeeElement(['id' => $block]);
}

public function contentsmanagement_メンテナンス管理(AcceptanceTester $I)
{
$I->wantTo('EA0607-UC08-T01_メンテナンス管理');

$I->expect('メンテナンスモードを有効にします');
MaintenanceManagePage::go($I)
->メンテナンス有効無効();
$I->see('メンテナンスモードを有効にしました。', MaintenanceManagePage::$完了メッセージ);

$I->expect('トップページを確認します');
$I->amOnPage('/');
$I->see('メンテナンスモードが有効になっています。', '#page_homepage > div.ec-maintenanceAlert > div');
$I->see('全ての商品', TopPage::$検索_カテゴリ選択);

$I->expect('ログアウトします');
$config = Fixtures::get('config');
$I->amOnPage('/'.$config['eccube_admin_route'].'/logout');

$I->expect('トップページを確認します');
$I->amOnPage('/');
$I->dontSee('メンテナンスモードが有効になっています。', '#page_homepage > div.ec-maintenanceAlert > div');
$I->see('ただいまメンテナンス中です。', 'body > div > div > div > div > p.ec-404Role__title.ec-reportHeading');

// 画面遷移がスムーズにいかない場合があるため、ログイン画面に遷移させておく
$account = Fixtures::get('admin_account');
$I->amOnPage('/'.$config['eccube_admin_route'].'/login');
$I->submitForm('#form1', [
'login_id' => $account['member'],
'password' => $account['password'],
]);

$I->expect('メンテナンスモードを無効にします');

MaintenanceManagePage::go($I)
->メンテナンス有効無効();
$I->see('メンテナンスモードを無効にしました。', MaintenanceManagePage::$完了メッセージ);

$I->expect('トップページを確認します');
$I->amOnPage('/');
$I->dontSee('メンテナンスモードが有効になっています。', '#page_homepage > div.ec-maintenanceAlert > div');
$I->see('全ての商品', TopPage::$検索_カテゴリ選択);
}
}
22 changes: 22 additions & 0 deletions html/template/default/assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions html/template/default/assets/scss/project/_11.2.header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,30 @@ Styleguide 11.2.7
.ec-itemNavAccordion {
display: none;
}

.ec-maintenanceAlert {
background: steelblue;
height: 5rem;
position: fixed;
top: 0;
width: 100%;
color: white;
z-index: 9999;
display: flex;
font-weight: bold;
& > * {
margin: auto;
}
& &__icon {
display: inline-block;
margin-right: 1rem;
width: 20px;
height: 20px;
color: #fff;
fill: #fff;
vertical-align: top;
}
& +* {
margin-top: 5rem;
}
}
20 changes: 13 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Eccube\Kernel;
use Eccube\Service\SystemService;
use Symfony\Component\Debug\Debug;
use Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -62,13 +63,18 @@
$adminPath = env('ECCUBE_ADMIN_ROUTE', 'admin');
$adminPath = '/'.\trim($adminPath, '/').'/';
if (\strpos($pathInfo, $adminPath) !== 0) {
$locale = env('ECCUBE_LOCALE');
$templateCode = env('ECCUBE_TEMPLATE_CODE');
$baseUrl = \htmlspecialchars(\rawurldecode($request->getBaseUrl()), ENT_QUOTES);

header('HTTP/1.1 503 Service Temporarily Unavailable');
require __DIR__.'/maintenance.php';
return;
$maintenanceContents = file_get_contents($maintenanceFile);
$maintenanceToken = explode(':', $maintenanceContents)[1] ?? null;
$tokenInCookie = $request->cookies->get(SystemService::MAINTENANCE_TOKEN_KEY);
if ($tokenInCookie === null || $tokenInCookie !== $maintenanceToken) {
$locale = env('ECCUBE_LOCALE');
$templateCode = env('ECCUBE_TEMPLATE_CODE');
$baseUrl = \htmlspecialchars(\rawurldecode($request->getBaseUrl()), ENT_QUOTES);

header('HTTP/1.1 503 Service Temporarily Unavailable');
require __DIR__.'/maintenance.php';
return;
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/Eccube/Controller/Admin/Content/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@ public function index(Request $request)

if ($form->isSubmitted() && $form->isValid()) {
$changeTo = $request->request->get('maintenance');
$path = $this->container->getParameter('eccube_content_maintenance_file_path');

if ($isMaintenance === false && $changeTo == 'on') {
// 現在メンテナンスモードではない かつ メンテナンスモードを有効 にした場合
// メンテナンスモードを有効にする
file_put_contents($path, null);

$this->systemService->enableMaintenance('', true);
$this->addSuccess('admin.content.maintenance_switch__on_message', 'admin');
} elseif ($isMaintenance && $changeTo == 'off') {
// 現在メンテナンスモード かつ メンテナンスモードを無効 にした場合
// メンテナンスモードを無効にする
unlink($path);
$this->systemService->disableMaintenanceNow('', true);

$this->addSuccess('admin.content.maintenance_switch__off_message', 'admin');
}
Expand Down
64 changes: 64 additions & 0 deletions src/Eccube/EventListener/MaintenanceListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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 Eccube\EventListener;

use Eccube\Entity;
use Eccube\Request\Context;
use Eccube\Service\SystemService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class MaintenanceListener implements EventSubscriberInterface
{

/** @var Context */
protected $requestContext;

/** @var SystemService */
protected $systemService;

public function __construct(Context $requestContext, SystemService $systemService)
{
$this->requestContext = $requestContext;
$this->systemService = $systemService;
}

public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => ['onResponse'],
];
}

public function onResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();

if (!$this->systemService->isMaintenanceMode()) {
$response->headers->clearCookie(SystemService::MAINTENANCE_TOKEN_KEY);
return;
}

$user = $this->requestContext->getCurrentUser();
if ($user instanceof Entity\Member && $this->requestContext->isAdmin()) {
$cookie = new Cookie(
SystemService::MAINTENANCE_TOKEN_KEY,
$this->systemService->getMaintenanceToken()
);
$response->headers->setCookie($cookie);
}
}
}
35 changes: 12 additions & 23 deletions src/Eccube/EventListener/TwigInitializeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
use Eccube\Entity\PageLayout;
use Eccube\Repository\AuthorityRoleRepository;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\BlockPositionRepository;
use Eccube\Repository\LayoutRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\PageRepository;
use Eccube\Repository\PageLayoutRepository;
use Eccube\Repository\BlockPositionRepository;
use Eccube\Repository\PageRepository;
use Eccube\Request\Context;
use Eccube\Service\SystemService;
use SunCat\MobileDetectBundle\DeviceDetector\MobileDetector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
Expand Down Expand Up @@ -103,21 +104,13 @@ class TwigInitializeListener implements EventSubscriberInterface
*/
private $layoutRepository;

/**
* @var SystemService
*/
protected $systemService;

/**
* TwigInitializeListener constructor.
*
* @param Environment $twig
* @param BaseInfoRepository $baseInfoRepository
* @param PageRepository $pageRepository
* @param PageLayoutRepository $pageLayoutRepository
* @param BlockPositionRepository $blockPositionRepository
* @param DeviceTypeRepository $deviceTypeRepository
* @param AuthorityRoleRepository $authorityRoleRepository
* @param EccubeConfig $eccubeConfig
* @param Context $context
* @param MobileDetector $mobileDetector
* @param UrlGeneratorInterface $router
* @param LayoutRepository $layoutRepository
*/
public function __construct(
Environment $twig,
Expand All @@ -131,7 +124,8 @@ public function __construct(
Context $context,
MobileDetector $mobileDetector,
UrlGeneratorInterface $router,
LayoutRepository $layoutRepository
LayoutRepository $layoutRepository,
SystemService $systemService
) {
$this->twig = $twig;
$this->baseInfoRepository = $baseInfoRepository;
Expand All @@ -145,11 +139,10 @@ public function __construct(
$this->mobileDetector = $mobileDetector;
$this->router = $router;
$this->layoutRepository = $layoutRepository;
$this->systemService = $systemService;
}

/**
* @param GetResponseEvent $event
*
* @throws NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
Expand All @@ -171,8 +164,6 @@ public function onKernelRequest(GetResponseEvent $event)
}

/**
* @param GetResponseEvent $event
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function setFrontVariables(GetResponseEvent $event)
Expand Down Expand Up @@ -243,11 +234,9 @@ public function setFrontVariables(GetResponseEvent $event)
$this->twig->addGlobal('Layout', $Layout);
$this->twig->addGlobal('Page', $Page);
$this->twig->addGlobal('title', $Page->getName());
$this->twig->addGlobal('isMaintenance', $this->systemService->isMaintenanceMode());
}

/**
* @param GetResponseEvent $event
*/
public function setAdminGlobals(GetResponseEvent $event)
{
// メニュー表示用配列.
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ front.shopping.payment_total_invalid: The total amount is invalid.
front.shopping.different_payment_methods: Sorry, your order includes items with different purchase methods, which are unable to be processed in one order.
front.shopping.payment_method_unselected: Please select the payment method.
front.shopping.payment_method_not_fount: Sorry, you have no payment options. If you have selected multiple delivery methods, you can only select the same payment option for them all.
front.under_maintenance: The site is currently under maintenance.

#====================================================================================
# Admin Console
Expand Down
Loading

0 comments on commit 4a202ca

Please sign in to comment.