Skip to content

Commit

Permalink
[FIX] access restrictions stack for TYPO3 13
Browse files Browse the repository at this point in the history
This change fixes the access restrictions stack within TYPO3 13.
There were multiple troubles in classes and in integration tests.
The page indexer stack on live system runs in multiple isolated processes:

1. CLI
2. first FE request to get FE-groups
3. multiple FE requests to get real content from page for desired FE-groups combination

unlike on integration test running the page indexer steps allways on single process. 
This requires to unset the produced state on each step of indexing process.
The runtime cache was interfering between the steps 
and did things that had nothing to do withhin the own step.

---

The main problem within access restriction stack on page indexing 
was the registration of Event-Listeners methods within `UserGroupDetector` with `#[AsEventListener]` on EXT:solr. 
Due of current troubles with circular dependencies 
the auto-wiring and auto-configuration was disabled in Servvices.yaml globally. 
It requires to enable this features manually for classes, which was done for `UserGroupDetector` class.

Relates: TYPO3-Solr#3995
Fixes: TYPO3-Solr#4146
  • Loading branch information
dkd-kaehm committed Sep 30, 2024
1 parent 111f684 commit 12b7af9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Classes/EventListener/PageIndexer/FrontendGroupsModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use ApacheSolrForTypo3\Solr\Access\Rootline;
use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\AuthorizationService;
use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\PageIndexer;
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use TYPO3\CMS\Core\Http\JsonResponse;
Expand All @@ -29,6 +30,8 @@
/**
* Class FrontendGroupsModifier is responsible to fake the fe_groups to make
* the indexing of access restricted pages and content elements.
*
* This class is involved only on {@link PageIndexer} processing.
*/
class FrontendGroupsModifier
{
Expand All @@ -40,7 +43,9 @@ class FrontendGroupsModifier
public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
{
$pageIndexerRequest = $event->getRequest()->getAttribute('solr.pageIndexingInstructions');
if (!$pageIndexerRequest instanceof PageIndexerRequest) {
if (
!$pageIndexerRequest instanceof PageIndexerRequest
|| !in_array(PageIndexer::ACTION_NAME, $pageIndexerRequest->getActions())) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/IndexQueue/FrontendHelper/PageIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@
*/
class PageIndexer implements FrontendHelper, SingletonInterface
{
public const ACTION_NAME = 'indexPage';

protected bool $activated = false;

/**
* This frontend helper's executed action.
*/
protected string $action = 'indexPage';
protected string $action = self::ACTION_NAME;

/**
* Index Queue page indexer request.
Expand Down
11 changes: 6 additions & 5 deletions Classes/IndexQueue/FrontendHelper/UserGroupDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
class UserGroupDetector implements FrontendHelper, SingletonInterface
{
public const ACTION_NAME = 'findUserGroups';

/**
* Index Queue page indexer request.
*/
Expand All @@ -42,7 +44,7 @@ class UserGroupDetector implements FrontendHelper, SingletonInterface
/**
* This frontend helper's executed action.
*/
protected string $action = 'findUserGroups';
protected string $action = self::ACTION_NAME;

/**
* Holds the original, unmodified TCA during user group detection
Expand Down Expand Up @@ -96,9 +98,8 @@ public function deactivateTcaFrontendGroupEnableFields(ModifyTypoScriptConfigEve
return;
}
if (empty($this->originalTca)) {
return;
$this->originalTca = $GLOBALS['TCA'];
}
$this->originalTca = $GLOBALS['TCA'];

foreach ($GLOBALS['TCA'] as $tableName => $tableConfiguration) {
if (isset($GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'])) {
Expand All @@ -117,8 +118,7 @@ public function deactivateTcaFrontendGroupEnableFields(ModifyTypoScriptConfigEve
public function getPage_preProcess(BeforePageIsRetrievedEvent $event): void
{
if ($this->activated) {
//$event->skipGroupAccessCheck();
$disableGroupAccessCheck = true;
$event->skipGroupAccessCheck();
}
}

Expand Down Expand Up @@ -227,6 +227,7 @@ protected function getFrontendGroups(): array
public function deactivate(PageIndexerResponse $response): void
{
$this->activated = false;
$GLOBALS['TCA'] = $this->originalTca;
$response->addActionResult($this->action, $this->getFrontendGroups());
}
}
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ services:
- name: event.listener
identifier: 'solr.index.PageFieldMappingIndexer'

ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\UserGroupDetector:
autowire: true
autoconfigure: true

ApacheSolrForTypo3\Solr\EventListener\Extbase\PersistenceEventListener:
autowire: true
tags:
Expand Down
12 changes: 7 additions & 5 deletions Tests/Integration/IndexQueue/PageIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Traversable;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;

Expand All @@ -50,14 +52,14 @@ protected function setUp(): void
page.10.stdWrap.dataWrap = <!--TYPO3SEARCH_begin-->|<!--TYPO3SEARCH_end-->
'
);
$this->cleanUpAllCoresOnSolrServerAndAssertEmpty();
}

/**
* Executed after each test. Emptys solr and checks if the index is empty
* Executed after each test. Empties solr and checks if the index is empty
*/
protected function tearDown(): void
{
$this->cleanUpAllCoresOnSolrServerAndAssertEmpty();
parent::tearDown();
}

Expand All @@ -73,9 +75,6 @@ public function canIndexPageWithAccessProtectedContentIntoSolr(
int $expectedNumFoundLoggedInUser,
string $core = 'core_en'
): void {
self::markTestSkipped('@todo: Fix it. See: https://github.com/TYPO3-Solr/ext-solr/issues/4161');

$this->cleanUpAllCoresOnSolrServerAndAssertEmpty();
$this->importCSVDataSet(__DIR__ . '/Fixtures/' . $fixture . '.csv');

$createPageIndexerMock = function(): PageIndexerRequest {
Expand Down Expand Up @@ -279,6 +278,9 @@ protected function sendPageIndexerRequest(string $url, PageIndexerRequest $reque
$indexerResponse->addActionResult($action, $actionResult);
}

/** @var VariableFrontend $runtimeCache */
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$runtimeCache->flush();
return $indexerResponse;
}
}
6 changes: 6 additions & 0 deletions Tests/Integration/IntegrationTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use ReflectionClass;
use ReflectionException;
use ReflectionObject;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
Expand Down Expand Up @@ -461,6 +463,10 @@ protected function executePageIndexer(string $url, Item $item, int $frontendUser
$requestContext = (new InternalRequestContext())->withFrontendUserId($frontendUserId);
}
$response = $this->executeFrontendSubRequest($request, $requestContext);
/** @var VariableFrontend $runtimeCache */
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$runtimeCache->flush();

$response->getBody()->rewind();
return $response;
}
Expand Down

0 comments on commit 12b7af9

Please sign in to comment.