From 6f98b353fe0806c901b2e491e14eece78137dbfc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 30 Jan 2023 15:51:17 +0100 Subject: [PATCH] !!!|Own module group (#106) Add own module group and migrate old menu to different modules. This should improve user experience as most users are used to modules and are not aware of the dropdown menu. Rename Overview controller to Configuration controller As it handled configurations. This streamlines with labels and identifiers. --- .../Controller/Backend/AbstractController.php | 15 --- ...roller.php => ConfigurationController.php} | 17 +-- .../Controller/Backend/ImportController.php | 17 +-- Classes/Extension.php | 38 +++++- .../Updates/BackendModuleUserPermission.php | 114 ++++++++++++++++++ Classes/View/Backend/Menu.php | 68 ----------- .../Changelog/{1.3.0.rst => 2.0.0.rst} | 4 +- Resources/Private/Language/locallang.xlf | 2 +- Resources/Private/Language/locallang_mod.xlf | 7 +- .../Language/locallang_mod_configurations.xlf | 17 +++ .../Language/locallang_mod_imports.xlf | 17 +++ .../{Overview => Configuration}/Index.html | 0 .../Public/Icons/ModuleConfigurations.svg | 1 + Resources/Public/Icons/ModuleImports.svg | 1 + ext_emconf.php | 2 +- ext_localconf.php | 2 + phpstan.neon | 6 +- 17 files changed, 200 insertions(+), 128 deletions(-) rename Classes/Controller/Backend/{OverviewController.php => ConfigurationController.php} (86%) create mode 100644 Classes/Updates/BackendModuleUserPermission.php delete mode 100644 Classes/View/Backend/Menu.php rename Documentation/Changelog/{1.3.0.rst => 2.0.0.rst} (96%) create mode 100644 Resources/Private/Language/locallang_mod_configurations.xlf create mode 100644 Resources/Private/Language/locallang_mod_imports.xlf rename Resources/Private/Templates/Backend/{Overview => Configuration}/Index.html (100%) create mode 100644 Resources/Public/Icons/ModuleConfigurations.svg create mode 100644 Resources/Public/Icons/ModuleImports.svg diff --git a/Classes/Controller/Backend/AbstractController.php b/Classes/Controller/Backend/AbstractController.php index 83b8809..489e862 100644 --- a/Classes/Controller/Backend/AbstractController.php +++ b/Classes/Controller/Backend/AbstractController.php @@ -25,8 +25,6 @@ namespace WerkraumMedia\ThueCat\Controller\Backend; use TYPO3\CMS\Backend\View\BackendTemplateView; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; -use WerkraumMedia\ThueCat\View\Backend\Menu; abstract class AbstractController extends ActionController { @@ -43,17 +41,4 @@ abstract class AbstractController extends ActionController * @var string */ protected $defaultViewObjectName = BackendTemplateView::class; - - protected function initializeView(ViewInterface $view): void - { - if ($view instanceof BackendTemplateView) { - $this->getMenu()->addMenu( - $view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry(), - $this->uriBuilder, - get_class($this) - ); - } - } - - abstract protected function getMenu(): Menu; } diff --git a/Classes/Controller/Backend/OverviewController.php b/Classes/Controller/Backend/ConfigurationController.php similarity index 86% rename from Classes/Controller/Backend/OverviewController.php rename to Classes/Controller/Backend/ConfigurationController.php index c2a4084..91e1847 100644 --- a/Classes/Controller/Backend/OverviewController.php +++ b/Classes/Controller/Backend/ConfigurationController.php @@ -25,9 +25,8 @@ namespace WerkraumMedia\ThueCat\Controller\Backend; use WerkraumMedia\ThueCat\Domain\Repository\Backend\ImportConfigurationRepository; use WerkraumMedia\ThueCat\Domain\Repository\Backend\OrganisationRepository; -use WerkraumMedia\ThueCat\View\Backend\Menu; -class OverviewController extends AbstractController +class ConfigurationController extends AbstractController { /** * @var OrganisationRepository @@ -39,19 +38,12 @@ class OverviewController extends AbstractController */ private $importConfigurationRepository; - /** - * @var Menu - */ - private $menu; - public function __construct( OrganisationRepository $organisationRepository, - ImportConfigurationRepository $importConfigurationRepository, - Menu $menu + ImportConfigurationRepository $importConfigurationRepository ) { $this->organisationRepository = $organisationRepository; $this->importConfigurationRepository = $importConfigurationRepository; - $this->menu = $menu; } public function indexAction(): void @@ -61,9 +53,4 @@ class OverviewController extends AbstractController 'organisations' => $this->organisationRepository->findAll(), ]); } - - protected function getMenu(): Menu - { - return $this->menu; - } } diff --git a/Classes/Controller/Backend/ImportController.php b/Classes/Controller/Backend/ImportController.php index 0a5021b..09f20dc 100644 --- a/Classes/Controller/Backend/ImportController.php +++ b/Classes/Controller/Backend/ImportController.php @@ -30,7 +30,6 @@ use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration; use WerkraumMedia\ThueCat\Domain\Repository\Backend\ImportLogRepository; use WerkraumMedia\ThueCat\Extension; use WerkraumMedia\ThueCat\Typo3Wrapper\TranslationService; -use WerkraumMedia\ThueCat\View\Backend\Menu; class ImportController extends AbstractController { @@ -49,21 +48,14 @@ class ImportController extends AbstractController */ private $translation; - /** - * @var Menu - */ - private $menu; - public function __construct( Importer $importer, ImportLogRepository $repository, - TranslationService $translation, - Menu $menu + TranslationService $translation ) { $this->importer = $importer; $this->repository = $repository; $this->translation = $translation; - $this->menu = $menu; } public function indexAction(): void @@ -86,12 +78,7 @@ class ImportController extends AbstractController $this->createImportDoneFlashMessage($importConfiguration); } - $this->redirect('index', 'Backend\Overview'); - } - - protected function getMenu(): Menu - { - return $this->menu; + $this->redirect('index', 'Backend\Configuration'); } private function createImportErrorFlashMessage(ImportConfiguration $importConfiguration): void diff --git a/Classes/Extension.php b/Classes/Extension.php index fd2d1c8..382011d 100644 --- a/Classes/Extension.php +++ b/Classes/Extension.php @@ -29,8 +29,8 @@ use TYPO3\CMS\Core\Imaging\IconRegistry; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\ExtensionUtility; +use WerkraumMedia\ThueCat\Controller\Backend\ConfigurationController; use WerkraumMedia\ThueCat\Controller\Backend\ImportController; -use WerkraumMedia\ThueCat\Controller\Backend\OverviewController; class Extension { @@ -51,17 +51,43 @@ class Extension { ExtensionUtility::registerModule( self::EXTENSION_NAME, - 'site', 'thuecat', '', + '', + [], [ - OverviewController::class => 'index', - ImportController::class => 'import, index', + 'access' => 'user,group', + 'icon' => self::getIconPath() . 'ModuleGroup.svg', + 'labels' => self::getLanguagePath() . 'locallang_mod.xlf', + ] + ); + ExtensionUtility::registerModule( + self::EXTENSION_NAME, + 'thuecat', + 'configurations', + '', + [ + ConfigurationController::class => 'index', + ImportController::class => 'import', ], [ 'access' => 'user,group', - 'icon' => self::getIconPath() . 'Extension.svg', - 'labels' => self::getLanguagePath() . 'locallang_mod.xlf', + 'icon' => self::getIconPath() . 'ModuleConfigurations.svg', + 'labels' => self::getLanguagePath() . 'locallang_mod_configurations.xlf', + ] + ); + ExtensionUtility::registerModule( + self::EXTENSION_NAME, + 'thuecat', + 'imports', + '', + [ + ImportController::class => 'index,import', + ], + [ + 'access' => 'user,group', + 'icon' => self::getIconPath() . 'ModuleImports.svg', + 'labels' => self::getLanguagePath() . 'locallang_mod_imports.xlf', ] ); } diff --git a/Classes/Updates/BackendModuleUserPermission.php b/Classes/Updates/BackendModuleUserPermission.php new file mode 100644 index 0000000..17962a0 --- /dev/null +++ b/Classes/Updates/BackendModuleUserPermission.php @@ -0,0 +1,114 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace WerkraumMedia\ThueCat\Updates; + +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite; +use TYPO3\CMS\Install\Updates\UpgradeWizardInterface; + +class BackendModuleUserPermission implements UpgradeWizardInterface +{ + /** + * @var ConnectionPool + */ + private $connectionPool; + + public function __construct( + ConnectionPool $connectionPool + ) { + $this->connectionPool = $connectionPool; + } + + public function getIdentifier(): string + { + return self::class; + } + + public function getTitle(): string + { + return 'Update user permissions for ThüCAT modules.'; + } + + public function getDescription(): string + { + return 'The module was migrated to an own group which changes the permission identifiers.'; + } + + public function updateNecessary(): bool + { + $qb = $this->connectionPool->getQueryBuilderForTable('be_users'); + $qb->getRestrictions()->removeAll(); + $qb->count('*'); + $qb->from('be_users'); + $qb->where($qb->expr()->like('userMods', $qb->createNamedParameter('%site_ThuecatThuecat%'))); + + return $qb->execute()->fetchOne() > 0; + } + + public function executeUpdate(): bool + { + $qb = $this->connectionPool->getQueryBuilderForTable('be_users'); + $qb->getRestrictions()->removeAll(); + $qb->select('uid', 'userMods'); + $qb->from('be_users'); + $qb->where($qb->expr()->like('userMods', $qb->createNamedParameter('%site_ThuecatThuecat%'))); + $result = $qb->execute(); + + foreach ($result as $backendUser) { + $qb = $this->connectionPool->getQueryBuilderForTable('be_users'); + $qb->update('be_users'); + $qb->set('userMods', $this->updateMods($backendUser['userMods'])); + $qb->where($qb->expr()->eq('uid', $qb->createNamedParameter($backendUser['uid']))); + $qb->execute(); + } + + return true; + } + + private function updateMods(string $mods): string + { + $mods = GeneralUtility::trimExplode(',', $mods, true); + + unset($mods[array_search('site_ThuecatThuecat', $mods)]); + + $mods[] = 'ThuecatThuecat'; + $mods[] = 'ThuecatThuecat_ThuecatConfigurations'; + $mods[] = 'ThuecatThuecat_ThuecatImports'; + + return implode(',', $mods); + } + + public function getPrerequisites(): array + { + return [ + DatabaseUpdatedPrerequisite::class, + ]; + } + + public static function register(): void + { + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][self::class] = self::class; + } +} diff --git a/Classes/View/Backend/Menu.php b/Classes/View/Backend/Menu.php deleted file mode 100644 index 156d8e4..0000000 --- a/Classes/View/Backend/Menu.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -namespace WerkraumMedia\ThueCat\View\Backend; - -use TYPO3\CMS\Backend\Template\Components\MenuRegistry; -use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use WerkraumMedia\ThueCat\Controller\Backend\ImportController; -use WerkraumMedia\ThueCat\Controller\Backend\OverviewController; -use WerkraumMedia\ThueCat\Extension; -use WerkraumMedia\ThueCat\Typo3Wrapper\TranslationService; - -class Menu -{ - /** - * @var TranslationService - */ - private $translation; - - public function __construct( - TranslationService $translation - ) { - $this->translation = $translation; - } - - public function addMenu( - MenuRegistry $registry, - UriBuilder $uriBuilder, - string $controllerClassName - ): void { - $menu = $registry->makeMenu(); - $menu->setIdentifier('action'); - - $menuItem = $menu->makeMenuItem(); - $menuItem->setTitle($this->translation->translate('module.overview.headline', Extension::EXTENSION_NAME)); - $menuItem->setHref($uriBuilder->reset()->uriFor('index', [], 'Backend\Overview')); - $menuItem->setActive($controllerClassName === OverviewController::class); - $menu->addMenuItem($menuItem); - - $menuItem = $menu->makeMenuItem(); - $menuItem->setTitle($this->translation->translate('module.imports.headline', Extension::EXTENSION_NAME)); - $menuItem->setHref($uriBuilder->reset()->uriFor('index', [], 'Backend\Import')); - $menuItem->setActive($controllerClassName === ImportController::class); - $menu->addMenuItem($menuItem); - - $registry->addMenu($menu); - } -} diff --git a/Documentation/Changelog/1.3.0.rst b/Documentation/Changelog/2.0.0.rst similarity index 96% rename from Documentation/Changelog/1.3.0.rst rename to Documentation/Changelog/2.0.0.rst index 0ee4a70..c52493e 100644 --- a/Documentation/Changelog/1.3.0.rst +++ b/Documentation/Changelog/2.0.0.rst @@ -4,7 +4,9 @@ Breaking -------- -Nothing +* Permissions of backend modules. + The modules got new identifiers. User permissions need to be adjusted. + An update wizard is provided that will migrate the permissions. Features -------- diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 8fc6fd9..ae8c4ae 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -31,7 +31,7 @@ Actions - ThüCAT - Overview + ThüCAT - Configurations diff --git a/Resources/Private/Language/locallang_mod.xlf b/Resources/Private/Language/locallang_mod.xlf index 54e9d2d..d206077 100644 --- a/Resources/Private/Language/locallang_mod.xlf +++ b/Resources/Private/Language/locallang_mod.xlf @@ -4,13 +4,10 @@
- ThüCat - - - Provides access to current connection, imported data and configuration. + ThüCAT - ThüCat + ThüCAT diff --git a/Resources/Private/Language/locallang_mod_configurations.xlf b/Resources/Private/Language/locallang_mod_configurations.xlf new file mode 100644 index 0000000..f96a278 --- /dev/null +++ b/Resources/Private/Language/locallang_mod_configurations.xlf @@ -0,0 +1,17 @@ + + + +
+ + + Configurations + + + Provides an short overview + + + Shows all existing import configurations and allows to edit, import and create new configurations. + + + + diff --git a/Resources/Private/Language/locallang_mod_imports.xlf b/Resources/Private/Language/locallang_mod_imports.xlf new file mode 100644 index 0000000..e61eefd --- /dev/null +++ b/Resources/Private/Language/locallang_mod_imports.xlf @@ -0,0 +1,17 @@ + + + +
+ + + Imports + + + Shows executed imports and their results + + + Provides detailed overview of errors during imports, as well as how many records of each type were imported. + + + + diff --git a/Resources/Private/Templates/Backend/Overview/Index.html b/Resources/Private/Templates/Backend/Configuration/Index.html similarity index 100% rename from Resources/Private/Templates/Backend/Overview/Index.html rename to Resources/Private/Templates/Backend/Configuration/Index.html diff --git a/Resources/Public/Icons/ModuleConfigurations.svg b/Resources/Public/Icons/ModuleConfigurations.svg new file mode 100644 index 0000000..189e138 --- /dev/null +++ b/Resources/Public/Icons/ModuleConfigurations.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Resources/Public/Icons/ModuleImports.svg b/Resources/Public/Icons/ModuleImports.svg new file mode 100644 index 0000000..0af409a --- /dev/null +++ b/Resources/Public/Icons/ModuleImports.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ext_emconf.php b/ext_emconf.php index e95ae0e..159eaaa 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,7 +11,7 @@ $EM_CONF[$_EXTKEY] = [ 'author' => 'Daniel Siepmann', 'author_email' => 'coding@daniel-siepmann.de', 'author_company' => '', - 'version' => '1.3.0', + 'version' => '2.0.0', 'constraints' => [ 'depends' => [ 'core' => '', diff --git a/ext_localconf.php b/ext_localconf.php index c2e0ddb..5fd4423 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -4,6 +4,8 @@ defined('TYPO3') or die(); \WerkraumMedia\ThueCat\Extension::registerConfig(); +\WerkraumMedia\ThueCat\Updates\BackendModuleUserPermission::register(); + (static function (string $extensionKey) { TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup( '@import "EXT:' . $extensionKey . '/Configuration/TypoScript/Default/Setup.typoscript"' diff --git a/phpstan.neon b/phpstan.neon index f4496a5..b33b687 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,5 +11,9 @@ parameters: checkGenericClassInNonGenericObjectType: false ignoreErrors: # Depending on TYPO3 version - - "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#" + - "#^Argument of an invalid type Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int supplied for foreach, only iterables are supported\\.$#" + - "#^Argument of an invalid type Doctrine\\\\DBAL\\\\Result\\|int supplied for foreach, only iterables are supported\\.$#" - "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" + - "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#" + - "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" + - "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#"