diff --git a/Classes/Controller/UniversalMessengerController.php b/Classes/Controller/UniversalMessengerController.php index 4532de5..6ec30ea 100644 --- a/Classes/Controller/UniversalMessengerController.php +++ b/Classes/Controller/UniversalMessengerController.php @@ -17,7 +17,11 @@ use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Type\Bitmask\Permission; +use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Http\ForwardResponse; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Utility\DebuggerUtility; @@ -89,6 +93,14 @@ private function getBackendUserAuthentication(): BackendUserAuthentication return $GLOBALS['BE_USER']; } + /** + * @return LanguageService + */ + private function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } + /** * Returns the module template instance. * @@ -120,7 +132,27 @@ private function moduleResponse(): ResponseInterface // Show button only at pages matching our page type. if ($contentPage['doktype'] !== Configuration::getNewsletterPageDokType()) { - return $this->moduleTemplate->renderResponse('Backend/UniversalMessenger.html'); + $this->moduleTemplate->addFlashMessage( + $this->translate('error.page_not_allowed'), + 'Universal Messenger', + ContextualFeedbackSeverity::INFO + ); + + return new ForwardResponse('error'); + } + + // Check if backend user is allowed to access this newsletter + if (!GeneralUtility::inList( + $this->getBackendUserAuthentication()->user['universal_messenger_channels'], + $contentPage['universal_messenger_channel'] + )) { + $this->moduleTemplate->addFlashMessage( + $this->translate('error.access_not_allowed'), + 'Universal Messenger', + ContextualFeedbackSeverity::ERROR + ); + + return new ForwardResponse('error'); } DebuggerUtility::var_dump($contentPage['title']); @@ -129,7 +161,21 @@ private function moduleResponse(): ResponseInterface } /** - * Shows the textDB entires. + * Returns the translated language label for the given identifier. + * + * @param string $key + * + * @return string + */ + private function translate(string $key): string + { + return $this->getLanguageService()->sL( + 'LLL:EXT:nrc_universal_messenger/Resources/Private/Language/locallang.xlf:' . $key + ); + } + + /** + * The main entry point. * * @return ResponseInterface */ @@ -139,4 +185,14 @@ public function indexAction(): ResponseInterface return $this->moduleResponse(); } + + /** + * The error entry point. + * + * @return ResponseInterface + */ + public function errorAction(): ResponseInterface + { + return $this->moduleTemplate->renderResponse('Backend/UniversalMessenger.html'); + } } diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 2efc4c3..b043361 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -8,6 +8,14 @@ Universal Messenger + + + Bitte wählen Sie eine Seite mit dem Seiten-Typ "Newsletter" aus. + + + Sie verfügen nicht über die notwendigen Rechte, um diesen Newsletter zu versenden. + + Newsletter-Kanäle diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 99ab571..5606f68 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -8,12 +8,20 @@ Universal Messenger + + + Please select a page with the page type "Newsletter". + + + You do not have the necessary rights to send this newsletter. + + - Newsletter channels + Newsletter channels - Here select the newsletter channels for which this user is allowed to send newsletters. + Here select the newsletter channels for which this user is allowed to send newsletters.