Skip to content
Snippets Groups Projects
Commit 40d0c292 authored by Susanne Moog's avatar Susanne Moog Committed by Christian Kuhn
Browse files

[BUGFIX] Initialize AdminPanel only if enabled by user

The admin panel can be disabled via the frontend UI by
click. When the admin panel is disabled the initialize
methods should not be called. This has been fixed.

Resolves: #85104
Releases: master
Change-Id: I966b5887b03b4fb8d3f63e9556b00a37384f9dfc
Reviewed-on: https://review.typo3.org/57077


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 629bd4cc
Branches
Tags
No related merge requests found
...@@ -43,13 +43,15 @@ class AdminPanelInitiator implements MiddlewareInterface ...@@ -43,13 +43,15 @@ class AdminPanelInitiator implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{ {
if ($GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) { if ($GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) {
// Initialize admin panel since simulation settings are required here
$beUser = $GLOBALS['BE_USER']; $beUser = $GLOBALS['BE_USER'];
// set legacy config // set legacy config
$beUser->extAdminConfig = $beUser->getTSConfig()['admPanel.'] ?? []; $beUser->extAdminConfig = $beUser->getTSConfig()['admPanel.'] ?? [];
$adminPanelConfiguration = $beUser->extAdminConfig; $adminPanelConfiguration = $beUser->extAdminConfig;
if (isset($adminPanelConfiguration['enable.'])) { if (isset($adminPanelConfiguration['enable.']) &&
($beUser->uc['TSFE_adminConfig']['display_top'] ?? false) &&
($GLOBALS['TSFE']->config['config']['admPanel'] ?? false)
) {
// only initialize if at least one module is enabled.
foreach ($adminPanelConfiguration['enable.'] as $value) { foreach ($adminPanelConfiguration['enable.'] as $value) {
if ($value) { if ($value) {
$adminPanelController = GeneralUtility::makeInstance( $adminPanelController = GeneralUtility::makeInstance(
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Tests\Unit\Middleware;
use Prophecy\Argument;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Adminpanel\Controller\MainController;
use TYPO3\CMS\Adminpanel\Middleware\AdminPanelInitiator;
use TYPO3\CMS\Adminpanel\View\AdminPanelView;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class AdminPanelInitiatorTest extends UnitTestCase
{
/**
* @test
*/
public function processCallsInitialize(): void
{
$tsConfig = [
'admPanel.' => [
'enable.' => [
'all',
],
],
];
$uc = [
'TSFE_adminConfig' => [
'display_top' => true
]
];
$typoScript = [
'config' => [
'admPanel' => 1
]
];
$userAuthentication = $this->prophesize(FrontendBackendUserAuthentication::class);
$userAuthentication->getTSConfig(Argument::any())->willReturn($tsConfig);
$userAuthentication->uc = $uc;
$GLOBALS['BE_USER'] = $userAuthentication->reveal();
$tsfe = $this->prophesize(TypoScriptFrontendController::class);
$tsfe->config = $typoScript;
$GLOBALS['TSFE'] = $tsfe;
$controller = $this->prophesize(MainController::class);
GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
GeneralUtility::addInstance(AdminPanelView::class, $this->prophesize(AdminPanelView::class)->reveal());
$handler = $this->prophesizeHandler();
$request = $this->prophesize(ServerRequest::class);
// Act
$adminPanelInitiator = new AdminPanelInitiator();
$adminPanelInitiator->process(
$request->reveal(),
$handler->reveal()
);
// Assert
$controller->initialize(Argument::any())->shouldHaveBeenCalled();
}
/**
* @test
*/
public function processDoesNotCallInitializeIfAdminPanelIsNotEnabledInTypoScript(): void
{
$tsConfig = [
'admPanel.' => [
'enable.' => [
'all',
],
],
];
$uc = [
'TSFE_adminConfig' => [
'display_top' => true
]
];
$typoScript = [
'config' => [
'admPanel' => 0
]
];
$this->checkAdminPanelDoesNotCallInitialize($tsConfig, $uc, $typoScript);
}
/**
* @test
*/
public function processDoesNotCallInitializeIfAdminPanelIsNotEnabledInUC(): void
{
$tsConfig = [
'admPanel.' => [
'enable.' => [
'all',
],
],
];
$uc = [
'TSFE_adminConfig' => [
'display_top' => false
]
];
$typoScript = [
'config' => [
'admPanel' => 1
]
];
$this->checkAdminPanelDoesNotCallInitialize($tsConfig, $uc, $typoScript);
}
/**
* @test
*/
public function processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled(): void
{
$tsConfig = [
'admPanel.' => [],
];
$uc = [
'TSFE_adminConfig' => [
'display_top' => true
]
];
$typoScript = [
'config' => [
'admPanel' => 1
]
];
$this->checkAdminPanelDoesNotCallInitialize($tsConfig, $uc, $typoScript);
}
/**
* @param $tsConfig
* @param $uc
* @param $typoScript
*/
protected function checkAdminPanelDoesNotCallInitialize($tsConfig, $uc, $typoScript): void
{
$userAuthentication = $this->prophesize(FrontendBackendUserAuthentication::class);
$userAuthentication->getTSConfig(Argument::any())->willReturn($tsConfig);
$userAuthentication->uc = $uc;
$GLOBALS['BE_USER'] = $userAuthentication->reveal();
$tsfe = $this->prophesize(TypoScriptFrontendController::class);
$tsfe->config = $typoScript;
$GLOBALS['TSFE'] = $tsfe;
$controller = $this->prophesize(MainController::class);
GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal());
$handler = $this->prophesizeHandler();
$request = $this->prophesize(ServerRequest::class);
// Act
$adminPanelInitiator = new AdminPanelInitiator();
$adminPanelInitiator->process(
$request->reveal(),
$handler->reveal()
);
// Assert
$controller->initialize(Argument::any())->shouldNotHaveBeenCalled();
}
/**
* @return \Prophecy\Prophecy\ObjectProphecy|\Psr\Http\Server\RequestHandlerInterface
*/
protected function prophesizeHandler()
{
$handler = $this->prophesize(RequestHandlerInterface::class);
$handler
->handle(Argument::any())
->willReturn(
$this->prophesize(ResponseInterface::class)->reveal()
);
return $handler;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment