diff --git a/Classes/Service/AuthService.php b/Classes/Service/AuthService.php deleted file mode 100644 index e1e37d47fc8f8cdbb5d7f9c563d743f63deca531..0000000000000000000000000000000000000000 --- a/Classes/Service/AuthService.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - - -namespace NL\NlMenubuilder\Service; - - -use TYPO3\CMS\Core\Context\AspectInterface; -use TYPO3\CMS\Core\Context\Context; -use TYPO3\CMS\Core\SingletonInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Domain\Model\FrontendUser; -use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository; - -class AuthService implements SingletonInterface -{ - /** - * @var FrontendUserRepository - */ - protected $userRepository = null; - - /** - * @param FrontendUserRepository $repository - */ - public function injectUserRepository(FrontendUserRepository $repository): void - { - $this->userRepository = $repository; - } - - /** - * @throws \TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException - */ - public function getUser(): ?FrontendUser - { - $id = $this->getPropertyFromAspect('id'); - - return $id ? $this->userRepository->findByUid($id) : null; - } - - /** - * @return bool - * @throws \TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException - */ - public function isLoggedIn(): bool - { - return (bool) $this->getPropertyFromAspect('isLoggedIn'); - } - - /** - * @param string $property - * @return mixed - * @throws \TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException - */ - protected function getPropertyFromAspect(string $property) - { - return $this->getAspect()->get($property); - } - - /** - * @return object|\Psr\Log\LoggerAwareInterface|SingletonInterface - */ - protected function getAspect(): AspectInterface - { - return GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user'); - } -} diff --git a/Classes/Service/MenuSecurityService.php b/Classes/Service/MenuSecurityService.php index 3658d5d3c3bc71ce6eed955c51829326cd5f3a6f..6048a9eade0747a2995e5fb9ec615b172afaf5f5 100644 --- a/Classes/Service/MenuSecurityService.php +++ b/Classes/Service/MenuSecurityService.php @@ -9,23 +9,11 @@ use NL\NlMenubuilder\Domain\Model\MenuItem; use NL\NlMenubuilder\Domain\Model\MenuItemPage; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Reflection\ObjectAccess; +use TYPO3\CMS\Core\Utility\RootlineUtility; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; class MenuSecurityService implements SingletonInterface { - /** - * @var AuthService - */ - protected $authService; - - /** - * @param AuthService $service - */ - public function injectAuthService(AuthService $service): void - { - $this->authService = $service; - } - /** * @param MenuInterface $menu * @throws \TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException @@ -63,7 +51,7 @@ class MenuSecurityService implements SingletonInterface foreach ($menu->getSubmenuItems() as $submenuItem) { $this->removeEmpty($submenuItem); - if (empty($submenuItem->getItems())) { + if (0 === $submenuItem->getItems()->count()) { $menu->removeItem($submenuItem); } } @@ -76,28 +64,27 @@ class MenuSecurityService implements SingletonInterface */ protected function isAccessible(MenuItemPage $itemPage): bool { - $feGroups = array_filter(GeneralUtility::intExplode( - ',', - ObjectAccess::getPropertyPath($itemPage, 'page.feGroup'), - true - )); - - if (empty($feGroups) || (in_array(-2, $feGroups) && $this->authService->isLoggedIn())) { - return true; - } - - if (in_array(-1, $feGroups) && $this->authService->isLoggedIn()) { + if (null === $itemPage->getPage()) { return false; } - if ($user = $this->authService->getUser()) { - foreach ($user->getUsergroup() as $group) { - if (in_array($group->getUid(), $feGroups)) { - return true; - } + /** @var RootlineUtility $rootline */ + $rootline = GeneralUtility::makeInstance(RootlineUtility::class, $itemPage->getPage()->getUid()); + + foreach ($rootline->get() as $item) { + if (!$this->getTypoScriptFrontendController()->checkPagerecordForIncludeSection($item)) { + return false; } } - return false; + return true; + } + + /** + * @return TypoScriptFrontendController + */ + protected function getTypoScriptFrontendController(): TypoScriptFrontendController + { + return $GLOBALS['TSFE']; } }