From 519bc7e5b4fb8ac6b1ff87a347b78a2ee1d1927c Mon Sep 17 00:00:00 2001 From: Benjamin Serfhos Date: Wed, 24 Oct 2018 10:09:22 +0200 Subject: [PATCH] [BUGFIX] Inherit access groups from parent pages when extended to subpages --- .../Domain/Index/TcaIndexer/PagesIndexer.php | 46 +++++++++++++++++++ .../Index/TcaIndexer/TcaTableService.php | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php index ebee56c..89b2e13 100644 --- a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php +++ b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php @@ -25,6 +25,8 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Connection\ConnectionInterface; use Codappix\SearchCore\Domain\Index\TcaIndexer; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\RootlineUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; /** * Specific indexer for Pages, will basically add content of page. @@ -65,6 +67,9 @@ class PagesIndexer extends TcaIndexer { parent::prepareRecord($record); + // Override access from parent rootline + $record['search_access'] = $this->fetchAccess($record['uid'], $record['search_access']); + $possibleTitleFields = ['nav_title', 'tx_tqseo_pagetitle_rel', 'title']; foreach ($possibleTitleFields as $searchTitleField) { if (isset($record[$searchTitleField]) && trim($record[$searchTitleField])) { @@ -148,6 +153,47 @@ class PagesIndexer extends TcaIndexer return $this->fetchSysFileReferenceUids($uid, 'pages', 'media'); } + /** + * @param integer $uid + * @param array $pageAccess + * @return array + */ + protected function fetchAccess(int $uid, array $pageAccess): array + { + try { + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $rootline = $objectManager->get(RootlineUtility::class, $uid)->get(); + } catch (\RuntimeException $e) { + $this->logger->notice( + sprintf('Could not fetch rootline for page %u, because: %s', $uid, $e->getMessage()), + [$pageAccess, $e] + ); + return $pageAccess; + } + + $access = [$pageAccess]; + $extended = false; + foreach ($rootline as $pageInRootLine) { + if ($pageInRootLine['extendToSubpages'] && (!empty($pageInRootLine['fe_group']))) { + $extended = true; + $access[] = GeneralUtility::intExplode( + ',', + $pageInRootLine['fe_group'], + true + ); + } + } + + // Return combined rootline extended access and return unique id's + $access = array_unique(array_merge(...$access)); + + // Remove public value if fe_group is extended to this page + if ($extended && ($key = array_search(0, $access, true)) !== false) { + unset($access[$key]); + } + return array_values($access); + } + /** * @param integer $uid * @param string $tablename diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index 6b2514c..2125a73 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -171,7 +171,8 @@ class TcaTableService implements TcaTableServiceInterface if (isset($record[$this->tca['ctrl']['label']]) && !isset($record['search_title'])) { $record['search_title'] = $record[$this->tca['ctrl']['label']]; } - if (isset($this->tca['ctrl']['enablecolumns']['fe_group']) && isset($record[$this->tca['ctrl']['enablecolumns']['fe_group']])) { + + if (isset($this->tca['ctrl']['enablecolumns']['fe_group'], $record[$this->tca['ctrl']['enablecolumns']['fe_group']])) { $groups = GeneralUtility::intExplode( ',', $record[$this->tca['ctrl']['enablecolumns']['fe_group']],