From 3fd076811c646b6208417d28a44805241cda9d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cygankiewicz?= Date: Fri, 19 Apr 2024 13:09:16 +0200 Subject: [PATCH] Permissions: button for inline generation --- .../CustomFileControlsEventListener.php | 10 ++- .../ModifyFilelistButtonBarEventListener.php | 10 ++- Classes/Backend/Hooks/ButtonBarHook.php | 25 ++++-- Classes/Controller/AiImageController.php | 84 ------------------- Classes/Controller/AjaxController.php | 59 ++++++++++++- Classes/Controller/BaseController.php | 32 ++++++- .../InlineControl/ImageGenerationButton.php | 7 ++ Classes/Utility/PermissionsUtility.php | 20 ++++- Configuration/Backend/AjaxRoutes.php | 2 +- Configuration/Services.yaml | 12 +++ Resources/Private/Language/de.locallang.xlf | 4 + .../Language/de.locallang_contentai.xlf | 4 + Resources/Private/Language/locallang.xlf | 3 + .../Private/Language/locallang_contentai.xlf | 3 + .../Private/Templates/AiImage/Prompt.html | 4 + ext_tables.php | 3 + 16 files changed, 183 insertions(+), 99 deletions(-) diff --git a/Classes/Backend/EventListener/CustomFileControlsEventListener.php b/Classes/Backend/EventListener/CustomFileControlsEventListener.php index 6687eea..528494c 100644 --- a/Classes/Backend/EventListener/CustomFileControlsEventListener.php +++ b/Classes/Backend/EventListener/CustomFileControlsEventListener.php @@ -17,6 +17,7 @@ namespace DMK\MkContentAi\Backend\EventListener; +use DMK\MkContentAi\Utility\PermissionsUtility; use TYPO3\CMS\Backend\Form\Event\CustomFileControlsEvent; use TYPO3\CMS\Backend\Form\NodeFactory; use TYPO3\CMS\Core\Imaging\Icon; @@ -36,14 +37,21 @@ final class CustomFileControlsEventListener */ public $iconFactory; - public function __construct() + private PermissionsUtility $permissionsUtility; + + public function __construct(PermissionsUtility $permissionsUtility) { $this->nodeFactory = GeneralUtility::makeInstance(NodeFactory::class); $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); + $this->permissionsUtility = $permissionsUtility; } public function handleEvent(CustomFileControlsEvent $event): void { + if (!$this->permissionsUtility->userHasAccessToImageGenerationPromptButton()) { + return; + } + $translatedMessage = LocalizationUtility::translate('labelAiGenerateText', 'mkcontentai') ?? ''; $item = '