commit 61d66df0780721572008cf793698c5252244ee53 Author: Sven Wappler Date: Mon Aug 10 22:31:03 2026 +0200 TYPO3 v15 dev-main snapshot () diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/Classes/Controller/BackendUserController.php b/Classes/Controller/BackendUserController.php new file mode 100644 index 0000000..cc5b610 --- /dev/null +++ b/Classes/Controller/BackendUserController.php @@ -0,0 +1,771 @@ +getArguments(); + $moduleData = $request->getAttribute('moduleData'); + + if (in_array((string)($arguments['action'] ?? ''), ['list', 'groups', 'online', 'filemounts'], true) + && (string)$moduleData->get('defaultAction') !== (string)$arguments['action'] + ) { + $moduleData->set('defaultAction', (string)$arguments['action']); + $this->getBackendUser()->pushModuleData($moduleData->getModuleIdentifier(), $moduleData->toArray()); + } + + return parent::processRequest($request); + } + + /** + * Init module state. + * This isn't done within __construct() since the controller + * object is only created once in extbase when multiple actions are called in + * one call. When those change module state, the second action would see old state. + */ + public function initializeAction(): void + { + $this->moduleData = $this->request->getAttribute('moduleData'); + $this->moduleTemplate = $this->moduleTemplateFactory->create($this->request); + $this->moduleTemplate->setTitle(LocalizationUtility::translate('beuser.modules.user_management:title')); + $this->moduleTemplate->setLayout(ModuleLayout::NORMAL); + $this->moduleTemplate->setFlashMessageQueue($this->getFlashMessageQueue()); + } + + /** + * Assign default variables to ModuleTemplate view + */ + protected function initializeView(): void + { + $this->moduleTemplate->assignMultiple([ + 'dateFormat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], + 'timeFormat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], + ]); + // Load JavaScript modules + $this->pageRenderer->loadJavaScriptModule('@typo3/backend/context-menu.js'); + $this->pageRenderer->loadJavaScriptModule('@typo3/backend/modal.js'); + $this->pageRenderer->loadJavaScriptModule('@typo3/backend/element/status-indicator-element.js'); + $this->pageRenderer->loadJavaScriptModule('@typo3/beuser/backend-user-listing.js'); + } + + /** + * Default action, forwarding the request to either a defined default action or the default entry point "list" + */ + public function indexAction(): ResponseInterface + { + $moduleData = $this->request->getAttribute('moduleData'); + + if ($moduleData->has('defaultAction') + && in_array((string)$moduleData->get('defaultAction'), ['list', 'groups', 'online', 'filemounts'], true) + ) { + return new ForwardResponse((string)$moduleData->get('defaultAction')); + } + + return new ForwardResponse('list'); + } + + /** + * Displays all BackendUsers + */ + public function listAction(?Demand $demand = null, int $currentPage = 1, string $operation = ''): ResponseInterface + { + $backendUser = $this->getBackendUser(); + + if ($operation === 'reset-filters') { + // Reset the module data demand object + $this->moduleData->set('demand', []); + $demand = null; + } + if ($demand === null) { + $demand = Demand::fromUc((array)$this->moduleData->get('demand', [])); + } else { + $this->moduleData->set('demand', $demand->forUc()); + } + $backendUser->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray()); + + $compareUserList = array_keys((array)$this->moduleData->get('compareUserList', [])); + + $backendUsers = $this->backendUserRepository->findDemanded($demand); + $paginator = new QueryResultPaginator($backendUsers, $currentPage, 50); + $pagination = new SimplePagination($paginator); + $backendUserGroups = $this->eventDispatcher->dispatch( + new AfterBackendGroupFilterListIsAssembledEvent( + $this->request, + array_merge([''], $this->backendUserGroupRepository->findAll()->toArray()) + ) + )->backendGroups; + + $this->moduleTemplate->assignMultiple([ + 'onlineBackendUsers' => $this->getOnlineBackendUsers(), + 'demand' => $demand, + 'paginator' => $paginator, + 'pagination' => $pagination, + 'totalAmountOfBackendUsers' => $backendUsers->count(), + 'backendUserGroups' => $backendUserGroups, + 'compareUserUidList' => array_combine($compareUserList, $compareUserList), + 'currentUserUid' => $backendUser->user['uid'] ?? null, + 'compareUserList' => !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '', + ]); + + $this->addMainMenu('list'); + $createEditorButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:btn.editor.create', 'beuser')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_users' => [0 => 'new']], + 'module' => 'backend_user_management', + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($createEditorButton); + $createAdminButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:btn.admin.create', 'beuser')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_users' => [0 => 'new']], + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + 'defVals' => ['be_users' => ['admin' => 1]], + ])); + $this->moduleTemplate->addButtonToButtonBar($createAdminButton, ButtonBar::BUTTON_POSITION_LEFT, 2); + + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUsers', 'beuser'), + ['action' => 'list'] + ); + + $this->pageRenderer->loadJavaScriptModule('@typo3/backend/switch-user.js'); + + return $this->moduleTemplate->renderResponse('BackendUser/List'); + } + + /** + * Views all currently logged in BackendUsers and their sessions + */ + public function onlineAction(): ResponseInterface + { + $onlineUsersAndSessions = []; + $onlineUsers = $this->backendUserRepository->findOnline(); + foreach ($onlineUsers as $onlineUser) { + $onlineUsersAndSessions[] = [ + 'backendUser' => $onlineUser, + 'sessions' => $this->backendUserSessionRepository->findByBackendUser($onlineUser), + ]; + } + + $currentSessionId = $this->backendUserSessionRepository->getPersistedSessionIdentifier($this->getBackendUser()); + + $this->moduleTemplate->assignMultiple([ + 'onlineUsersAndSessions' => $onlineUsersAndSessions, + 'currentSessionId' => $currentSessionId, + ]); + + $this->addMainMenu('online'); + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:onlineUsers', 'beuser'), + ['action' => 'online'] + ); + + return $this->moduleTemplate->renderResponse('BackendUser/Online'); + } + + public function showAction(int $uid = 0): ResponseInterface + { + $data = $this->userInformationService->getUserInformation($uid); + $this->moduleTemplate->assignMultiple([ + 'data' => $data, + 'showUid' => $this->getBackendUser()->shallDisplayDebugInformation(), + ]); + + $this->addMainMenu('show'); + $this->moduleTemplate->addButtonToButtonBar($this->componentFactory->createBackButton((string)$this->backendUriBuilder->buildUriFromRoute('backend_user_management'))); + $editButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-open', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.edit')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_users' => [$uid => 'edit']], + 'module' => 'backend_user_management', + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($editButton, ButtonBar::BUTTON_POSITION_LEFT, 2); + $addUserButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:btn.backendUser.create', 'beuser')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_users' => [0 => 'new']], + 'module' => 'backend_user_management', + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($addUserButton, ButtonBar::BUTTON_POSITION_LEFT, 3); + $username = empty($data['user']['username']) ? '' : ': ' . $data['user']['username']; + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUser', 'beuser') . $username, + ['action' => 'show', 'uid' => $uid] + ); + + return $this->moduleTemplate->renderResponse('BackendUser/Show'); + } + + /** + * Compare backend users from demand + */ + public function compareAction(): ResponseInterface + { + $compareUserList = array_keys((array)$this->moduleData->get('compareUserList', [])); + if (empty($compareUserList)) { + return $this->redirect('list'); + } + + $compareData = []; + foreach ($compareUserList as $uid) { + if ($compareInformation = $this->userInformationService->getUserInformation($uid)) { + $compareData[] = $compareInformation; + } + } + + $this->moduleTemplate->assignMultiple([ + 'compareUserList' => $compareData, + 'onlineBackendUsers' => $this->getOnlineBackendUsers(), + 'showUid' => $this->getBackendUser()->shallDisplayDebugInformation(), + ]); + + $this->addMainMenu('compare'); + $this->moduleTemplate->addButtonToButtonBar($this->componentFactory->createBackButton((string)$this->backendUriBuilder->buildUriFromRoute('backend_user_management'))); + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:compareBackendUsers', 'beuser'), + ['action' => 'compare'] + ); + + return $this->moduleTemplate->renderResponse('BackendUser/Compare'); + } + + protected function initializeInitiatePasswordResetAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Starts the password reset process for a selected user. + */ + public function initiatePasswordResetAction(int $user): ResponseInterface + { + $context = GeneralUtility::makeInstance(Context::class); + /** @var BackendUser|null $userObject */ + $userObject = $this->backendUserRepository->findByUid($user); + if (!$userObject || !$userObject->isPasswordResetEnabled() || !$context->getAspect('backend.user')->isAdmin()) { + // Add an error message + $this->addFlashMessage( + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.error.text', 'beuser') ?? '', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.error.title', 'beuser') ?? '', + ContextualFeedbackSeverity::ERROR + ); + } else { + GeneralUtility::makeInstance(PasswordReset::class)->initiateReset( + $this->request, + $context, + $userObject->getEmail() + ); + $this->addFlashMessage( + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.text', 'beuser', [$userObject->getEmail()]) ?? '', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.title', 'beuser') ?? '' + ); + } + return $this->redirect('list'); + } + + protected function initializeAddToCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Attaches one backend user to the compare list + */ + public function addToCompareListAction(int $uid): ResponseInterface + { + $this->addToCompareList('compareUserList', $uid); + return $this->redirect('list'); + } + + protected function initializeRemoveFromCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Removes given backend user to the compare list + */ + public function removeFromCompareListAction(int $uid, int $redirectToCompare = 0): ResponseInterface + { + $this->removeFromCompareList('compareUserList', $uid); + if ($redirectToCompare) { + return $this->redirect('compare'); + } + return $this->redirect('list'); + } + + protected function initializeRemoveAllFromCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Removes all backend users from the compare list + */ + public function removeAllFromCompareListAction(): ResponseInterface + { + $this->cleanCompareList('compareUserList'); + return $this->redirect('list'); + } + + protected function initializeTerminateBackendUserSessionAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Terminate BackendUser session and logout corresponding client + * Redirects to onlineAction with message + */ + protected function terminateBackendUserSessionAction(string $sessionId): ResponseInterface + { + // terminating value of persisted session ID + $success = $this->backendUserSessionRepository->terminateSessionByIdentifier($sessionId); + if ($success) { + $this->addFlashMessage(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUser.online.flashMessage.terminateSessionSuccess', 'beuser') ?? ''); + } + return $this->redirect('online'); + } + + /** + * Displays all BackendUserGroups + */ + public function groupsAction(?BackendUserGroup $userGroupDto = null, int $currentPage = 1, string $operation = ''): ResponseInterface + { + $backendUser = $this->getBackendUser(); + + if ($operation === 'reset-filters') { + $this->moduleData->set('userGroupDto', []); + $userGroupDto = null; + } + + if ($userGroupDto === null) { + $userGroupDto = BackendUserGroup::fromUc((array)$this->moduleData->get('userGroupDto', [])); + } else { + $this->moduleData->set('userGroupDto', $userGroupDto->forUc()); + } + + $backendUser->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray()); + + $backendUserGroups = $this->backendUserGroupRepository->findByFilter($userGroupDto); + $paginator = new QueryResultPaginator($backendUserGroups, $currentPage, 50); + $pagination = new SimplePagination($paginator); + $compareGroupUidList = array_keys((array)$this->moduleData->get('compareGroupUidList', [])); + $this->moduleTemplate->assignMultiple( + [ + 'paginator' => $paginator, + 'pagination' => $pagination, + 'totalAmountOfBackendUserGroups' => $backendUserGroups->count(), + 'compareGroupUidList' => array_map(static function (int $value): int { // uid as key and force value to 1 + return 1; + }, array_flip($compareGroupUidList)), + 'compareGroupList' => !empty($compareGroupUidList) ? $this->backendUserGroupRepository->findByUidList($compareGroupUidList) : [], + 'userGroupDto' => $userGroupDto, + ] + ); + + $this->addMainMenu('groups'); + $addGroupButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:btn.backendUserGroup.create', 'beuser')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_groups' => [0 => 'new']], + 'module' => 'backend_user_management', + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($addGroupButton); + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroupsMenu', 'beuser'), + ['action' => 'groups'] + ); + + return $this->moduleTemplate->renderResponse('BackendUserGroup/List'); + } + + /** + * Show a single backend user group. + */ + public function showGroupAction(int $uid = 0): ResponseInterface + { + $data = $this->userInformationService->getGroupInformation($uid); + $this->moduleTemplate->assignMultiple([ + 'data' => $data, + 'showUid' => $this->getBackendUser()->shallDisplayDebugInformation(), + ]); + + $this->addMainMenu('showGroup'); + $this->moduleTemplate->addButtonToButtonBar($this->componentFactory->createBackButton((string)$this->backendUriBuilder->buildUriFromRoute('backend_user_management', ['action' => 'groups']))); + $editButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-open', IconSize::SMALL)) + ->setTitle( + LocalizationUtility::translate( + 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.edit' + ) + ) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_groups' => [$uid => 'edit']], + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($editButton, ButtonBar::BUTTON_POSITION_LEFT, 2); + $addUserButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle( + LocalizationUtility::translate( + 'LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:btn.backendUserGroup.create', + 'beuser' + ) + ) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['be_groups' => [0 => 'new']], + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($addUserButton, ButtonBar::BUTTON_POSITION_LEFT, 3); + $backendGroupTitle = empty($data['group']['title']) ? '' : ': ' . $data['group']['title']; + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate( + 'LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroup', + 'beuser' + ) . $backendGroupTitle, + ['action' => 'showGroup', 'uid' => $uid] + ); + + return $this->moduleTemplate->renderResponse('BackendUserGroup/Show'); + } + + public function compareGroupsAction(): ResponseInterface + { + $compareGroupUidList = array_keys((array)$this->moduleData->get('compareGroupUidList', [])); + + $compareData = []; + foreach ($compareGroupUidList as $uid) { + if ($compareInformation = $this->userInformationService->getGroupInformation($uid)) { + $compareData[] = $compareInformation; + } + } + if (empty($compareData)) { + return $this->redirect('groups'); + } + + $this->moduleTemplate->assignMultiple([ + 'compareGroupList' => $compareData, + 'showUid' => $this->getBackendUser()->shallDisplayDebugInformation(), + ]); + + $this->addMainMenu('compareGroups'); + $this->moduleTemplate->addButtonToButtonBar($this->componentFactory->createBackButton($this->uriBuilder->uriFor('groups'))); + $this->moduleTemplate->getDocHeaderComponent()->setShortcutContext( + 'backend_user_management', + LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:compareBackendUsersGroups', 'beuser'), + ['action' => 'compareGroups'] + ); + + return $this->moduleTemplate->renderResponse('BackendUserGroup/Compare'); + } + + protected function initializeAddGroupToCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Attaches one backend user group to the compare list + */ + public function addGroupToCompareListAction(int $uid): ResponseInterface + { + $this->addToCompareList('compareGroupUidList', $uid); + return $this->redirect('groups'); + } + + protected function initializeRemoveGroupFromCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Removes given backend user group to the compare list + */ + public function removeGroupFromCompareListAction(int $uid, int $redirectToCompare = 0): ResponseInterface + { + $this->removeFromCompareList('compareGroupUidList', $uid); + if ($redirectToCompare) { + return $this->redirect('compareGroups'); + } + return $this->redirect('groups'); + } + + protected function initializeRemoveAllGroupsFromCompareListAction(): void + { + $this->assertAllowedHttpMethod($this->request, 'POST'); + } + + /** + * Removes all backend user groups from the compare list + */ + public function removeAllGroupsFromCompareListAction(): ResponseInterface + { + $this->cleanCompareList('compareGroupUidList'); + return $this->redirect('groups'); + } + + protected function filemountsAction(int $currentPage = 1): ResponseInterface + { + $filemounts = $this->eventDispatcher->dispatch( + new AfterFilemountsListIsAssembledEvent( + $this->request, + $this->fileMountRepository->findAll()->toArray() + ) + )->filemounts; + + $this->addMainMenu('filemounts'); + + $paginator = new ArrayPaginator($filemounts, $currentPage, 50); + $pagination = new SimplePagination($paginator); + $this->moduleTemplate->assignMultiple( + [ + 'paginator' => $paginator, + 'pagination' => $pagination, + 'totalAmountOfFilemounts' => count($filemounts), + ] + ); + + $addFilemountButton = $this->componentFactory->createLinkButton() + ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL)) + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:filemount.create', 'beuser')) + ->setShowLabelText(true) + ->setHref((string)$this->backendUriBuilder->buildUriFromRoute('record_edit', [ + 'edit' => ['sys_filemounts' => [0 => 'new']], + 'module' => 'backend_user_management', + 'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(), + ])); + $this->moduleTemplate->addButtonToButtonBar($addFilemountButton); + + return $this->moduleTemplate->renderResponse('Filemount/List'); + } + + /** + * Create an array with the uids of online users as the keys + * [ + * 1 => true, + * 5 => true + * ] + */ + protected function getOnlineBackendUsers(): array + { + $onlineUsers = $this->backendUserSessionRepository->findAllActive(); + $onlineBackendUsers = []; + foreach ($onlineUsers as $onlineUser) { + $onlineBackendUsers[$onlineUser['ses_userid']] = true; + } + return $onlineBackendUsers; + } + + /** + * Doc header main drop down + */ + protected function addMainMenu(string $currentAction): void + { + $this->uriBuilder->setRequest($this->request); + $menu = $this->componentFactory->createMenu(); + $menu->setIdentifier('BackendUserModuleMenu'); + $menu->setLabel( + LocalizationUtility::translate( + 'LLL:EXT:backend/Resources/Private/Language/locallang.xlf:modulemenu.label', + 'backend', + ) + ); + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUsers', 'beuser')) + ->setHref($this->uriBuilder->uriFor('list')) + ->setActive($currentAction === 'list') + ); + if ($currentAction === 'show') { + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserDetails', 'beuser')) + ->setHref($this->uriBuilder->uriFor('show')) + ->setActive(true) + ); + } + if ($currentAction === 'compare') { + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:compareBackendUsers', 'beuser')) + ->setHref($this->uriBuilder->uriFor('list')) + ->setActive(true) + ); + } + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroupsMenu', 'beuser')) + ->setHref($this->uriBuilder->uriFor('groups')) + ->setActive($currentAction === 'groups') + ); + if ($currentAction === 'showGroup') { + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroupDetails', 'beuser')) + ->setHref($this->uriBuilder->uriFor('showGroup')) + ->setActive(true) + ); + } + if ($currentAction === 'compareGroups') { + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:compareBackendUsersGroups', 'beuser')) + ->setHref($this->uriBuilder->uriFor('compareGroups')) + ->setActive(true) + ); + } + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:onlineUsers', 'beuser')) + ->setHref($this->uriBuilder->uriFor('online')) + ->setActive($currentAction === 'online') + ); + $menu->addMenuItem( + $this->componentFactory->createMenuItem() + ->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:filemounts', 'beuser')) + ->setHref($this->uriBuilder->uriFor('filemounts')) + ->setActive($currentAction === 'filemounts') + ); + $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); + } + + /** + * Attaches the given uid to the requested compare list + */ + protected function addToCompareList(string $listIdentifier, int $uid): void + { + $compareList = (array)$this->moduleData->get($listIdentifier, []); + $compareList[$uid] = true; + $this->moduleData->set($listIdentifier, $compareList); + $this->getBackendUser()->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray()); + } + + /** + * Removes the given uid from the requested compare list + */ + protected function removeFromCompareList(string $listIdentifier, int $uid): void + { + $compareList = (array)$this->moduleData->get($listIdentifier, []); + unset($compareList[$uid]); + $this->moduleData->set($listIdentifier, $compareList); + $this->getBackendUser()->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray()); + } + + /** + * Removes all items from the requested compare list + */ + protected function cleanCompareList(string $listIdentifier): void + { + $this->moduleData->set($listIdentifier, []); + $this->getBackendUser()->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray()); + } + + protected function getBackendUser(): BackendUserAuthentication + { + return $GLOBALS['BE_USER']; + } +} diff --git a/Classes/Controller/PermissionController.php b/Classes/Controller/PermissionController.php new file mode 100644 index 0000000..7e6fe11 --- /dev/null +++ b/Classes/Controller/PermissionController.php @@ -0,0 +1,548 @@ +getParsedBody(); + $queryParams = $request->getQueryParams(); + $backendUser = $this->getBackendUser(); + $lang = $this->getLanguageService(); + + // determine depth parameter + $this->depth = (int)($parsedBody['depth'] ?? $queryParams['depth'] ?? 0); + if (!$this->depth) { + $this->depth = (int)$backendUser->getSessionData(self::SESSION_PREFIX . 'depth'); + } else { + $backendUser->setAndSaveSessionData(self::SESSION_PREFIX . 'depth', $this->depth); + } + + // determine id parameter + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $pageRecord = BackendUtility::getRecord('pages', $this->id); + // Check if a page with the given id exists, otherwise fall back + if ($pageRecord === null) { + $this->id = 0; + } + + $this->returnUrl = GeneralUtility::sanitizeLocalUrl((string)($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? ''), $request); + $this->pageInfo = BackendUtility::readPageAccess($this->id, ' 1=1') ?: [ + 'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], + 'uid' => 0, + 'pid' => 0, + ]; + + $action = (string)($parsedBody['action'] ?? $queryParams['action'] ?? 'index'); + + if ($action === 'update') { + // Update returns a redirect. No further fiddling with view here, return directly. + return $this->updateAction($request); + } + + $view = $this->moduleTemplateFactory->create($request); + if ($backendUser->workspace !== 0) { + $this->addFlashMessage( + $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarningText'), + $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarning'), + ContextualFeedbackSeverity::WARNING + ); + } + $this->registerDocHeaderButtons($view, $action); + $view->setTitle( + $this->getLanguageService()->translate('title', 'beuser.modules.permissions'), + $this->id !== 0 && !empty($this->pageInfo['title']) ? $this->pageInfo['title'] : '' + ); + $view->getDocHeaderComponent()->setPageBreadcrumb($this->pageInfo); + + if ($action === 'edit') { + return $this->editAction($view); + } + return $this->indexAction($view, $request); + } + + public function handleAjaxRequest(ServerRequestInterface $request): ResponseInterface + { + $parsedBody = $request->getParsedBody(); + $conf = [ + 'page' => $parsedBody['page'] ?? null, + 'who' => $parsedBody['who'] ?? null, + 'mode' => $parsedBody['mode'] ?? null, + 'bits' => (int)($parsedBody['bits'] ?? 0), + 'permissions' => (int)($parsedBody['permissions'] ?? 0), + 'action' => $parsedBody['action'] ?? null, + 'ownerUid' => (int)($parsedBody['ownerUid'] ?? 0), + 'username' => $parsedBody['username'] ?? null, + 'groupUid' => (int)($parsedBody['groupUid'] ?? 0), + 'groupname' => $parsedBody['groupname'] ?? '', + 'editLockState' => (int)($parsedBody['editLockState'] ?? 0), + 'new_owner_uid' => (int)($parsedBody['newOwnerUid'] ?? 0), + 'new_group_uid' => (int)($parsedBody['newGroupUid'] ?? 0), + ]; + + // Basic test for required value + if ($conf['page'] <= 0) { + return $this->htmlResponse('This script cannot be called directly', 500); + } + + // Initialize view and always assign current page id + $view = $this->backendViewFactory->create($request); + $view->assign('pageId', $conf['page']); + + // Initialize TCE for execution of updates + $tce = GeneralUtility::makeInstance(DataHandler::class); + // Determine the action to execute + switch ($conf['action'] ?? '') { + case 'show_change_owner_selector': + $template = 'Permission/ChangeOwnerSelector'; + $users = BackendUtility::getUserNames(); + $view->assignMultiple([ + 'elementId' => 'o_' . $conf['page'], + 'ownerUid' => $conf['ownerUid'], + 'username' => $conf['username'], + 'users' => $users, + 'addCurrentUser' => !isset($users[$conf['ownerUid']]), + ]); + break; + case 'show_change_group_selector': + $template = 'Permission/ChangeGroupSelector'; + $groups = BackendUtility::getGroupNames(); + $view->assignMultiple([ + 'elementId' => 'g_' . $conf['page'], + 'groupUid' => $conf['groupUid'], + 'groupname' => $conf['groupname'], + 'groups' => $groups, + 'addCurrentGroup' => !isset($groups[$conf['groupUid']]), + ]); + break; + case 'toggle_edit_lock': + // Initialize requested lock state + $editLockState = $conf['editLockState'] ? 0 : 1; + + // Execute TCE Update + $tce->start([ + 'pages' => [ + $conf['page'] => [ + 'editlock' => $editLockState, + ], + ], + ], []); + $tce->process_datamap(); + + // Setup view + $template = 'Permission/ToggleEditLock'; + $view->assignMultiple([ + 'elementId' => 'el_' . $conf['page'], + 'editLockState' => $editLockState, + ]); + break; + case 'change_owner': + // Check if new owner uid is given (also accept 0 => [not set]) + if ($conf['new_owner_uid'] < 0) { + return $this->htmlResponse('An error occurred: No page owner uid specified', 500); + } + + // Execute TCE Update + $tce->start([ + 'pages' => [ + $conf['page'] => [ + 'perms_userid' => $conf['new_owner_uid'], + ], + ], + ], []); + $tce->process_datamap(); + + // Setup and render view + $template = 'Permission/ChangeOwner'; + $view->assignMultiple([ + 'userId' => $conf['new_owner_uid'], + 'username' => BackendUtility::getUserNames( + 'username', + ' AND uid = ' . $conf['new_owner_uid'] + )[$conf['new_owner_uid']]['username'] ?? '', + ]); + break; + case 'change_group': + // Check if new group uid is given (also accept 0 => [not set]) + if ($conf['new_group_uid'] < 0) { + return $this->htmlResponse('An error occurred: No page group uid specified', 500); + } + + // Execute TCE Update + $tce->start([ + 'pages' => [ + $conf['page'] => [ + 'perms_groupid' => $conf['new_group_uid'], + ], + ], + ], []); + $tce->process_datamap(); + + // Setup and render view + $template = 'Permission/ChangeGroup'; + $view->assignMultiple([ + 'groupId' => $conf['new_group_uid'], + 'groupname' => BackendUtility::getGroupNames( + 'title', + ' AND uid = ' . $conf['new_group_uid'] + )[$conf['new_group_uid']]['title'] ?? '', + ]); + break; + default: + // Initialize permissions state + if ($conf['mode'] === 'delete') { + $conf['permissions'] -= $conf['bits']; + } else { + $conf['permissions'] += $conf['bits']; + } + + // Execute TCE Update + $tce->start([ + 'pages' => [ + $conf['page'] => [ + 'perms_' . $conf['who'] => $conf['permissions'], + ], + ], + ], []); + $tce->process_datamap(); + + // Setup and render view + $template = 'Permission/ChangePermission'; + $view->assignMultiple([ + 'permission' => $conf['permissions'], + 'scope' => $conf['who'], + ]); + } + + return $this->htmlResponse($view->render($template)); + } + + public function indexAction(ModuleTemplate $view, ServerRequestInterface $request): ResponseInterface + { + $view->assignMultiple([ + 'currentId' => $this->id, + 'viewTree' => $this->getTree(), + 'beUsers' => BackendUtility::getUserNames(), + 'beGroups' => BackendUtility::getGroupNames(), + 'depth' => $this->depth, + 'depthBaseUrl' => $this->uriBuilder->buildUriFromRoute('permissions_pages', [ + 'id' => $this->id, + 'depth' => '${value}', + 'action' => 'index', + ]), + 'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute('permissions_pages', [ + 'id' => $this->id, + 'depth' => $this->depth, + 'action' => 'index', + ]), + ]); + + return $view->renderResponse('Permission/Index'); + } + + public function editAction(ModuleTemplate $view): ResponseInterface + { + $lang = $this->getLanguageService(); + $selectNone = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone'); + $selectUnchanged = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectUnchanged'); + + // Owner selector + $beUserDataArray = [0 => $selectNone]; + foreach (BackendUtility::getUserNames() as $uid => $row) { + $beUserDataArray[$uid] = $row['username'] ?? ''; + } + $beUserDataArray[-1] = $selectUnchanged; + + // Group selector + $beGroupDataArray = [0 => $selectNone]; + foreach (BackendUtility::getGroupNames() as $uid => $row) { + $beGroupDataArray[$uid] = $row['title'] ?? ''; + } + $beGroupDataArray[-1] = $selectUnchanged; + + $view->assignMultiple([ + 'id' => $this->id, + 'depth' => $this->depth, + 'currentBeUser' => $this->pageInfo['perms_userid'] ?? 0, + 'beUserData' => $beUserDataArray, + 'currentBeGroup' => $this->pageInfo['perms_groupid'] ?? 0, + 'beGroupData' => $beGroupDataArray, + 'pageInfo' => $this->pageInfo, + 'returnUrl' => $this->returnUrl, + 'recursiveSelectOptions' => $this->getRecursiveSelectOptions(), + 'formAction' => (string)$this->uriBuilder->buildUriFromRoute('permissions_pages', [ + 'action' => 'update', + 'id' => $this->id, + 'depth' => $this->depth, + 'returnUrl' => $this->returnUrl, + ]), + ]); + + return $view->renderResponse('Permission/Edit'); + } + + protected function updateAction(ServerRequestInterface $request): ResponseInterface + { + $data = (array)($request->getParsedBody()['data'] ?? []); + $mirror = (array)($request->getParsedBody()['mirror'] ?? []); + + $dataHandlerInput = []; + // Prepare the input data for data handler + $dataPages = $data['pages'] ?? null; + if (is_array($dataPages) && $dataPages !== []) { + foreach ($dataPages as $pageUid => $properties) { + // if the owner and group field shouldn't be touched, unset the option + if ((int)($properties['perms_userid'] ?? 0) === -1) { + unset($properties['perms_userid']); + } + if ((int)($properties['perms_groupid'] ?? 0) === -1) { + unset($properties['perms_groupid']); + } + $dataHandlerInput[$pageUid] = $properties; + if (!empty($mirror['pages'][$pageUid])) { + $mirrorPages = GeneralUtility::intExplode(',', (string)$mirror['pages'][$pageUid]); + foreach ($mirrorPages as $mirrorPageUid) { + $dataHandlerInput[$mirrorPageUid] = $properties; + } + } + } + } + + $dataHandler = GeneralUtility::makeInstance(DataHandler::class); + $dataHandler->start( + [ + 'pages' => $dataHandlerInput, + ], + [] + ); + $dataHandler->process_datamap(); + + return $this->responseFactory->createResponse(303) + ->withHeader('location', $this->returnUrl); + } + + protected function registerDocHeaderButtons(ModuleTemplate $view, string $action): void + { + $lang = $this->getLanguageService(); + + if ($action === 'edit') { + // CLOSE button: + if ($this->returnUrl !== '') { + $view->addButtonToButtonBar($this->componentFactory->createCloseButton($this->returnUrl)); + } + + // SAVE button: + $saveButton = $this->componentFactory + ->createSaveButton('PermissionControllerEdit') + ->setName('_save') + ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.saveCloseDoc')); + $view->addButtonToButtonBar($saveButton, ButtonBar::BUTTON_POSITION_LEFT, 2); + } + + if ($action === 'index' && count($this->getDepthOptions()) > 0) { + $viewModeItems = []; + $viewModeItems[] = $this->componentFactory->createDropDownHeader() + ->setLabel($lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Depth')); + foreach ($this->getDepthOptions() as $value => $label) { + $viewModeItems[] = $this->componentFactory->createDropDownRadio() + ->setActive($this->depth === $value) + ->setLabel($label) + ->setHref((string)$this->uriBuilder->buildUriFromRoute('permissions_pages', [ + 'id' => $this->id, + 'depth' => $value, + ])); + } + $viewModeButton = $this->componentFactory->createDropDownButton() + ->setLabel($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view')) + ->setIcon($this->iconFactory->getIcon('actions-cog')) + ->setShowLabelText(true); + foreach ($viewModeItems as $viewModeItem) { + $viewModeButton->addItem($viewModeItem); + } + $view->addButtonToButtonBar($viewModeButton, ButtonBar::BUTTON_POSITION_RIGHT, 2); + } + + $view->getDocHeaderComponent()->setShortcutContext( + 'permissions_pages', + $this->getShortcutTitle(), + ['id' => $this->id, 'action' => $action] + ); + } + + protected function getTree(): array + { + $tree = GeneralUtility::makeInstance(PageTreeView::class); + $tree->init(); + + // Create the tree from $this->id + if ($this->id) { + $icon = $this->iconFactory->getIconForRecord('pages', $this->pageInfo, IconSize::SMALL); + } else { + $icon = $this->iconFactory->getIcon('apps-pagetree-root', IconSize::SMALL); + } + $iconMarkup = '' . $icon->render() . ''; + $tree->tree[] = ['row' => $this->pageInfo, 'HTML' => '', 'icon' => $iconMarkup]; + $tree->getTree($this->id, $this->depth); + + return $tree->tree; + } + + protected function getDepthOptions(): array + { + $depthOptions = []; + foreach (self::DEPTH_LEVELS as $depthLevel) { + $levelLabel = $depthLevel === 1 ? 'level' : 'levels'; + $depthOptions[$depthLevel] = $depthLevel . ' ' . $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $levelLabel); + } + return $depthOptions; + } + + /** + * Finding tree and offer setting of values recursively. + */ + protected function getRecursiveSelectOptions(): array + { + $lang = $this->getLanguageService(); + // Initialize tree object: + $tree = GeneralUtility::makeInstance(PageTreeView::class); + $tree->init(); + $tree->makeHTML = false; + // Make tree: + $tree->getTree($this->id, self::RECURSIVE_LEVELS); + $options = [ + '' => $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone'), + ]; + // If there are a hierarchy of page ids, then... + if (!empty($tree->orig_ids_hierarchy) && ($this->getBackendUser()->user['uid'] ?? false)) { + // Init: + $labelRecursive = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:recursive'); + $labelLevel = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:level'); + $labelLevels = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:levels'); + $labelPageAffected = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:page_affected'); + $labelPagesAffected = $lang->sL('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:pages_affected'); + $theIdListArr = []; + // Traverse the number of levels we want to allow recursive + // setting of permissions for: + for ($a = self::RECURSIVE_LEVELS; $a > 0; $a--) { + if (is_array($tree->orig_ids_hierarchy[$a] ?? false)) { + foreach ($tree->orig_ids_hierarchy[$a] as $theId) { + $theIdListArr[] = $theId; + } + $lKey = self::RECURSIVE_LEVELS - $a + 1; + $pagesCount = count($theIdListArr); + $options[implode(',', $theIdListArr)] = $labelRecursive . ' ' . $lKey . ' ' . ($lKey === 1 ? $labelLevel : $labelLevels) + . ' (' . $pagesCount . ' ' . ($pagesCount === 1 ? $labelPageAffected : $labelPagesAffected) . ')'; + } + } + } + return $options; + } + + /** + * Adds a flash message to the default flash message queue + */ + protected function addFlashMessage(string $message, string $title = '', ContextualFeedbackSeverity $severity = ContextualFeedbackSeverity::INFO): void + { + $flashMessage = new FlashMessage($message, $title, $severity, true); + $defaultFlashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier(); + $defaultFlashMessageQueue->enqueue($flashMessage); + } + + /** + * Returns the shortcut title for the current page + */ + protected function getShortcutTitle(): string + { + return sprintf( + '%s: %s [%d]', + $this->getLanguageService()->translate('title', 'beuser.modules.permissions'), + BackendUtility::getRecordTitle('pages', $this->pageInfo), + $this->id + ); + } + + protected function htmlResponse(string $html, int $code = 200): ResponseInterface + { + $response = $this->responseFactory->createResponse($code) + ->withHeader('Content-Type', 'text/html; charset=utf-8'); + $response->getBody()->write($html); + return $response; + } + + protected function getBackendUser(): BackendUserAuthentication + { + return $GLOBALS['BE_USER']; + } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Classes/Domain/Dto/BackendUserGroup.php b/Classes/Domain/Dto/BackendUserGroup.php new file mode 100644 index 0000000..3149bbd --- /dev/null +++ b/Classes/Domain/Dto/BackendUserGroup.php @@ -0,0 +1,45 @@ +title = (string)($uc['title'] ?? ''); + return $demand; + } + + public function getTitle(): string + { + return $this->title; + } + + public function forUc(): array + { + return [ + 'title' => $this->title, + ]; + } +} diff --git a/Classes/Domain/Model/BackendUser.php b/Classes/Domain/Model/BackendUser.php new file mode 100644 index 0000000..4f5dba5 --- /dev/null +++ b/Classes/Domain/Model/BackendUser.php @@ -0,0 +1,240 @@ + + */ + protected ObjectStorage $backendUserGroups; + + /** + * Comma separated list of uids in multi-select + * Might retrieve the labels from TCA/DataMapper + */ + protected string $allowedLanguages = ''; + + protected string $dbMountPoints = ''; + protected string $description = ''; + protected string $fileMountPoints = ''; + protected bool $isAdministrator = false; + protected bool $isDisabled = false; + protected ?\DateTime $startDateAndTime = null; + protected ?\DateTime $endDateAndTime = null; + protected string $email = ''; + protected string $realName = ''; + protected ?\DateTime $lastLoginDateAndTime = null; + + public function __construct() + { + $this->initializeObject(); + } + + public function initializeObject(): void + { + $this->backendUserGroups = new ObjectStorage(); + } + + public function setAllowedLanguages(string $allowedLanguages): void + { + $this->allowedLanguages = $allowedLanguages; + } + + public function getAllowedLanguages(): string + { + return $this->allowedLanguages; + } + + public function setDbMountPoints(string $dbMountPoints): void + { + $this->dbMountPoints = $dbMountPoints; + } + + public function getDbMountPoints(): string + { + return $this->dbMountPoints; + } + + public function setFileMountPoints(string $fileMountPoints): void + { + $this->fileMountPoints = $fileMountPoints; + } + + public function getFileMountPoints(): string + { + return $this->fileMountPoints; + } + + /** + * Check if user is active, not disabled + */ + public function isActive(): bool + { + if ($this->getIsDisabled()) { + return false; + } + $now = new \DateTime('now'); + return (!$this->getStartDateAndTime() && !$this->getEndDateAndTime()) || ($this->getStartDateAndTime() <= $now && (!$this->getEndDateAndTime() || $this->getEndDateAndTime() > $now)); + } + + public function setBackendUserGroups(ObjectStorage $backendUserGroups): void + { + $this->backendUserGroups = $backendUserGroups; + } + + /** + * @return ObjectStorage + */ + public function getBackendUserGroups(): ObjectStorage + { + return $this->backendUserGroups; + } + + /** + * Check if user is currently logged in + */ + public function isCurrentlyLoggedIn(): bool + { + return $this->getUid() === (int)($this->getBackendUser()->user['uid'] ?? 0); + } + + /** + * Check if the user is allowed to trigger a password reset + * + * Requirements: + * 1. The user for which the password reset should be triggered is not the currently logged in user + * 2. Password reset is enabled for the user (Email+Password are set) + * 3. The currently logged in user is allowed to reset passwords in the backend (Enabled in user TSconfig) + */ + public function isPasswordResetEnabled(): bool + { + return !$this->isCurrentlyLoggedIn() + && GeneralUtility::makeInstance(PasswordReset::class)->isEnabledForUser((int)$this->getUid()) + && ($this->getBackendUser()->getTSConfig()['options.']['passwordReset'] ?? true); + } + + public function getUserName(): string + { + return $this->userName; + } + + public function setUserName(string $userName): void + { + $this->userName = $userName; + } + + public function getDescription(): string + { + return $this->description; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function getIsAdministrator(): bool + { + return $this->isAdministrator; + } + + public function setIsAdministrator(bool $isAdministrator): void + { + $this->isAdministrator = $isAdministrator; + } + + public function getIsDisabled(): bool + { + return $this->isDisabled; + } + + public function setIsDisabled(bool $isDisabled): void + { + $this->isDisabled = $isDisabled; + } + + public function getStartDateAndTime(): ?\DateTime + { + return $this->startDateAndTime; + } + + public function setStartDateAndTime(?\DateTime $dateAndTime = null): void + { + $this->startDateAndTime = $dateAndTime; + } + + public function getEndDateAndTime(): ?\DateTime + { + return $this->endDateAndTime; + } + + public function setEndDateAndTime(?\DateTime $dateAndTime = null): void + { + $this->endDateAndTime = $dateAndTime; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail(string $email): void + { + $this->email = $email; + } + + public function getRealName(): string + { + return $this->realName; + } + + public function setRealName(string $name): void + { + $this->realName = $name; + } + + public function getLastLoginDateAndTime(): ?\DateTime + { + return $this->lastLoginDateAndTime; + } + + public function setLastLoginDateAndTime(?\DateTime $dateAndTime = null): void + { + $this->lastLoginDateAndTime = $dateAndTime; + } + + public function getBackendUser(): BackendUserAuthentication + { + return $GLOBALS['BE_USER']; + } +} diff --git a/Classes/Domain/Model/BackendUserGroup.php b/Classes/Domain/Model/BackendUserGroup.php new file mode 100644 index 0000000..dbf96cd --- /dev/null +++ b/Classes/Domain/Model/BackendUserGroup.php @@ -0,0 +1,89 @@ + + */ + #[Extbase\ORM\Lazy] + protected ObjectStorage $subGroups; + + public function __construct() + { + $this->initializeObject(); + } + + public function initializeObject(): void + { + $this->subGroups = new ObjectStorage(); + } + + public function setTitle(string $title): void + { + $this->title = $title; + } + + public function getTitle(): string + { + return $this->title; + } + + public function getDescription(): string + { + return $this->description; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function setHidden(bool $hidden): void + { + $this->hidden = $hidden; + } + + public function getHidden(): bool + { + return $this->hidden; + } + + public function setSubGroups(ObjectStorage $subGroups): void + { + $this->subGroups = $subGroups; + } + + public function getSubGroups(): ObjectStorage + { + return $this->subGroups; + } +} diff --git a/Classes/Domain/Model/Demand.php b/Classes/Domain/Model/Demand.php new file mode 100644 index 0000000..7cdddc5 --- /dev/null +++ b/Classes/Domain/Model/Demand.php @@ -0,0 +1,115 @@ +userName = (string)($uc['userName'] ?? ''); + $demand->userType = (int)($uc['userType'] ?? 0); + $demand->status = (int)($uc['status'] ?? 0); + $demand->logins = (int)($uc['logins'] ?? 0); + $demand->backendUserGroup = (int)($uc['backendUserGroup'] ?? 0); + return $demand; + } + + public function forUc(): array + { + return [ + 'userName' => $this->getUserName(), + 'userType' => $this->getUserType(), + 'status' => $this->getStatus(), + 'logins' => $this->getLogins(), + 'backendUserGroup' => $this->getBackendUserGroup(), + ]; + } + + public function setUserName(string $userName): void + { + $this->userName = $userName; + } + + public function getUserName(): string + { + return $this->userName; + } + + public function setUserType(int $userType): void + { + $this->userType = $userType; + } + + public function getUserType(): int + { + return $this->userType; + } + + public function setStatus(int $status): void + { + $this->status = $status; + } + + public function getStatus(): int + { + return $this->status; + } + + public function setLogins(int $logins): void + { + $this->logins = $logins; + } + + public function getLogins(): int + { + return $this->logins; + } + + public function setBackendUserGroup(int $backendUserGroup): void + { + $this->backendUserGroup = $backendUserGroup; + } + + public function getBackendUserGroup(): int + { + return $this->backendUserGroup; + } +} diff --git a/Classes/Domain/Model/FileMount.php b/Classes/Domain/Model/FileMount.php new file mode 100644 index 0000000..fe707ef --- /dev/null +++ b/Classes/Domain/Model/FileMount.php @@ -0,0 +1,140 @@ +title; + } + + /** + * Setter for the title of the file mount. + */ + public function setTitle(string $value): void + { + $this->title = $value; + } + + /** + * Getter for the description of the file mount. + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * Setter for the description of the file mount. + */ + public function setDescription(string $description): void + { + $this->description = $description; + } + + /** + * Setter for the readOnly property of the file mount. + */ + public function setReadOnly(bool $readOnly): void + { + $this->readOnly = $readOnly; + } + + /** + * Getter for the readOnly property of the file mount. + */ + public function isReadOnly(): bool + { + return $this->readOnly; + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function setIdentifier(string $identifier): void + { + $this->identifier = $identifier; + } + + public function isHidden(): bool + { + return $this->hidden; + } + + public function setHidden(bool $hidden): void + { + $this->hidden = $hidden; + } + + /** + * returns the path segment of the file mount (without the storage id) + */ + public function getPath(): string + { + return explode(':/', $this->identifier)[1] ?? ''; + } + + /** + * @todo This should be part of the ORM not the model class + */ + public function getStorage(): ?ResourceStorage + { + return GeneralUtility::makeInstance(StorageRepository::class)->findByCombinedIdentifier($this->identifier); + } +} diff --git a/Classes/Domain/Repository/BackendUserGroupRepository.php b/Classes/Domain/Repository/BackendUserGroupRepository.php new file mode 100644 index 0000000..d0cc4e4 --- /dev/null +++ b/Classes/Domain/Repository/BackendUserGroupRepository.php @@ -0,0 +1,117 @@ + + */ +class BackendUserGroupRepository extends Repository +{ + public const TABLE_NAME = 'be_groups'; + + protected $defaultOrderings = [ + 'title' => QueryInterface::ORDER_ASCENDING, + ]; + + /** + * Overwrite createQuery to don't respect enable fields + */ + public function createQuery(): QueryInterface + { + $query = parent::createQuery(); + $query->getQuerySettings()->setIgnoreEnableFields(true); + return $query; + } + + /** + * Get QueryBuilder without restrictions for table be_groups + */ + public function getQueryBuilder(bool $removeRestrictions = true): QueryBuilder + { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME); + if ($removeRestrictions === true) { + $queryBuilder->getRestrictions()->removeAll(); + } + + return $queryBuilder; + } + + /** + * Finds Backend Usergroups on a given list of uids + */ + public function findByUidList(array $uidList): array + { + $query = $this->createQuery(); + // being explicit here, albeit `Typo3DbQueryParser::parseDynamicOperand` uses prepared parameters + $uidList = array_map(intval(...), $uidList); + $query->matching($query->in('uid', $uidList)); + return $query->execute(true); + } + + /** + * Preforms a query on be_groups, matching the field title with like + * @throws InvalidQueryException + */ + public function findByFilter(BackendUserGroup $backendUserGroupDto): QueryResult + { + $constraints = []; + $query = $this->createQuery(); + $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]); + if ($backendUserGroupDto->getTitle() !== '') { + $searchConstraints = []; + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME); + $searchConstraints[] = $query->like( + 'title', + '%' . $queryBuilder->escapeLikeWildcards($backendUserGroupDto->getTitle()) . '%' + ); + + if (MathUtility::canBeInterpretedAsInteger($backendUserGroupDto->getTitle())) { + $searchConstraints[] = $query->equals('uid', (int)$backendUserGroupDto->getTitle()); + } + + if (count($searchConstraints) >= 2) { + $constraints[] = $query->logicalOr(...$searchConstraints); + } else { + $constraints = $searchConstraints; + } + } + $constraints = $this->eventDispatcher->dispatch( + new AfterBackendGroupListConstraintsAssembledFromDemandEvent( + $backendUserGroupDto, + $query, + $constraints + ) + )->constraints; + $query->matching($query->logicalAnd(...$constraints)); + /** @var QueryResult $result */ + $result = $query->execute(); + + return $result; + } +} diff --git a/Classes/Domain/Repository/BackendUserRepository.php b/Classes/Domain/Repository/BackendUserRepository.php new file mode 100644 index 0000000..f17eeeb --- /dev/null +++ b/Classes/Domain/Repository/BackendUserRepository.php @@ -0,0 +1,171 @@ + + */ +class BackendUserRepository extends Repository +{ + /** + * Finds Backend Users on a given list of uids + */ + public function findByUidList(array $uidList): QueryResult + { + $query = $this->createQuery(); + $query->matching($query->in('uid', array_map(intval(...), $uidList))); + /** @var QueryResult $result */ + $result = $query->execute(); + return $result; + } + + /** + * Find Backend Users matching to Demand object properties + */ + public function findDemanded(Demand $demand): QueryResult + { + $constraints = []; + $query = $this->createQuery(); + $query->setOrderings(['userName' => QueryInterface::ORDER_ASCENDING]); + // Username + if ($demand->getUserName() !== '') { + $searchConstraints = []; + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users'); + foreach (['userName', 'realName'] as $field) { + $searchConstraints[] = $query->like( + $field, + '%' . $queryBuilder->escapeLikeWildcards($demand->getUserName()) . '%' + ); + } + if (MathUtility::canBeInterpretedAsInteger($demand->getUserName())) { + $searchConstraints[] = $query->equals('uid', (int)$demand->getUserName()); + } + if (count($searchConstraints) === 1) { + $constraints[] = reset($searchConstraints); + } else { + $constraints[] = $query->logicalOr(...$searchConstraints); + } + } + + switch ($demand->getUserType()) { + case Demand::USERTYPE_ADMINONLY: + // Only display admin users + $constraints[] = $query->equals('admin', 1); + break; + case Demand::USERTYPE_USERONLY: + // Only display non-admin users + $constraints[] = $query->equals('admin', 0); + break; + } + + switch ($demand->getStatus()) { + case Demand::STATUS_ACTIVE: + // Only display active users + $constraints[] = $query->equals('disable', 0); + break; + case Demand::STATUS_INACTIVE: + // Only display in-active users + $constraints[] = $query->equals('disable', 1); + break; + } + + switch ($demand->getLogins()) { + case Demand::LOGIN_NONE: + // Not logged in before + $constraints[] = $query->equals('lastlogin', 0); + break; + case Demand::LOGIN_SOME: + // At least one login + $constraints[] = $query->logicalNot($query->equals('lastlogin', 0)); + break; + + case Demand::LOGIN_CURRENT: + // Currently logged-in users + $sessionTimeout = (int)($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] ?? 28800); + $constraints[] = $query->greaterThanOrEqual('lastlogin', time() - $sessionTimeout); + } + + // In backend user group + if ($demand->getBackendUserGroup()) { + $constraints[] = $query->logicalOr( + $query->equals('usergroup', $demand->getBackendUserGroup()), + $query->like('usergroup', $demand->getBackendUserGroup() . ',%'), + $query->like('usergroup', '%,' . $demand->getBackendUserGroup()), + $query->like('usergroup', '%,' . $demand->getBackendUserGroup() . ',%'), + ); + } + $constraints = $this->eventDispatcher->dispatch( + new AfterBackendUserListConstraintsAssembledFromDemandEvent( + $demand, + $query, + $constraints + ) + )->constraints; + $query->matching($query->logicalAnd(...$constraints)); + + /** @var QueryResult $result */ + $result = $query->execute(); + return $result; + } + + /** + * Find Backend Users currently online + */ + public function findOnline(): QueryResult + { + $uids = []; + foreach ($this->getSessionBackend()->getAll() as $sessionRecord) { + if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) { + $uids[] = $sessionRecord['ses_userid']; + } + } + + $query = $this->createQuery(); + $query->matching($query->in('uid', $uids)); + /** @var QueryResult $result */ + $result = $query->execute(); + return $result; + } + + /** + * Overwrite createQuery to don't respect enable fields + */ + public function createQuery(): QueryInterface + { + $query = parent::createQuery(); + $query->getQuerySettings()->setIgnoreEnableFields(true); + return $query; + } + + protected function getSessionBackend(): SessionBackendInterface + { + return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE'); + } +} diff --git a/Classes/Domain/Repository/BackendUserSessionRepository.php b/Classes/Domain/Repository/BackendUserSessionRepository.php new file mode 100644 index 0000000..5f078d2 --- /dev/null +++ b/Classes/Domain/Repository/BackendUserSessionRepository.php @@ -0,0 +1,93 @@ +sessionBackend = GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE'); + } + + /** + * Find all active sessions for all backend users + */ + public function findAllActive(): array + { + $allSessions = $this->sessionBackend->getAll(); + + // Map array to correct keys + $allSessions = array_map( + static function (array $session): array { + return [ + 'id' => $session['ses_id'], // this is the hashed sessionId + 'ip' => $session['ses_iplock'], + 'timestamp' => $session['ses_tstamp'], + 'ses_userid' => $session['ses_userid'], + ]; + }, + $allSessions + ); + + // Sort by timestamp + usort($allSessions, static function ($session1, $session2) { + return $session1['timestamp'] <=> $session2['timestamp']; + }); + + return $allSessions; + } + + /** + * Find Sessions for specific BackendUser + */ + public function findByBackendUser(BackendUser $backendUser): array + { + $allActive = $this->findAllActive(); + + return array_filter( + $allActive, + static function (array $session) use ($backendUser): bool { + return (int)$session['ses_userid'] === $backendUser->getUid(); + } + ); + } + + public function getPersistedSessionIdentifier(AbstractUserAuthentication $userObject): string + { + $currentSessionId = $userObject->getSession()->getIdentifier(); + if ($this->sessionBackend instanceof HashableSessionBackendInterface) { + $currentSessionId = $this->sessionBackend->hash($currentSessionId); + } + return $currentSessionId; + } + + public function terminateSessionByIdentifier(string $sessionIdentifier): bool + { + return $this->sessionBackend->remove($sessionIdentifier); + } +} diff --git a/Classes/Domain/Repository/FileMountRepository.php b/Classes/Domain/Repository/FileMountRepository.php new file mode 100644 index 0000000..3541361 --- /dev/null +++ b/Classes/Domain/Repository/FileMountRepository.php @@ -0,0 +1,39 @@ + + */ +class FileMountRepository extends Repository +{ + public function initializeObject(): void + { + /** @var Typo3QuerySettings $querySettings */ + $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); + $querySettings->setRespectStoragePage(false); + $querySettings->setIgnoreEnableFields(true); + $this->setDefaultQuerySettings($querySettings); + } +} diff --git a/Classes/Event/AfterBackendGroupFilterListIsAssembledEvent.php b/Classes/Event/AfterBackendGroupFilterListIsAssembledEvent.php new file mode 100644 index 0000000..b3d2a64 --- /dev/null +++ b/Classes/Event/AfterBackendGroupFilterListIsAssembledEvent.php @@ -0,0 +1,31 @@ +enablecolumns = [ + 'deleted' => true, + ]; + + // Setup dummy user to allow fetching all group data + // @see \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::fetchGroups + $user->user = [ + 'uid' => PHP_INT_MAX, + 'options' => 3, + // The below admin flag is required to prevent workspace access checks, + // triggered by workspaceInit() in fetchGroupData(). Those would fail + // due to insufficient permissions of the dummy user and therefore might + // result in generating superfluous log entries. + 'admin' => 1, + 'workspace_id' => 0, + 'realName' => 'fakeUser', + 'email' => 'fake.user@typo3.org', + 'TSconfig' => '', + 'category_perms' => '', + $user->usergroup_column => $groupId, + ]; + $user->fetchGroupData(); + + $data = $this->convert($user); + $data['group'] = $usergroupRecord; + + return $data; + } + + /** + * Get all relevant information of the user + */ + public function getUserInformation(int $userId): array + { + $user = GeneralUtility::makeInstance(BackendUserAuthentication::class); + $user->enablecolumns = [ + 'deleted' => true, + ]; + $user->setBeUserByUid($userId); + if (!$user->user) { + return []; + } + $user->fetchGroupData(); + + return $this->convert($user); + } + + /** + * Convert hard readable user & group information into structured + * data which can be rendered later + */ + private function convert(BackendUserAuthentication $user): array + { + // usergroups + $data = [ + 'user' => $user->user ?? [], + 'groups' => [ + 'inherit' => $user->userGroupsUID, + 'direct' => GeneralUtility::trimExplode(',', (string)($user->user['usergroup'] ?? ''), true), + ], + 'modules' => [], + ]; + $data['groups']['diff'] = array_diff($data['groups']['inherit'], $data['groups']['direct']); + foreach ($data['groups'] as $type => $groups) { + foreach ($groups as $id) { + $record = BackendUtility::getRecord('be_groups', (int)$id); + if (isset($record['uid'])) { + $recordId = $record['uid']; + $data['groups']['all'][$recordId]['row'] = $record; + $data['groups']['all'][$recordId][$type] = 1; + } + } + } + + // languages + $siteLanguages = $this->getAllSiteLanguages(); + $userLanguages = GeneralUtility::trimExplode(',', $user->groupData['allowed_languages'] ?? '', true); + asort($userLanguages); + foreach ($userLanguages as $languageId) { + $languageId = (int)$languageId; + $record = $siteLanguages[$languageId] ?? null; + if ($record) { + $data['languages'][$languageId] = $record; + } + } + + // table permissions + $data['tables']['tables_select'] = []; + $data['tables']['tables_modify'] = []; + foreach (['tables_select', 'tables_modify'] as $tableField) { + $temp = GeneralUtility::trimExplode(',', $user->groupData[$tableField] ?? '', true); + foreach ($temp as $tableName) { + if ($this->tcaSchemaFactory->has($tableName)) { + $data['tables'][$tableField][$tableName] = $this->tcaSchemaFactory->get($tableName)->getTitle() ?: $tableName; + } + } + } + $data['tables']['all'] = array_replace($data['tables']['tables_select'], $data['tables']['tables_modify']); + + // Page Tree Entry Points / dbMounts + $dbMounts = GeneralUtility::trimExplode(',', $user->groupData['webmounts'] ?? '', true); + asort($dbMounts); + foreach ($dbMounts as $mount) { + $record = BackendUtility::getRecord('pages', (int)$mount); + if ($record) { + $data['dbMounts'][] = $record; + } + } + + // File mounts + $fileMounts = GeneralUtility::trimExplode(',', $user->groupData['filemounts'] ?? '', true); + asort($fileMounts); + foreach ($fileMounts as $mount) { + $record = BackendUtility::getRecord('sys_filemounts', (int)$mount); + if ($record) { + $data['fileMounts'][] = $record; + } + } + + // Modules + $modules = GeneralUtility::trimExplode(',', $user->groupData['modules'] ?? '', true); + foreach ($modules as $moduleIdentifier) { + if ($this->moduleProvider->isModuleRegistered($moduleIdentifier)) { + $data['modules'][] = $this->moduleProvider->getModule($moduleIdentifier); + } + } + + // Categories + $categories = $user->getCategoryMountPoints(); + foreach ($categories as $category) { + $record = BackendUtility::getRecord('sys_category', $category); + if ($record) { + $data['categories'][$category] = $record; + } + } + + // workspaces + if (ExtensionManagementUtility::isLoaded('workspaces')) { + $data['workspaces'] = [ + 'loaded' => true, + 'record' => $user->workspaceRec, + ]; + } + + // file & folder permissions + $filePermissions = $user->groupData['file_permissions'] ?? ''; + if ($filePermissions) { + $items = GeneralUtility::trimExplode(',', $filePermissions, true); + /** @var StaticSelectFieldType $fieldType */ + $fieldType = $this->tcaSchemaFactory->get('be_groups')->getField('file_permissions'); + foreach ($fieldType->getConfiguration()['items'] ?? [] as $availableItem) { + if (in_array($availableItem['value'], $items, true)) { + $data['fileFolderPermissions'][] = $availableItem; + } + } + } + + // tsconfig + $data['tsconfig'] = $user->getTSConfig(); + + // non_exclude_fields + $fieldListTmp = GeneralUtility::trimExplode(',', $user->groupData['non_exclude_fields'] ?? '', true); + $fieldList = []; + foreach ($fieldListTmp as $item) { + $itemParts = explode(':', $item); + $itemTable = $itemParts[0]; + $itemField = $itemParts[1] ?? ''; + if (!empty($itemField) && $this->tcaSchemaFactory->has($itemTable)) { + $schema = $this->tcaSchemaFactory->get($itemTable); + $fieldList[$itemTable]['label'] = $schema->getTitle(); + if ($schema->hasField($itemField)) { + $fieldList[$itemTable]['fields'][$itemField] = $schema->getField($itemField)->getLabel(); + } + } + } + $data['non_exclude_fields'] = $fieldList; + + // page types + foreach ($this->pageDoktypeRegistry->getAllDoktypes() as $specialItem) { + if (!GeneralUtility::inList($user->groupData['pagetypes_select'] ?? '', $specialItem->getValue())) { + continue; + } + $label = $specialItem->getLabel(); + $icon = $specialItem->getIcon() ?? 'apps-pagetree-page-default'; + $data['pageTypes'][] = ['label' => $label, 'value' => $specialItem->getValue(), 'icon' => $icon]; + } + + // page content types + $pageContentTypes = GeneralUtility::trimExplode(',', $user->groupData['explicit_allowdeny'] ?? '', true); + foreach ($pageContentTypes as $item) { + $split = explode(':', $item); + if (count($split) !== 3) { + continue; + } + [$table, $recordType, $recordTypeValue] = $split; + $label = $this->schemaLabelResolver->getLabelForFieldValue(...$split); + $data['pageContentTypes'][] = [ + // If label is empty => the record type value does not exist so we use "empty-empty" as icon instead of falling back to the default record type icon + 'icon' => $label ? $this->iconFactory->getIconForRecord($table, [$recordType => $recordTypeValue], IconSize::SMALL)->getIdentifier() : 'install-check-extables', + 'label' => $label, + 'shortType' => $recordTypeValue, + 'longType' => $item, + ]; + } + + return $data; + } + + private function getAllSiteLanguages(): array + { + $siteLanguages = []; + foreach ($this->siteFinder->getAllSites() as $site) { + foreach ($site->getAllLanguages() as $languageId => $language) { + if (isset($siteLanguages[$languageId])) { + // Language already provided by another site, check if values differ + if (!str_contains($siteLanguages[$languageId]['title'], $language->getTitle())) { + // Language already provided by another site, but with a different title + $siteLanguages[$languageId]['title'] .= ', ' . $language->getTitle(); + } + if ($siteLanguages[$languageId]['flagIconIdentifier'] !== $language->getFlagIdentifier()) { + // Language already provided by another site, but with a different flag icon identifier + $siteLanguages[$languageId]['flagIconIdentifier'] = 'flags-multiple'; + } + } else { + $siteLanguages[$languageId] = [ + 'title' => $language->getTitle(), + 'flagIconIdentifier' => $language->getFlagIdentifier(), + ]; + } + } + } + return $siteLanguages; + } +} diff --git a/Classes/ViewHelpers/ArrayElementViewHelper.php b/Classes/ViewHelpers/ArrayElementViewHelper.php new file mode 100644 index 0000000..160a793 --- /dev/null +++ b/Classes/ViewHelpers/ArrayElementViewHelper.php @@ -0,0 +1,68 @@ + + * ``` + * + * @internal + */ +final class ArrayElementViewHelper extends AbstractViewHelper +{ + public function initializeArguments(): void + { + $this->registerArgument('array', 'array', 'Array to search in', true); + $this->registerArgument('key', 'string', 'Key to return its value', true); + $this->registerArgument('subKey', 'string', 'If result of key access is an array, subkey can be used to fetch an element from this again', false, ''); + } + + /** + * Return array element by key. Accessed values must be scalar (string, int, float or double) + * + * @throws Exception + */ + public function render(): string + { + $array = $this->arguments['array']; + $key = $this->arguments['key']; + $subKey = $this->arguments['subKey']; + $result = ''; + if (isset($array[$key])) { + $result = $array[$key]; + if (is_array($result) && $subKey && isset($result[$subKey])) { + $result = $result[$subKey]; + } + } + if (!is_scalar($result)) { + throw new Exception('Only scalar return values (string, int, float or double) are supported.', 1382284105); + } + return (string)$result; + } +} diff --git a/Classes/ViewHelpers/IsArrayViewHelper.php b/Classes/ViewHelpers/IsArrayViewHelper.php new file mode 100644 index 0000000..03b684e --- /dev/null +++ b/Classes/ViewHelpers/IsArrayViewHelper.php @@ -0,0 +1,38 @@ +registerArgument('value', 'mixed', 'The variable being checked', true); + } + + public function render(): bool + { + return is_array($this->arguments['value']); + } +} diff --git a/Classes/ViewHelpers/MfaStatusViewHelper.php b/Classes/ViewHelpers/MfaStatusViewHelper.php new file mode 100644 index 0000000..3c43068 --- /dev/null +++ b/Classes/ViewHelpers/MfaStatusViewHelper.php @@ -0,0 +1,84 @@ + + * ``` + * + * @internal + */ +final class MfaStatusViewHelper extends AbstractTagBasedViewHelper +{ + protected $tagName = 'span'; + + public function __construct( + private readonly MfaProviderRegistry $mfaProviderRegistry + ) { + parent::__construct(); + } + + public function initializeArguments(): void + { + parent::initializeArguments(); + $this->registerArgument('userUid', 'int', 'The uid of the user to check', true); + } + + public function render(): string + { + $userUid = (int)($this->arguments['userUid'] ?? 0); + if (!$userUid) { + return ''; + } + + $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class); + $backendUser->enablecolumns = ['deleted' => true]; + $backendUser->setBeUserByUid($userUid); + + // Check if user has active providers + if (!$this->mfaProviderRegistry->hasActiveProviders($backendUser)) { + return ''; + } + + // Check locked providers + if ($this->mfaProviderRegistry->hasLockedProviders($backendUser)) { + $this->tag->addAttribute('class', 'badge badge-warning'); + $this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:lockedMfaProviders'))); + return $this->tag->render(); + } + + // Add mfa enabled label since we have active providers and non of them are locked + $this->tag->addAttribute('class', 'badge badge-info'); + $this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:mfaEnabled'))); + return $this->tag->render(); + } + + private function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Classes/ViewHelpers/PermissionsViewHelper.php b/Classes/ViewHelpers/PermissionsViewHelper.php new file mode 100644 index 0000000..552851d --- /dev/null +++ b/Classes/ViewHelpers/PermissionsViewHelper.php @@ -0,0 +1,107 @@ + + * ``` + * + * @internal + */ +final class PermissionsViewHelper extends AbstractViewHelper +{ + private const array MASKS = [1, 16, 2, 4, 8]; + + /** + * As this ViewHelper renders HTML, the output must not be escaped. + * + * @var bool + */ + protected $escapeOutput = false; + + public function __construct( + private readonly IconFactory $iconFactory, + #[Autowire(service: 'cache.runtime')] + private readonly FrontendInterface $cachePermissionLabels + ) {} + + public function initializeArguments(): void + { + $this->registerArgument('permission', 'int', 'Current permission', true); + $this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true); + $this->registerArgument('pageId', 'int', 'Page ID to evaluate permission for', true); + } + + public function render(): string + { + $icon = ''; + foreach (self::MASKS as $mask) { + if ($this->arguments['permission'] & $mask) { + $iconIdentifier = 'actions-check'; + $iconClass = 'text-success'; + $mode = 'delete'; + } else { + $iconIdentifier = 'actions-close'; + $iconClass = 'text-danger'; + $mode = 'add'; + } + + $label = $this->resolvePermissionLabel($mask); + $icon .= '' + . $this->iconFactory->getIcon($iconIdentifier, IconSize::SMALL)->render(SvgIconProvider::MARKUP_IDENTIFIER_INLINE) + . ''; + } + return $icon; + } + + private function resolvePermissionLabel(int $mask): string + { + $cacheIdentifier = 'beuser-viewhelper-permission_' . $mask; + if (!$this->cachePermissionLabels->has($cacheIdentifier)) { + $this->cachePermissionLabels->set($cacheIdentifier, htmlspecialchars($this->getLanguageService()->sL( + 'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask, + ))); + } + return $this->cachePermissionLabels->get($cacheIdentifier); + } + + private function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php b/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php new file mode 100644 index 0000000..53d11d5 --- /dev/null +++ b/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php @@ -0,0 +1,83 @@ + + * ``` + * + * @internal + */ +final class SpriteIconForRecordViewHelper extends AbstractViewHelper +{ + /** + * As this ViewHelper renders HTML, the output must not be escaped. + * + * @var bool + */ + protected $escapeOutput = false; + + public function __construct( + private readonly IconFactory $iconFactory + ) {} + + public function initializeArguments(): void + { + parent::initializeArguments(); + $this->registerArgument('table', 'string', '', true); + $this->registerArgument('object', 'object', '', true); + } + + /** + * Displays spriteIcon for database table and object + */ + public function render(): string + { + $object = $this->arguments['object']; + $table = $this->arguments['table']; + + if (!method_exists($object, 'getUid')) { + return ''; + } + $row = [ + 'uid' => $object->getUid(), + 'startTime' => false, + 'endTime' => false, + ]; + if (method_exists($object, 'getIsDisabled')) { + $row['disable'] = $object->getIsDisabled(); + } + if (method_exists($object, 'getHidden')) { + $row['hidden'] = $object->getHidden(); + } + if (method_exists($object, 'getStartDateAndTime')) { + $row['startTime'] = $object->getStartDateAndTime(); + } + if (method_exists($object, 'getEndDateAndTime')) { + $row['endTime'] = $object->getEndDateAndTime(); + } + return $this->iconFactory->getIconForRecord($table, $row, IconSize::SMALL)->render(); + } +} diff --git a/Classes/ViewHelpers/SwitchUserViewHelper.php b/Classes/ViewHelpers/SwitchUserViewHelper.php new file mode 100644 index 0000000..04a8b02 --- /dev/null +++ b/Classes/ViewHelpers/SwitchUserViewHelper.php @@ -0,0 +1,89 @@ + + * ``` + * + * @internal + */ +final class SwitchUserViewHelper extends AbstractTagBasedViewHelper +{ + /** + * @var string + */ + protected $tagName = 'typo3-backend-switch-user'; + + public function __construct( + private readonly IconFactory $iconFactory + ) { + parent::__construct(); + } + + public function initializeArguments(): void + { + parent::initializeArguments(); + $this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true); + } + + public function render(): string + { + /** @var BackendUser $targetUser */ + $targetUser = $this->arguments['backendUser']; + $currentUser = self::getBackendUserAuthentication(); + + if ((int)$targetUser->getUid() === (int)$currentUser->getUserId() + || !$targetUser->isActive() + || !$currentUser->isAdmin() + || $currentUser->getOriginalUserIdWhenInSwitchUserMode() !== null + ) { + $this->tag->setTagName('span'); + $this->tag->addAttribute('class', $this->tag->getAttribute('class') . ' disabled'); + $this->tag->addAttribute('disabled', 'disabled'); + $this->tag->setContent($this->iconFactory->getIcon('empty-empty', IconSize::SMALL)->render()); + } else { + $this->tag->addAttribute('title', self::getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:switchBackMode')); + $this->tag->addAttribute('targetUser', (string)$targetUser->getUid()); + $this->tag->setContent($this->iconFactory->getIcon('actions-system-backend-user-switch', IconSize::SMALL)->render()); + } + + $this->tag->forceClosingTag(true); + return $this->tag->render(); + } + + private static function getBackendUserAuthentication(): BackendUserAuthentication + { + return $GLOBALS['BE_USER']; + } + + private static function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Configuration/Backend/AjaxRoutes.php b/Configuration/Backend/AjaxRoutes.php new file mode 100644 index 0000000..ea6674b --- /dev/null +++ b/Configuration/Backend/AjaxRoutes.php @@ -0,0 +1,13 @@ + [ + 'path' => '/users/access/permissions', + 'target' => \TYPO3\CMS\Beuser\Controller\PermissionController::class . '::handleAjaxRequest', + 'inheritAccessFromModule' => 'permissions_pages', + ], +]; diff --git a/Configuration/Backend/Modules.php b/Configuration/Backend/Modules.php new file mode 100644 index 0000000..aec43bc --- /dev/null +++ b/Configuration/Backend/Modules.php @@ -0,0 +1,56 @@ + [ + 'parent' => 'admin', + 'position' => ['after' => 'scheduler'], + 'access' => 'admin', + 'path' => '/module/users/permissions', + 'iconIdentifier' => 'module-permission', + 'navigationComponent' => '@typo3/backend/tree/page-tree-element', + 'labels' => 'beuser.modules.permissions', + 'aliases' => ['system_BeuserTxPermission'], + 'routes' => [ + '_default' => [ + 'target' => PermissionController::class . '::handleRequest', + ], + ], + ], + 'backend_user_management' => [ + 'parent' => 'admin', + 'position' => ['before' => '*'], + 'access' => 'admin', + 'path' => '/module/users/management', + 'iconIdentifier' => 'module-user', + 'labels' => 'beuser.modules.user_management', + 'aliases' => ['system_BeuserTxBeuser'], + 'extensionName' => 'Beuser', + 'controllerActions' => [ + BackendUserController::class => [ + 'index', + 'list', + 'show', + 'addToCompareList', + 'removeFromCompareList', + 'removeAllFromCompareList', + 'compare', + 'online', + 'terminateBackendUserSession', + 'initiatePasswordReset', + 'groups', + 'showGroup', + 'addGroupToCompareList', + 'removeGroupFromCompareList', + 'removeAllGroupsFromCompareList', + 'compareGroups', + 'filemounts', + ], + ], + ], +]; diff --git a/Configuration/Extbase/Persistence/Classes.php b/Configuration/Extbase/Persistence/Classes.php new file mode 100644 index 0000000..b1b7547 --- /dev/null +++ b/Configuration/Extbase/Persistence/Classes.php @@ -0,0 +1,55 @@ + [ + 'tableName' => 'be_users', + 'properties' => [ + 'userName' => [ + 'fieldName' => 'username', + ], + 'isAdministrator' => [ + 'fieldName' => 'admin', + ], + 'isDisabled' => [ + 'fieldName' => 'disable', + ], + 'realName' => [ + 'fieldName' => 'realName', + ], + 'startDateAndTime' => [ + 'fieldName' => 'starttime', + ], + 'endDateAndTime' => [ + 'fieldName' => 'endtime', + ], + 'lastLoginDateAndTime' => [ + 'fieldName' => 'lastlogin', + ], + 'allowedLanguages' => [ + 'fieldName' => 'allowed_languages', + ], + 'fileMountPoints' => [ + 'fieldName' => 'file_mountpoints', + ], + 'dbMountPoints' => [ + 'fieldName' => 'db_mountpoints', + ], + 'backendUserGroups' => [ + 'fieldName' => 'usergroup', + ], + ], + ], + \TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup::class => [ + 'tableName' => 'be_groups', + 'properties' => [ + 'subGroups' => [ + 'fieldName' => 'subgroup', + ], + ], + ], + \TYPO3\CMS\Beuser\Domain\Model\FileMount::class => [ + 'tableName' => 'sys_filemounts', + ], +]; diff --git a/Configuration/JavaScriptModules.php b/Configuration/JavaScriptModules.php new file mode 100644 index 0000000..e7c595c --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,11 @@ + [ + 'backend', + 'core', + ], + 'imports' => [ + '@typo3/beuser/' => 'EXT:beuser/Resources/Public/JavaScript/', + ], +]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..2415fd4 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + TYPO3\CMS\Beuser\: + resource: '../Classes/*' diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..b27a471 --- /dev/null +++ b/README.rst @@ -0,0 +1,18 @@ +========================== +TYPO3 extension ``beuser`` +========================== + +The TYPO3 backend module `Administration > Users` is managing backend users and +groups. + +It allows you to add / delete / modify backend users and groups, configure and +compare the settings of backend users and verify their permissions. This module +also displays any backend users who are currently logged in. + +Additionally it is possible to display a list / add / delete / modify +file mounts in a separate submodule. + +:Repository: https://github.com/typo3/typo3 +:Issues: https://forge.typo3.org/ +:Read online: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Backend/AccessControl/UsersAndGroups/ +:Packagist: https://packagist.org/packages/typo3/cms-beuser diff --git a/Resources/Private/Language/Modules/permissions.xlf b/Resources/Private/Language/Modules/permissions.xlf new file mode 100644 index 0000000..f863b47 --- /dev/null +++ b/Resources/Private/Language/Modules/permissions.xlf @@ -0,0 +1,17 @@ + + + +
+ + + Permissions + + + Manage page access permissions + + + Administers which backend users and groups can access and edit pages in the site tree. For each page, an owner user and group can be assigned, and read, write, and edit permissions defined. These settings control who can view or modify content within the page hierarchy. + + + + diff --git a/Resources/Private/Language/Modules/user_management.xlf b/Resources/Private/Language/Modules/user_management.xlf new file mode 100644 index 0000000..0ac51f3 --- /dev/null +++ b/Resources/Private/Language/Modules/user_management.xlf @@ -0,0 +1,17 @@ + + + +
+ + + Users + + + Backend users management + + + Administers backend user accounts and groups, and defines access permissions on records, files, and modules. Page-level read and write permissions can be managed separately in the Permissions module. + + + + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf new file mode 100644 index 0000000..0032030 --- /dev/null +++ b/Resources/Private/Language/locallang.xlf @@ -0,0 +1,430 @@ + + + +
+ + + Username + + + Avatar + + + Real name + + + Name + + + Email + + + Admin + + + Users + + + User + + + Yes + + + No + + + Never + + + Enabled + + + Start + + + Stop + + + Last login + + + Limit to languages + + + Page Tree Entry Points + + + File mountpoints + + + Groups + + + Inheritance + + + Group + + + Languages + + + Categories + + + Permissions + + + Modules + + + Read + + + Read & Write + + + Mounts and workspaces + + + Options + + + Allowed page content types + + + General permissions + + + Table permissions + + + Inherit + + + Direct + + + Default + + + Default + + + Group title + + + + Backend User + + + Backend User Group + + + Backend users + + + Backend user details + + + Backend user groups + + + Backend user group details + + + Compare backend users + + + Compare backend user groups + + + Online users + + + + Add to compare list + + + Create new backend user + + + Create editor + + + Create admin + + + Create new backend user group + + + Clear compare list + + + Compare + + + Delete + + + Show details + + + Disable + + + Edit + + + Enable + + + Info + + + Remove from compare list + + + + Filter + + + Reset + + + + previous + + + next + + + first + + + last + + + Records + + + Page + + + Refresh + + + + Switch to user + + + Locked MFA providers + + + MFA enabled + + + + Backend users + + + Backend users to compare + + + Backend users in the system + + + Compare selected backend users + + + Group + + + Group + + + Login state + + + All + + + Logged in before + + + Never logged in + + + Currently logged in + + + Status + + + All + + + Enabled + + + Disabled + + + Type + + + All + + + Admin + + + Normal user + + + online + + + Are you sure you want to delete the backend user '%s'? + + + + Configuration of backend user "%s" + + + Not configured. + + + Compiled rights and settings + + + This view displays all compiled rights and settings of the selected backend user. These can come from settings in the backend user record itself, as well as from settings that have been stored in backend user groups assigned to this backend user. + + + + Compare backend users + + + + Online users + + + IP address + + + Last access + + + Active session + + + Session successfully terminated. + + + Really logout + + + End session + + + + Backend user groups + + + No backend user groups found + + + There are currently no backend user groups found in the database. + + + Backend user groups to compare + + + Backend user groups in the system + + + Compare selected backend user groups + + + Group title or group ID + + + Group title + + + Inherit settings from groups + + + Are you sure you want to delete the backend user group '%s'? + + + + Configuration of backend user group "%s" + + + Not configured. + + + Compiled rights and settings + + + This view displays all compiled rights and settings of the selected backend user group. These can come from settings in the backend user group record itself, as well as from settings that have been stored in backend user groups assigned to this backend user group. + + + + Compare backend user groups + + + + File mounts + + + File Mounts + + + Are you sure, that you want to delete the file mount "%s"? + + + Create new file mount + + + No file mount found + + + Please create a file mount and select its entry point. + + + Open in file list + + + File mounts + + + File mount + + + + Password reset not triggered + + + Sorry, the password of this user cannot be reset. + + + Password reset triggered + + + Password reset for email address %s initiated. + + + Reset Password + + + Reset Password + + + Are you sure you want to reset the password for %s? + + + + diff --git a/Resources/Private/Language/locallang_mod_permission.xlf b/Resources/Private/Language/locallang_mod_permission.xlf new file mode 100644 index 0000000..bb2d058 --- /dev/null +++ b/Resources/Private/Language/locallang_mod_permission.xlf @@ -0,0 +1,134 @@ + + + +
+ + + Permissions + + + Change permissions + + + Legend + + + Owner + + + Group + + + Everybody + + + Disable the »Admin-only« edit lock for this page. Currently this page and all content is locked for editing by all non-Admin users. + + + Enable the »Admin-only« edit lock for this page + + + Save + + + Abort + + + EDIT + + + Set recursively + + + page affected + + + pages affected + + + User overview + + + Mode + + + Depth + + + level + + + levels + + + User + + + Change owner + + + Change group + + + Definition: 'content' is records from all tables on a page - except from records from the table 'pages' (Pages). + + + Access Granted + + + Access Denied + + + Show page + + + Edit content + + + Edit page + + + Delete page + + + New pages + + + Show/Copy page and content. + + + Change/Add/Delete/Move content. + + + Change page eg. change pagetitle etc. + + + Delete/Move page and content. + + + Create new pages under this page. + + + Workspace Warning + + + Permissions set in a workspace take effect only after the related elements are published. To apply permissions immediately, configure them in the Live workspace. (Permissions are always evaluated based on the Live workspace record or the placeholder of a draft version) + + + not set + + + deleted + + + No user groups exist. + + + - none - + + + - leave unchanged - + + + + diff --git a/Resources/Private/Layouts/Permission.fluid.html b/Resources/Private/Layouts/Permission.fluid.html new file mode 100644 index 0000000..3f3c59c --- /dev/null +++ b/Resources/Private/Layouts/Permission.fluid.html @@ -0,0 +1,9 @@ + + + + + + diff --git a/Resources/Private/Partials/BackendUser/Filter.fluid.html b/Resources/Private/Partials/BackendUser/Filter.fluid.html new file mode 100644 index 0000000..52c46a6 --- /dev/null +++ b/Resources/Private/Partials/BackendUser/Filter.fluid.html @@ -0,0 +1,80 @@ + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + + + +
+
+
+ + diff --git a/Resources/Private/Partials/BackendUser/PaginatedList.fluid.html b/Resources/Private/Partials/BackendUser/PaginatedList.fluid.html new file mode 100644 index 0000000..e07b507 --- /dev/null +++ b/Resources/Private/Partials/BackendUser/PaginatedList.fluid.html @@ -0,0 +1,223 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
/
+ + + + + + + + + + {backendUser.realName} +
+ ({backendUser.username}) +
+ + {backendUser.username} + + +
+
+
+ + {backendUserGroup.title}, + + + + + {backendUser.lastLoginDateAndTime} + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + +
+
+ + {totalAmountOfBackendUsers} + {totalAmountOfBackendUsers} + +
+
+ + diff --git a/Resources/Private/Partials/BackendUserGroup/Filter.fluid.html b/Resources/Private/Partials/BackendUserGroup/Filter.fluid.html new file mode 100644 index 0000000..8136192 --- /dev/null +++ b/Resources/Private/Partials/BackendUserGroup/Filter.fluid.html @@ -0,0 +1,27 @@ + + + +
+
+ + +
+
+ + + + + + +
+
+
+ + diff --git a/Resources/Private/Partials/BackendUserGroup/PaginatedList.fluid.html b/Resources/Private/Partials/BackendUserGroup/PaginatedList.fluid.html new file mode 100644 index 0000000..ab1083d --- /dev/null +++ b/Resources/Private/Partials/BackendUserGroup/PaginatedList.fluid.html @@ -0,0 +1,162 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + {backendUserGroup.title} + + + + {subgroup.title}, + + +
+ + + + + + + + + + + + + + + +
+ +
+ +
+
+ + + + + + +
+
+ + + + + + + + + + + + + +
+
+ + {totalAmountOfBackendUserGroups} + {totalAmountOfBackendUserGroups} + +
+
+ + + + diff --git a/Resources/Private/Partials/Compare/Information.fluid.html b/Resources/Private/Partials/Compare/Information.fluid.html new file mode 100644 index 0000000..bd895de --- /dev/null +++ b/Resources/Private/Partials/Compare/Information.fluid.html @@ -0,0 +1,489 @@ + + + + +
+ + + + + + + + + + + + + + + +
+ {language.title} () [{languageId}] + + + {language.title} [{languageId}]
+
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + {group.row.title} [{group.row.uid}] + +
+
+
+
+ + + +
+ + + + + + + +
+ + + + {item.title} [{item.uid}] + +
+
+
+
+ + + +
+ + + + + + + +
+ + + + {item.title} [{item.uid}] + +
+
+
+
+ + + +
+ + + + + + + +
+ + {f:translate(key:item.label,default:item.label)} + {item.value} + + [{item.value}] +
+
+
+
+ + + +
+ + + + + + + +
+ + + + {item.title} [{item.uid}] + +
+
+
+
+ + + + +
+ + + + + +
+ + + {workspaces.record.title} + () [{workspaces.record.uid}] +
+
+
+
+
+ + + +
+ + + + + + + +
+ {f:translate(key:item.label,default:item.label)} [{item.value}] +
+
+
+
+ + + +
+ + + + + + + + + + + + + + + + +
{f:translate(key: module.title, default: module.title)} [{module.identifier}]
+
+
+
+ + + + + + + + + + + + +
+ +
+
+ + + + + + + + + +
+ + + {f:translate(key:label, default:label)} [{table}] +
+
+
+
+
+ + +
+ +
+
+ + + + + + + + + +
+ + + {f:translate(key:label, default:label)} [{table}] +
+
+
+
+
+
+
+ + + + +
+ +
+
+
    + +
  • {f:translate(key:label,default:label)} [{field}]
  • +
    +
+
+
+
+
+
+
+ + +
+ +
+
+ +
+
+
+
+ + +
    + +
  • + + {key} + + = + {value} + + + + + +
  • +
    +
+
+ + + +
+ + + + + + + +
+ + + + + {f:translate(key: item.label)} + [{item.shortType}] + + + {f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:notAvailableAbbreviation')} + [{item.longType}] + + +
+
+
+
+ + diff --git a/Resources/Private/Partials/Filemount/PaginatedList.fluid.html b/Resources/Private/Partials/Filemount/PaginatedList.fluid.html new file mode 100644 index 0000000..acb9913 --- /dev/null +++ b/Resources/Private/Partials/Filemount/PaginatedList.fluid.html @@ -0,0 +1,150 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + {fileMount.title} + + {fileMount.description} + + {fileMount.storage.name} + + + + {fileMount.storage.configuration.basePath}{fileMount.path} + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + {totalAmountOfFilemounts} + + + {totalAmountOfFilemounts} + + +
+
+ + + + diff --git a/Resources/Private/Partials/Permission/Groupname.fluid.html b/Resources/Private/Partials/Permission/Groupname.fluid.html new file mode 100644 index 0000000..7dd7026 --- /dev/null +++ b/Resources/Private/Partials/Permission/Groupname.fluid.html @@ -0,0 +1,42 @@ + + + + + + + diff --git a/Resources/Private/Partials/Permission/Ownername.fluid.html b/Resources/Private/Partials/Permission/Ownername.fluid.html new file mode 100644 index 0000000..6ba2cae --- /dev/null +++ b/Resources/Private/Partials/Permission/Ownername.fluid.html @@ -0,0 +1,42 @@ + + + + + + + diff --git a/Resources/Private/Partials/SimplePagination.fluid.html b/Resources/Private/Partials/SimplePagination.fluid.html new file mode 100644 index 0000000..1059267 --- /dev/null +++ b/Resources/Private/Partials/SimplePagination.fluid.html @@ -0,0 +1,99 @@ + + + + + + + diff --git a/Resources/Private/Templates/BackendUser/Compare.fluid.html b/Resources/Private/Templates/BackendUser/Compare.fluid.html new file mode 100644 index 0000000..d33f843 --- /dev/null +++ b/Resources/Private/Templates/BackendUser/Compare.fluid.html @@ -0,0 +1,290 @@ + + + + + + + + + + + + + +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + {compareData.user.username} [{compareData.user.uid}] +
+
+ + + + + + + +
+
+
+ + + + + + + + + + + [{compareData.user.admin}] +
{compareData.user.realName}
+ {compareData.user.email} +
+ +
+ + + + + + + + + + + [{compareData.user.disable}] +
+ + {compareData.user.starttime} + +
+ + {compareData.user.endtime} + +
+ + + {compareData.user.lastlogin} + + + + + +
+ {compareData.user.description -> f:format.nl2br()} +
+ +
+ +
+ +
+ + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + +
+
+ + +
+ + diff --git a/Resources/Private/Templates/BackendUser/List.fluid.html b/Resources/Private/Templates/BackendUser/List.fluid.html new file mode 100644 index 0000000..53a66d8 --- /dev/null +++ b/Resources/Private/Templates/BackendUser/List.fluid.html @@ -0,0 +1,116 @@ + + + + + +

+ + +

+
+ + + + + + + + + + + + + + + + + + + + +
/
+ + + + + + + + + + {compareUser.realName} +
+ ({compareUser.username}) +
+ + {compareUser.username} + +
+
+
+ + + + + + +
+ + {compareUserList -> f:count()} + {compareUserList -> f:count()} + +
+
+ + + + + + + + + +

+
+ + + +
+ + diff --git a/Resources/Private/Templates/BackendUser/Online.fluid.html b/Resources/Private/Templates/BackendUser/Online.fluid.html new file mode 100644 index 0000000..b24589d --- /dev/null +++ b/Resources/Private/Templates/BackendUser/Online.fluid.html @@ -0,0 +1,119 @@ + + + + + +

+
+ + + + + + + + + + + + + + 1) && !{backendUserIterator.isFirst}', then: ' class="beuser-online-table_row"')}> + + + + + + + + + + + + + + + + + + +
/
1', then: 'rowspan="{sessionAmount}" class="col-avatar align-top"', else: 'class="col-avatar"')}> + + 1', then: 'rowspan="{sessionAmount}" class="col-min align-top border-end"', else: 'class="col-min"')}> + + + + {onlineUser.backendUser.realName} +
+ ({onlineUser.backendUser.userName}) +
+ + {onlineUser.backendUser.userName} + + +
+
+
{session.ip} + + + + + + + + + + + + + + + + +
+ {onlineUsersAndSessions -> f:count()} + + {onlineUsersAndSessionsCount} + {onlineUsersAndSessionsCount} + +
+
+ +
+ + diff --git a/Resources/Private/Templates/BackendUser/Show.fluid.html b/Resources/Private/Templates/BackendUser/Show.fluid.html new file mode 100644 index 0000000..f398498 --- /dev/null +++ b/Resources/Private/Templates/BackendUser/Show.fluid.html @@ -0,0 +1,578 @@ + + + + + + + + + + + + + +

+ +

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+ {data.user.username} +
+ {data.user.realName} +
+ + + +
+ +
+ + + + + + + + +
+ + {data.user.starttime} + +
+ + {data.user.endtime} + +
+ + + {data.user.lastlogin} + + + + + +
+ {data.user.description -> f:format.nl2br()} +
+
+ +

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +

+ +
+ +
+
+ +
+
+

+
+
+
+
+ + + +

+ +
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + + + + +
+
+ +
+
+

+
+
+
+
+ +
+ + diff --git a/Resources/Private/Templates/BackendUserGroup/Compare.fluid.html b/Resources/Private/Templates/BackendUserGroup/Compare.fluid.html new file mode 100644 index 0000000..cbae3a9 --- /dev/null +++ b/Resources/Private/Templates/BackendUserGroup/Compare.fluid.html @@ -0,0 +1,217 @@ + + + + + + + + + + + + + +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + {compareData.group.title} [{compareData.group.uid}] +
+
+ + + + + + +
+
+
+ {compareData.group.description -> f:format.nl2br()} +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + +
+
+ + +
+ + diff --git a/Resources/Private/Templates/BackendUserGroup/List.fluid.html b/Resources/Private/Templates/BackendUserGroup/List.fluid.html new file mode 100644 index 0000000..85c73c2 --- /dev/null +++ b/Resources/Private/Templates/BackendUserGroup/List.fluid.html @@ -0,0 +1,114 @@ + + + + + +

+ + + +

+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + {compareGroup.title} + + + + + + + + +
+ + {compareGroupList -> f:count()} + {compareGroupList -> f:count()} + +
+
+ + + + + + + + + +

+
+
+ + +

+ + + +
+
+
+ + + + +
+ + diff --git a/Resources/Private/Templates/BackendUserGroup/Show.fluid.html b/Resources/Private/Templates/BackendUserGroup/Show.fluid.html new file mode 100644 index 0000000..1d8db13 --- /dev/null +++ b/Resources/Private/Templates/BackendUserGroup/Show.fluid.html @@ -0,0 +1,545 @@ + + + + + + + + + + + + +

+ +

+ + + +
+ + + + + + + + + + + + + +
+ {data.group.title} +
+ + + + + + + + +
+ {data.group.description -> f:format.nl2br()} +
+
+ +

+ + +
+ +
+
+ + + + + + + + + + + + + + + +
+ +
+ + + {group.row.title} [{group.row.uid}] + +
+
+
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +

+ +
+ +
+
+ +
+
+

+
+
+
+
+ + + +

+ +
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ + + +
+ +
+ +
+
+
+ +
+
+ +
+
+

+
+
+
+
+ +

+ + + + + +
+
+ +
+
+

+
+
+
+
+
+ + diff --git a/Resources/Private/Templates/Filemount/List.fluid.html b/Resources/Private/Templates/Filemount/List.fluid.html new file mode 100644 index 0000000..dd58e23 --- /dev/null +++ b/Resources/Private/Templates/Filemount/List.fluid.html @@ -0,0 +1,37 @@ + + + + + +

+ + + + + + +

+ + + + +
+
+
+ +
+ + diff --git a/Resources/Private/Templates/Permission/ChangeGroup.fluid.html b/Resources/Private/Templates/Permission/ChangeGroup.fluid.html new file mode 100644 index 0000000..3a59a28 --- /dev/null +++ b/Resources/Private/Templates/Permission/ChangeGroup.fluid.html @@ -0,0 +1,8 @@ + + + + + diff --git a/Resources/Private/Templates/Permission/ChangeGroupSelector.fluid.html b/Resources/Private/Templates/Permission/ChangeGroupSelector.fluid.html new file mode 100644 index 0000000..f8bc585 --- /dev/null +++ b/Resources/Private/Templates/Permission/ChangeGroupSelector.fluid.html @@ -0,0 +1,43 @@ + + + +
+ + + + + + + diff --git a/Resources/Private/Templates/Permission/ChangeOwner.fluid.html b/Resources/Private/Templates/Permission/ChangeOwner.fluid.html new file mode 100644 index 0000000..e532c1b --- /dev/null +++ b/Resources/Private/Templates/Permission/ChangeOwner.fluid.html @@ -0,0 +1,8 @@ + + + + + diff --git a/Resources/Private/Templates/Permission/ChangeOwnerSelector.fluid.html b/Resources/Private/Templates/Permission/ChangeOwnerSelector.fluid.html new file mode 100644 index 0000000..041d410 --- /dev/null +++ b/Resources/Private/Templates/Permission/ChangeOwnerSelector.fluid.html @@ -0,0 +1,41 @@ + + + +
+ + + +
+
+ + diff --git a/Resources/Private/Templates/Permission/ChangePermission.fluid.html b/Resources/Private/Templates/Permission/ChangePermission.fluid.html new file mode 100644 index 0000000..c076549 --- /dev/null +++ b/Resources/Private/Templates/Permission/ChangePermission.fluid.html @@ -0,0 +1,8 @@ + + + + + diff --git a/Resources/Private/Templates/Permission/Edit.fluid.html b/Resources/Private/Templates/Permission/Edit.fluid.html new file mode 100644 index 0000000..94187c5 --- /dev/null +++ b/Resources/Private/Templates/Permission/Edit.fluid.html @@ -0,0 +1,175 @@ + + + + + + + +

+ : + +

+ + + + +
+ +
+
+ + +
+
+ + + + + + +
+
+
+
+
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ + + + + + +
+ +

+

+ :
+ :
+ :
+ :
+ : +

+

+ +
+ + diff --git a/Resources/Private/Templates/Permission/Index.fluid.html b/Resources/Private/Templates/Permission/Index.fluid.html new file mode 100644 index 0000000..b5c360c --- /dev/null +++ b/Resources/Private/Templates/Permission/Index.fluid.html @@ -0,0 +1,196 @@ + + + + + + + +

+ +
+ + + + + + + + + + + + + + + + + + + + A "normal" page row is rendered, not the root page + + + + + + + + + + + + + + + + + Root page row is rendered + + + + + + + +
+
+ + {data.depthData -> f:format.raw()}{data.HTML -> f:format.raw()} + {data.icon -> f:format.raw()} + + {data.row.title} +
+
+ + + + + + + + + + + + + + + + + + + + + Edit link is workspace aware: If in ws, link to edit the ws overlay record is rendered + + + + + + + {data.HTML} + {data.icon -> f:format.raw()} + {data.row.title -> f:format.crop(maxCharacters:20)} +
+
+ +

:

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1:
2:
3:
4:
5:
+
+

+

+
+ +

+ +
+ + diff --git a/Resources/Private/Templates/Permission/ToggleEditLock.fluid.html b/Resources/Private/Templates/Permission/ToggleEditLock.fluid.html new file mode 100644 index 0000000..f1aa8d4 --- /dev/null +++ b/Resources/Private/Templates/Permission/ToggleEditLock.fluid.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/Resources/Public/Icons/Extension.png b/Resources/Public/Icons/Extension.png new file mode 100644 index 0000000..bcd5042 Binary files /dev/null and b/Resources/Public/Icons/Extension.png differ diff --git a/Resources/Public/JavaScript/backend-user-listing.js b/Resources/Public/JavaScript/backend-user-listing.js new file mode 100644 index 0000000..d2beb61 --- /dev/null +++ b/Resources/Public/JavaScript/backend-user-listing.js @@ -0,0 +1,13 @@ +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +import e from"@typo3/core/event/regular-event.js";import s from"@typo3/core/document-service.js";class i{constructor(){this.searchField=document.querySelector("#tx_Beuser_username"),this.activeSearch=this.searchField?this.searchField.value!=="":!1,s.ready().then(()=>{this.searchField&&new e("search",()=>{this.searchField.value===""&&this.activeSearch&&this.searchField.closest("form").submit()}).bindTo(this.searchField)})}}var r=new i;export{r as default}; diff --git a/Resources/Public/JavaScript/permissions.js b/Resources/Public/JavaScript/permissions.js new file mode 100644 index 0000000..6cedbd3 --- /dev/null +++ b/Resources/Public/JavaScript/permissions.js @@ -0,0 +1,13 @@ +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +import r from"@typo3/core/event/regular-event.js";import c from"@typo3/core/ajax/ajax-request.js";class i{constructor(){this.options={containerSelector:"#typo3-permissionList",editControllerSelector:"#PermissionControllerEdit"},this.ajaxUrl=TYPO3.settings.ajaxUrls.user_access_permissions,this.initializeCheckboxGroups(),this.initializeEvents()}static setPermissionCheckboxes(e,o){const t=document.querySelectorAll(`input[type="checkbox"][name^="${e}"]`);for(const a of t){const s=parseInt(a.value,10);a.checked=(o&s)===s}}static updatePermissionValue(e,o){let t=0;const a=document.querySelectorAll(`input[type="checkbox"][name^="${e}"]:checked`);for(const s of a)t|=parseInt(s.value,10);document.forms.namedItem("editform")[o].value=t|(e==="check[perms_user]"?1:0)}setPermissions(e){const o=e.dataset.page,t=e.dataset.who,a=e.dataset.bits;new c(this.ajaxUrl).post({page:o,who:t,permissions:e.dataset.permissions,mode:e.dataset.mode,bits:e.dataset.bits}).then(async s=>{const n=await s.resolve(),p=e.parentElement;p.innerHTML=n,p.querySelector('button[data-bits="'+a+'"]').focus()})}toggleEditLock(e){const o=e.dataset.page;new c(this.ajaxUrl).post({action:"toggle_edit_lock",page:o,editLockState:e.dataset.lockstate}).then(async t=>{const a=await t.resolve(),s=e.parentElement;e.outerHTML=a,s.querySelector('button[data-page="'+o+'"]').focus()})}changeOwner(e){const o=e.dataset.page,t=document.getElementById("o_"+o);new c(this.ajaxUrl).post({action:"change_owner",page:o,ownerUid:e.dataset.owner,newOwnerUid:t.getElementsByTagName("select")[0].value}).then(async a=>{t.outerHTML=await a.resolve()})}showChangeOwnerSelector(e){const o=e.dataset.page;new c(this.ajaxUrl).post({action:"show_change_owner_selector",page:o,ownerUid:e.dataset.owner,username:e.dataset.username}).then(async t=>{document.getElementById("o_"+o).outerHTML=await t.resolve()})}restoreOwner(e){const o=e.dataset.page,t=e.dataset.username??e.dataset.ifNotSet,a=document.createElement("span");a.setAttribute("id",`o_${o}`);const s=document.createElement("button");s.classList.add("ug_selector","changeowner","btn","btn-sm","btn-link"),s.setAttribute("type","button"),s.setAttribute("data-page",o),s.setAttribute("data-owner",e.dataset.owner),s.setAttribute("data-username",t),s.innerText=t,a.appendChild(s);const n=document.getElementById("o_"+o);n.parentNode.replaceChild(a,n)}restoreGroup(e){const o=e.dataset.page,t=e.dataset.groupname??e.dataset.ifNotSet,a=document.createElement("span");a.setAttribute("id",`g_${o}`);const s=document.createElement("button");s.classList.add("ug_selector","changegroup","btn","btn-sm","btn-link"),s.setAttribute("type","button"),s.setAttribute("data-page",o),s.setAttribute("data-group-id",e.dataset.groupId),s.setAttribute("data-groupname",t),s.innerText=t,a.appendChild(s);const n=document.getElementById("g_"+o);n.parentNode.replaceChild(a,n)}changeGroup(e){const o=e.dataset.page,t=document.getElementById("g_"+o);new c(this.ajaxUrl).post({action:"change_group",page:o,groupUid:e.dataset.groupId,newGroupUid:t.getElementsByTagName("select")[0].value}).then(async a=>{t.outerHTML=await a.resolve()})}showChangeGroupSelector(e){const o=e.dataset.page;new c(this.ajaxUrl).post({action:"show_change_group_selector",page:o,groupUid:e.dataset.groupId,groupname:e.dataset.groupname}).then(async t=>{document.getElementById("g_"+o).outerHTML=await t.resolve()})}initializeCheckboxGroups(){document.querySelectorAll("[data-checkbox-group]").forEach(o=>{const t=o.dataset.checkboxGroup,a=parseInt(o.value,10);i.setPermissionCheckboxes(t,a)})}initializeEvents(){const e=document.querySelector(this.options.containerSelector),o=document.querySelector(this.options.editControllerSelector);e!==null&&(new r("click",(t,a)=>{t.preventDefault(),this.setPermissions(a)}).delegateTo(e,".change-permission"),new r("click",(t,a)=>{t.preventDefault(),this.toggleEditLock(a)}).delegateTo(e,".editlock"),new r("click",(t,a)=>{t.preventDefault(),this.showChangeOwnerSelector(a)}).delegateTo(e,".changeowner"),new r("click",(t,a)=>{t.preventDefault(),this.showChangeGroupSelector(a)}).delegateTo(e,".changegroup"),new r("click",(t,a)=>{t.preventDefault(),this.restoreOwner(a)}).delegateTo(e,".restoreowner"),new r("click",(t,a)=>{t.preventDefault(),this.changeOwner(a)}).delegateTo(e,".saveowner"),new r("click",(t,a)=>{t.preventDefault(),this.restoreGroup(a)}).delegateTo(e,".restoregroup"),new r("click",(t,a)=>{t.preventDefault(),this.changeGroup(a)}).delegateTo(e,".savegroup")),o!==null&&new r("click",(t,a)=>{const s=a.dataset.checkChangePermissions.split(",").map(n=>n.trim());i.updatePermissionValue.apply(this,s)}).delegateTo(o,"[data-check-change-permissions]")}}var l=new i;export{l as default}; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..eca87c4 --- /dev/null +++ b/composer.json @@ -0,0 +1,56 @@ +{ + "name": "typo3/cms-beuser", + "type": "typo3-cms-framework", + "description": "TYPO3 CMS Backend User - TYPO3 backend module Administration > Users for managing backend users and groups.", + "homepage": "https://typo3.community/", + "funding": [ + { + "type": "membership", + "url": "https://typo3.org/membership" + } + ], + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "TYPO3 Core Team", + "email": "typo3cms@typo3.org", + "role": "Developer" + } + ], + "support": { + "issues": "https://forge.typo3.org/issues/", + "forum": "https://talk.typo3.org/", + "source": "https://github.com/TYPO3/typo3/", + "docs": "https://docs.typo3.org/", + "rss": "https://news.typo3.com/rss/", + "chat": "https://typo3.community/meet/slack/", + "security": "https://typo3.org/security/" + }, + "config": { + "sort-packages": true + }, + "require": { + "typo3/cms-core": "15.0.*@dev" + }, + "conflict": { + "typo3/cms": "*" + }, + "extra": { + "branch-alias": { + "dev-main": "15.0.x-dev" + }, + "typo3/cms": { + "Package": { + "partOfFactoryDefault": true + }, + "extension-key": "beuser" + } + }, + "autoload": { + "psr-4": { + "TYPO3\\CMS\\Beuser\\": "Classes/" + } + } +}