Skip to content
Snippets Groups Projects
Commit 85ca36a5 authored by Susanne Moog's avatar Susanne Moog Committed by Daniel Goerz
Browse files

[TASK] Set pseudo user when simulating a user group

Simulating a user group had no user set, which resulted in some things
not being simulated (for example the fluid `role` and `authenticated`
view helpers).

As the expectation just includes a `uid` > 0, we are now setting
`uid=1` for the simulated user. However, the long term solution for
future versions should be replacing the usergroup simulation by a
simulation of a concrete user (like impersonating is done in the
backend).

Resolves: #90773
Releases: master, 9.5
Change-Id: Idf380607921184edf50ab784ffa309e864e754f2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63794


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: default avatarHenrik Ziegenhain <henrik@ziegenhain.me>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 3699485e
No related merge requests found
......@@ -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]
)
);
......
......@@ -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');
......
......@@ -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(
......
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