diff --git a/typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php b/typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php index 12317845156ad2ceb96d756a9ac642fa5af7ad16..e53a41944919c018189f3bc3d64ce2dce23ef219 100644 --- a/typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php +++ b/typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php @@ -93,7 +93,8 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface, $this->config['showHiddenPages'], $this->config['showHiddenRecords'], $this->config['simulateDate'], - $this->config['simulateUserGroup'] + $this->config['simulateUserGroup'], + $request ); return $request; @@ -155,13 +156,15 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface, * @param bool $showHiddenRecords * @param int $simulateDate * @param int $simulateUserGroup UID of the fe_group to simulate + * @param \Psr\Http\Message\ServerRequestInterface $request * @throws \Exception */ protected function initializeFrontendPreview( bool $showHiddenPages, bool $showHiddenRecords, int $simulateDate, - int $simulateUserGroup + int $simulateUserGroup, + ServerRequestInterface $request ): void { $context = GeneralUtility::makeInstance(Context::class); $this->clearPreviewSettings($context); @@ -193,11 +196,15 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface, } // simulate usergroup if ($simulateUserGroup) { + $frontendUser = $request->getAttribute('frontend.user'); + $frontendUser->user[$frontendUser->usergroup_column] = $simulateUserGroup; + // let's fake having a user with that group, too + $frontendUser->user['uid'] = 1337; $context->setAspect( 'frontend.user', GeneralUtility::makeInstance( UserAspect::class, - null, + $frontendUser, [$simulateUserGroup] ) ); diff --git a/typo3/sysext/adminpanel/Tests/Unit/Modules/PreviewModuleTest.php b/typo3/sysext/adminpanel/Tests/Unit/Modules/PreviewModuleTest.php index 40c0bdd1a128158f947039a92d040aced9509c57..c5253dbac90f42817241c4901a70d4132c074850 100644 --- a/typo3/sysext/adminpanel/Tests/Unit/Modules/PreviewModuleTest.php +++ b/typo3/sysext/adminpanel/Tests/Unit/Modules/PreviewModuleTest.php @@ -9,6 +9,7 @@ use TYPO3\CMS\Adminpanel\Modules\PreviewModule; use TYPO3\CMS\Adminpanel\Service\ConfigurationService; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class PreviewModuleTest extends UnitTestCase @@ -61,6 +62,8 @@ class PreviewModuleTest extends UnitTestCase { $this->resetSingletonInstances = true; $request = $this->prophesize(ServerRequestInterface::class); + $request->getQueryParams()->willReturn([]); + $request->getAttribute('frontend.user')->willReturn($this->prophesize(FrontendUserAuthentication::class)->reveal()); $configurationService = $this->prophesize(ConfigurationService::class); $configurationService->getMainConfiguration()->willReturn([]); $configurationService->getConfigurationOption('preview', 'showHiddenPages')->willReturn('0'); diff --git a/typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php b/typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php index f3754492041ce87363d9eb3c770e180cf158aec3..7ed7becb3e3f0a56f263ac9cfa6db432279aab60 100644 --- a/typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php +++ b/typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php @@ -122,6 +122,8 @@ class PreviewSimulator implements MiddlewareInterface $frontendUser = $request->getAttribute('frontend.user'); $frontendUser->user[$frontendUser->usergroup_column] = $simulateUserGroup; + // let's fake having a user with that group, too + $frontendUser->user['uid'] = 1; $this->context->setAspect( 'frontend.user', GeneralUtility::makeInstance(