diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b1e0fda..55cb3f4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,9 +29,8 @@ jobs: strategy: matrix: php-version: - - 7.4 - - 8.0 - - 8.1 + - 8.2 + - 8.3 steps: - name: Checkout uses: actions/checkout@v2 diff --git a/Classes/Controller/BackendUserToolsController.php b/Classes/Controller/BackendUserToolsController.php index 7d51817..43fab12 100644 --- a/Classes/Controller/BackendUserToolsController.php +++ b/Classes/Controller/BackendUserToolsController.php @@ -3,7 +3,16 @@ namespace Visol\Beusertools\Controller; use Psr\Http\Message\ResponseInterface; +use TYPO3\CMS\Backend\Attribute\AsController; +use TYPO3\CMS\Backend\Template\Components\ButtonBar; +use TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownItem; +use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\View\ViewFactoryData; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use TYPO3\CMS\Fluid\View\FluidViewFactory; use Visol\Beusertools\Domain\Repository\BackendUserGroupRepository; use Visol\Beusertools\Domain\Repository\BackendUserRepository; @@ -32,21 +41,29 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +#[AsController] class BackendUserToolsController extends ActionController { - /** - * @var BackendUserGroupRepository - */ - protected $backendUserGroupRepository; + private ModuleTemplate $moduleTemplate; - /** - * @var BackendUserRepository - */ - protected $backendUserRepository; + protected BackendUserGroupRepository $backendUserGroupRepository; - public function listUsersByGroupAction(): ResponseInterface + protected BackendUserRepository $backendUserRepository; + + public function __construct( + protected readonly FluidViewFactory $fluidViewFactory, + protected readonly ModuleTemplateFactory $moduleTemplateFactory + ) { + } + + public function initializeAction(): void { + $this->moduleTemplate = $this->moduleTemplateFactory->create($this->request); + $this->setDocHeader(); + } + public function listUsersByGroupAction(): ResponseInterface + { $backendUserGroups = $this->backendUserGroupRepository->findAll()->toArray(); $backendUserGroupsWithUsers = []; $i = 0; @@ -56,12 +73,17 @@ public function listUsersByGroupAction(): ResponseInterface $backendUserGroupsWithUsers[$backendUserGroup->getUid()]['users'] = $this->backendUserRepository->findByUsergroups([$backendUserGroup->getUid()]); $i++; } - $this->view->assign('backendUserGroups', $backendUserGroupsWithUsers); - return $this->htmlResponse(); + $this->moduleTemplate->assign('backendUserGroups', $backendUserGroupsWithUsers); + return $this->moduleTemplate->renderResponse('BackendUserTools/ListUsersByGroup'); } - public function exportUsersByGroupAction() + public function exportUsersByGroupAction(): void { + $viewData = new ViewFactoryData( + templatePathAndFilename: 'EXT:beusertools/Resources/Private/Templates/Default/BackendUserTools/ExportUsersByGroup.html', + format: 'xml', + ); + $view = $this->fluidViewFactory->create($viewData); $backendUserGroups = $this->backendUserGroupRepository->findAll()->toArray(); $backendUserGroupsWithUsers = []; @@ -72,8 +94,9 @@ public function exportUsersByGroupAction() $backendUserGroupsWithUsers[$backendUserGroup->getUid()]['users'] = $this->backendUserRepository->findByUsergroups([$backendUserGroup->getUid()]); $i++; } - $this->view->assign('backendUserGroups', $backendUserGroupsWithUsers); - $content = $this->view->render(); + + $view->assign('backendUserGroups', $backendUserGroupsWithUsers); + $content = $view->render(); header('Content-Description: File Transfer'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); @@ -90,8 +113,8 @@ public function exportUsersByGroupAction() public function listUsersAction(): ResponseInterface { $backendUsers = $this->backendUserRepository->findAll(); - $this->view->assign('backendUsers', $backendUsers); - return $this->htmlResponse(); + $this->moduleTemplate->assign('backendUsers', $backendUsers); + return $this->moduleTemplate->renderResponse('BackendUserTools/ListUsers'); } public function injectBackendUserGroupRepository(BackendUserGroupRepository $backendUserGroupRepository): void @@ -103,4 +126,43 @@ public function injectBackendUserRepository(BackendUserRepository $backendUserRe { $this->backendUserRepository = $backendUserRepository; } + + public function setDocHeader(): void + { + $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); + $dropdownLabel = LocalizationUtility::translate( + 'LLL:EXT:beusertools/Resources/Private/Language/locallang.xlf:submoduleDropdownLabel' + ); + $dropDownButton = $buttonBar->makeDropDownButton()->setLabel($dropdownLabel)->setTitle( + $dropdownLabel + )->setShowLabelText($dropdownLabel); + + $dropDownButton->addItem( + GeneralUtility::makeInstance(DropDownItem::class) + ->setLabel(LocalizationUtility::translate('LLL:EXT:beusertools/Resources/Private/Language/locallang.xlf:submoduleTitle_listUsersByGroupAction')) + ->setHref( + $this->uriBuilder->setArguments( + [ + 'controller' => 'BackendUserTools', + 'action' => 'listUsersByGroup', + ] + )->buildBackendUri() + ) + ); + + $dropDownButton->addItem( + GeneralUtility::makeInstance(DropDownItem::class) + ->setLabel(LocalizationUtility::translate('LLL:EXT:beusertools/Resources/Private/Language/locallang.xlf:submoduleTitle_listUsersAction')) + ->setHref( + $this->uriBuilder->setArguments( + [ + 'controller' => 'BackendUserTools', + 'action' => 'listUsers', + ] + )->buildBackendUri() + ) + ); + + $buttonBar->addButton($dropDownButton, ButtonBar::BUTTON_POSITION_LEFT, 2); + } } diff --git a/Classes/Domain/Model/BackendUser.php b/Classes/Domain/Model/BackendUser.php index 41c2ef7..115f9f3 100644 --- a/Classes/Domain/Model/BackendUser.php +++ b/Classes/Domain/Model/BackendUser.php @@ -20,8 +20,8 @@ class BackendUser extends AbstractEntity // below are the "default" properties stolen from the extbase model /** * @var string - * @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty") */ + #[TYPO3\CMS\Extbase\Annotation\Validate(['validator' => 'NotEmpty'])] protected $userName = ''; /** @@ -89,7 +89,7 @@ public function getUserName() * * @param string $userName the user name to set, must not be empty */ - public function setUserName($userName) + public function setUserName($userName): void { $this->userName = $userName; } @@ -105,7 +105,7 @@ public function getDescription() /** * @param string $description */ - public function setDescription($description) + public function setDescription($description): void { $this->description = $description; } @@ -125,7 +125,7 @@ public function getIsAdministrator() * * @param bool $isAdministrator whether this user should be an administrator */ - public function setIsAdministrator($isAdministrator) + public function setIsAdministrator($isAdministrator): void { $this->isAdministrator = $isAdministrator; } @@ -145,7 +145,7 @@ public function getIsDisabled() * * @param bool $isDisabled whether this user is disabled */ - public function setIsDisabled($isDisabled) + public function setIsDisabled($isDisabled): void { $this->isDisabled = $isDisabled; } @@ -165,7 +165,7 @@ public function getStartDateAndTime() * * @param \DateTime|null $dateAndTime the start date and time */ - public function setStartDateAndTime(\DateTime $dateAndTime = null) + public function setStartDateAndTime(\DateTime $dateAndTime = null): void { $this->startDateAndTime = $dateAndTime; } @@ -185,7 +185,7 @@ public function getEndDateAndTime() * * @param \DateTime|null $dateAndTime the end date and time */ - public function setEndDateAndTime(\DateTime $dateAndTime = null) + public function setEndDateAndTime(\DateTime $dateAndTime = null): void { $this->endDateAndTime = $dateAndTime; } @@ -205,7 +205,7 @@ public function getEmail() * * @param string $email the e-mail address, may be empty */ - public function setEmail($email) + public function setEmail($email): void { $this->email = $email; } @@ -225,7 +225,7 @@ public function getRealName() * * @param string $name the user's real name, may be empty. */ - public function setRealName($name) + public function setRealName($name): void { $this->realName = $name; } @@ -285,7 +285,7 @@ public function getLastLoginDateAndTime() * * @param \DateTime|null $dateAndTime this user's last login date and time */ - public function setLastLoginDateAndTime(\DateTime $dateAndTime = null) + public function setLastLoginDateAndTime(\DateTime $dateAndTime = null): void { $this->lastLoginDateAndTime = $dateAndTime; } diff --git a/Classes/Domain/Model/BackendUserGroup.php b/Classes/Domain/Model/BackendUserGroup.php index d61640f..bbadcb5 100644 --- a/Classes/Domain/Model/BackendUserGroup.php +++ b/Classes/Domain/Model/BackendUserGroup.php @@ -13,8 +13,8 @@ class BackendUserGroup extends AbstractEntity /** * @var string - * @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty") */ + #[TYPO3\CMS\Extbase\Annotation\Validate(['validator' => 'NotEmpty'])] protected $title = ''; /** @@ -89,7 +89,7 @@ public function __construct() * * @param string $title */ - public function setTitle($title) + public function setTitle($title): void { $this->title = $title; } @@ -109,7 +109,7 @@ public function getTitle() * * @param string $description */ - public function setDescription($description) + public function setDescription($description): void { $this->description = $description; } @@ -129,7 +129,7 @@ public function getDescription() * * @param string $modules */ - public function setModules($modules) + public function setModules($modules): void { $this->modules = $modules; } @@ -149,7 +149,7 @@ public function getModules() * * @param string $tablesListening */ - public function setTablesListening($tablesListening) + public function setTablesListening($tablesListening): void { $this->tablesListening = $tablesListening; } @@ -169,7 +169,7 @@ public function getTablesListening() * * @param string $tablesModify */ - public function setTablesModify($tablesModify) + public function setTablesModify($tablesModify): void { $this->tablesModify = $tablesModify; } @@ -189,7 +189,7 @@ public function getTablesModify() * * @param string $pageTypes */ - public function setPageTypes($pageTypes) + public function setPageTypes($pageTypes): void { $this->pageTypes = $pageTypes; } @@ -209,7 +209,7 @@ public function getPageTypes() * * @param string $allowedExcludeFields */ - public function setAllowedExcludeFields($allowedExcludeFields) + public function setAllowedExcludeFields($allowedExcludeFields): void { $this->allowedExcludeFields = $allowedExcludeFields; } @@ -229,7 +229,7 @@ public function getAllowedExcludeFields() * * @param string $explicitlyAllowAndDeny */ - public function setExplicitlyAllowAndDeny($explicitlyAllowAndDeny) + public function setExplicitlyAllowAndDeny($explicitlyAllowAndDeny): void { $this->explicitlyAllowAndDeny = $explicitlyAllowAndDeny; } @@ -249,7 +249,7 @@ public function getExplicitlyAllowAndDeny() * * @param string $allowedLanguages */ - public function setAllowedLanguages($allowedLanguages) + public function setAllowedLanguages($allowedLanguages): void { $this->allowedLanguages = $allowedLanguages; } @@ -269,7 +269,7 @@ public function getAllowedLanguages() * * @param bool $workspacePermission */ - public function setWorkspacePermissions($workspacePermission) + public function setWorkspacePermissions($workspacePermission): void { $this->workspacePermission = $workspacePermission; } @@ -289,7 +289,7 @@ public function getWorkspacePermission() * * @param string $databaseMounts */ - public function setDatabaseMounts($databaseMounts) + public function setDatabaseMounts($databaseMounts): void { $this->databaseMounts = $databaseMounts; } @@ -309,7 +309,7 @@ public function getDatabaseMounts() * * @param int $fileOperationPermissions */ - public function setFileOperationPermissions($fileOperationPermissions) + public function setFileOperationPermissions($fileOperationPermissions): void { $this->fileOperationPermissions = $fileOperationPermissions; } @@ -340,7 +340,7 @@ public function isFileOperationAllowed() * * @param bool $value */ - public function setFileOperationAllowed($value) + public function setFileOperationAllowed($value): void { $this->setPermission(self::FILE_OPPERATIONS, $value); } @@ -360,7 +360,7 @@ public function isDirectoryOperationAllowed() * * @param bool $value */ - public function setDirectoryOperationAllowed($value) + public function setDirectoryOperationAllowed($value): void { $this->setPermission(self::DIRECTORY_OPPERATIONS, $value); } @@ -380,7 +380,7 @@ public function isDirectoryCopyAllowed() * * @param bool $value */ - public function setDirectoryCopyAllowed($value) + public function setDirectoryCopyAllowed($value): void { $this->setPermission(self::DIRECTORY_COPY, $value); } @@ -400,7 +400,7 @@ public function isDirectoryRemoveRecursivelyAllowed() * * @param bool $value */ - public function setDirectoryRemoveRecursivelyAllowed($value) + public function setDirectoryRemoveRecursivelyAllowed($value): void { $this->setPermission(self::DIRECTORY_REMOVE_RECURSIVELY, $value); } @@ -410,7 +410,7 @@ public function setDirectoryRemoveRecursivelyAllowed($value) * * @param string $tsConfig */ - public function setTsConfig($tsConfig) + public function setTsConfig($tsConfig): void { $this->tsConfig = $tsConfig; } diff --git a/Classes/Domain/Repository/BackendUserGroupRepository.php b/Classes/Domain/Repository/BackendUserGroupRepository.php index d8e0253..e892e7f 100644 --- a/Classes/Domain/Repository/BackendUserGroupRepository.php +++ b/Classes/Domain/Repository/BackendUserGroupRepository.php @@ -9,7 +9,7 @@ class BackendUserGroupRepository extends Repository { - public function initializeObject() + public function initializeObject(): void { $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); $querySettings->setRespectStoragePage(false); diff --git a/Classes/Domain/Repository/BackendUserRepository.php b/Classes/Domain/Repository/BackendUserRepository.php index b62e3b0..d2d6926 100644 --- a/Classes/Domain/Repository/BackendUserRepository.php +++ b/Classes/Domain/Repository/BackendUserRepository.php @@ -10,7 +10,14 @@ class BackendUserRepository extends Repository { - public function initializeObject() + /** + * Constructs a new Repository + */ + public function __construct(private readonly \TYPO3\CMS\Core\Database\ConnectionPool $connectionPool) + { + parent::__construct(); + } + public function initializeObject(): void { $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); $querySettings->setRespectStoragePage(false); @@ -26,7 +33,10 @@ public function findAll() $query = $this->createQuery(); $query->matching( $query->logicalNot( - $query->logicalOr([$query->equals('isAdministrator', true), $query->like('userName', '_cli%')]) + $query->logicalOr( + $query->equals('isAdministrator', true), + $query->like('userName', '_cli%') + ) ) ); $query->getQuerySettings()->setIgnoreEnableFields(true); @@ -35,18 +45,17 @@ public function findAll() public function findByUsergroups(array $usergroups): array { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('be_users')->createQueryBuilder(); + $queryBuilder = $this->connectionPool->getConnectionForTable('be_users')->createQueryBuilder(); $constraints = []; foreach ($usergroups as $usergroup) { - $constraints[] = $queryBuilder->expr()->inSet('bu.usergroup', $queryBuilder->createNamedParameter((int)$usergroup, \PDO::PARAM_INT)); + $constraints[] = $queryBuilder->expr()->inSet('bu.usergroup', $queryBuilder->createNamedParameter((int)$usergroup, \TYPO3\CMS\Core\Database\Connection::PARAM_INT)); } return $queryBuilder->select('*') ->from('be_users', 'bu') ->where($queryBuilder->expr()->and(...$constraints)) ->orderBy('username') - ->execute() ->fetchAllAssociative(); } } diff --git a/Configuration/Backend/Modules.php b/Configuration/Backend/Modules.php new file mode 100644 index 0000000..41e769b --- /dev/null +++ b/Configuration/Backend/Modules.php @@ -0,0 +1,17 @@ + [ + 'parent' => 'web', + 'access' => 'user', + 'labels' => 'LLL:EXT:beusertools/Resources/Private/Language/locallang_userlisting.xlf', + 'extensionName' => 'Beusertools', + 'controllerActions' => [ + 'Visol\Beusertools\Controller\BackendUserToolsController' => [ + 'listUsersByGroup', + 'listUsers', + 'exportUsersByGroup', + ], + ], + ], +]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..3cc0a90 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + Visol\Beusertools\: + resource: '../Classes/*' diff --git a/README.md b/README.md index 88086a4..a25fc4a 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,9 @@ Feel free the send pull requests for useful features. This package is currently maintained for the following versions: -| TYPO3 Version | Package Version | Branch | Maintained | -|-----------------------|-----------------|---------|---------------| -| TYPO3 11.5.x | 3.x | master | Yes | -| TYPO3 8.7.x | 2.x | - | No | -| TYPO3 6.2.x | 1.x | - | No | +| TYPO3 Version | Package Version | Branch | Maintained | +|---------------|-----------------|--------|------------| +| TYPO3 13.4.x | 4.x | master | Yes | +| TYPO3 11.5.x | 3.x | - | No | +| TYPO3 8.7.x | 2.x | - | No | +| TYPO3 6.2.x | 1.x | - | No | diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 22ef144..d3ed1a3 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -3,6 +3,10 @@
+ + Change view + Ansicht wechseln + List users by group Benutzerliste nach Gruppen diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 3688c35..523d0fb 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -3,6 +3,9 @@
+ + Change view + List users by group diff --git a/Resources/Private/Backend/Layouts/Default.html b/Resources/Private/Layouts/Default.html similarity index 83% rename from Resources/Private/Backend/Layouts/Default.html rename to Resources/Private/Layouts/Default.html index 72cb38b..c194971 100644 --- a/Resources/Private/Backend/Layouts/Default.html +++ b/Resources/Private/Layouts/Default.html @@ -1,9 +1,8 @@ - +
- @@ -17,7 +16,7 @@
- + test
@@ -27,4 +26,4 @@
-
+ diff --git a/Resources/Private/Backend/Templates/BackendUserTools/ExportUsersByGroup.html b/Resources/Private/Templates/Default/BackendUserTools/ExportUsersByGroup.html similarity index 100% rename from Resources/Private/Backend/Templates/BackendUserTools/ExportUsersByGroup.html rename to Resources/Private/Templates/Default/BackendUserTools/ExportUsersByGroup.html diff --git a/Resources/Private/Backend/Templates/BackendUserTools/ListUsers.html b/Resources/Private/Templates/Default/BackendUserTools/ListUsers.html similarity index 96% rename from Resources/Private/Backend/Templates/BackendUserTools/ListUsers.html rename to Resources/Private/Templates/Default/BackendUserTools/ListUsers.html index e736e15..7c82823 100644 --- a/Resources/Private/Backend/Templates/BackendUserTools/ListUsers.html +++ b/Resources/Private/Templates/Default/BackendUserTools/ListUsers.html @@ -1,6 +1,6 @@ - + - +

{f:translate(key: 'submoduleTitle_listUsersAction')}

diff --git a/Resources/Private/Backend/Templates/BackendUserTools/ListUsersByGroup.html b/Resources/Private/Templates/Default/BackendUserTools/ListUsersByGroup.html similarity index 95% rename from Resources/Private/Backend/Templates/BackendUserTools/ListUsersByGroup.html rename to Resources/Private/Templates/Default/BackendUserTools/ListUsersByGroup.html index 014a0b7..f438526 100644 --- a/Resources/Private/Backend/Templates/BackendUserTools/ListUsersByGroup.html +++ b/Resources/Private/Templates/Default/BackendUserTools/ListUsersByGroup.html @@ -1,6 +1,6 @@ - + - +

{f:translate(key: 'submoduleTitle_listUsersByGroupAction')}

diff --git a/composer.json b/composer.json index 0f4d448..92b8f20 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,6 @@ } }, "require": { - "typo3/cms-core": "^11.5" + "typo3/cms-core": "^13.4" } } diff --git a/ext_tables.php b/ext_tables.php deleted file mode 100644 index 08d1bd6..0000000 --- a/ext_tables.php +++ /dev/null @@ -1,26 +0,0 @@ - 'listUsersByGroup,listUsers,exportUsersByGroup', - ], - [ - 'access' => 'user,group', - 'icon' => 'EXT:beusertools/Resources/Public/Icons/icon.svg', - 'labels' => 'LLL:EXT:beusertools/Resources/Private/Language/locallang_userlisting.xlf', - ] -);