Issue Bug Closed

#96381Frontend preview doesn't work on restricted pages

Juergen Kussmann 12/17/21, 13:04 updated 10/04/22, 14:17

Description

The frontend-preview of restricted pages doesn’t work.

An example:
The TYPO3-page ‘mytypo3page’ is restricted by the fe_groups-record with UID 4884. When i click the frontend-preview-button in the TYPO3-backend-module ‘page’, than
TYPO3 is calling this URL:
https://mytypo3domain.com/mytypo3page?ADMCMD_simUser=4884

The result in an 404-pageNotFound-error, because of this:
1. TYPO3\CMS\Frontend\Middleware\PreviewSimulator::simulateUserGroup will create the aspect ‘frontend.user’ (with an logged-in FE-user).
2. Later (during the FE-rendering) TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::fetch_the_id will initialize the FE-userGroups, by calling ‘$this->initUserGroups()’.
3. TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::initUserGroups overrides the already existing aspect ‘frontend.user’ (with an ‘empty’ FE-user).

So, we must fix the bug in TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::initUserGroups:

    public function initUserGroups()
    {
        if ($this->isInPreviewMode() &&
            $this->context->getAspect('frontend.user')->isLoggedIn() ) {
            // do NOT create userAspect! Because that would overwrite the already
            // existing userAspect, which was created in TYPO3\CMS\Frontend\Middleware\PreviewSimulator::process()
            return;
        }
        $userAspect = $this->fe_user->createUserAspect((bool)$this->loginAllowedInBranch);
        $this->context->setAspect('frontend.user', $userAspect);
    }

Reviews 4