diff --git a/Classes/Service/AccessControlService.php b/Classes/Service/AccessControlService.php index 0ad4cdfd..57b5100c 100644 --- a/Classes/Service/AccessControlService.php +++ b/Classes/Service/AccessControlService.php @@ -5,7 +5,6 @@ use Thucke\ThRating\Exception\FeUserNotFoundException; use TYPO3\CMS\Core\Context\Context; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use \Thucke\ThRating\Domain\Model\Voter; @@ -68,6 +67,18 @@ public function injectVoterRepository(\Thucke\ThRating\Domain\Repository\VoterRe $this->voterRepository = $voterRepository; } + /** + * @var \TYPO3\CMS\Core\Context\Context $context + */ + protected $context; + /** + * @param \TYPO3\CMS\Core\Context\Context $context + */ + public function injectContext(\TYPO3\CMS\Core\Context\Context $context): void + { + $this->context = $context; + } + /** * Tests, if the given person is logged into the frontend * @@ -86,7 +97,6 @@ public function isLoggedIn(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $person return true; //treat anonymous user also as logged in } } - return false; } @@ -96,9 +106,7 @@ public function isLoggedIn(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $person */ public function backendAdminIsLoggedIn(): bool { - /** @var Context $context */ - $context = GeneralUtility::makeInstance(Context::class, null); - return $context->getPropertyFromAspect('backend.user', 'isLoggedIn'); + return $this->context->getPropertyFromAspect('backend.user', 'isLoggedIn'); } /** @@ -108,8 +116,7 @@ public function backendAdminIsLoggedIn(): bool public function hasLoggedInFrontendUser(): bool { /** @var Context $context */ - $context = GeneralUtility::makeInstance(Context::class, array()); - return $context->getPropertyFromAspect('frontend.user', 'isLoggedIn'); + return $this->context->getPropertyFromAspect('frontend.user', 'isLoggedIn'); } /** @@ -119,9 +126,8 @@ public function hasLoggedInFrontendUser(): bool public function getFrontendUserGroups(): array { if ($this->hasLoggedInFrontendUser()) { - return $GLOBALS['TSFE']->fe_user->groupData['uid']; + return $this->context->getPropertyFromAspect('frontend.user', 'groupIds'); } - return []; } @@ -131,8 +137,8 @@ public function getFrontendUserGroups(): array */ public function getFrontendUserUid(): ?int { - if ($this->hasLoggedInFrontendUser() && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) { - return (int)$GLOBALS['TSFE']->fe_user->user['uid']; + if ($this->hasLoggedInFrontendUser()) { + return $this->context->getPropertyFromAspect('frontend.user', 'id'); } return null; } diff --git a/ext_emconf.php b/ext_emconf.php index 547e92bb..f3ba48ef 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -12,7 +12,7 @@ 'title' => 'Rating AX', 'description' => 'Highly flexible AJAX rating based on extbase/fluid/jquery. Allows multiple ratings within one page. Could be used as a cObj by other extensions or included in every FLUID template using the viewhelper. Each ratingstep could be configured having a name - international localization included.', 'category' => 'misc', - 'version' => '1.8.2', + 'version' => '1.8.3', 'state' => 'stable', 'uploadfolder' => false, 'createDirs' => '',