Commit 82376cb5 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[TASK] Use ModuleData API in BackendUserController

The ModuleData API, introduced in #96895,
is now used in the BackendUserController.

EXT:beuser previously used an own "ModuleData"
model, which is now unused and therefore removed.

Resolves: #96955
Related: #96895
Releases: main
Change-Id: Ia8b48eb8e417c214beded4d12907ef88395e1a0a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73590


Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 5adcd1a9
...@@ -19,13 +19,13 @@ namespace TYPO3\CMS\Beuser\Controller; ...@@ -19,13 +19,13 @@ namespace TYPO3\CMS\Beuser\Controller;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Authentication\PasswordReset; use TYPO3\CMS\Backend\Authentication\PasswordReset;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder; use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser; use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
use TYPO3\CMS\Beuser\Domain\Model\Demand; use TYPO3\CMS\Beuser\Domain\Model\Demand;
use TYPO3\CMS\Beuser\Domain\Model\ModuleData;
use TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository; use TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository;
use TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository; use TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository;
use TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository; use TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository;
...@@ -73,19 +73,22 @@ class BackendUserController extends ActionController ...@@ -73,19 +73,22 @@ class BackendUserController extends ActionController
*/ */
public function processRequest(RequestInterface $request): ResponseInterface public function processRequest(RequestInterface $request): ResponseInterface
{ {
/** @var Request $request */
$arguments = $request->getArguments(); $arguments = $request->getArguments();
$backendUser = $this->getBackendUser(); $moduleData = $request->getAttribute('moduleData');
if (is_array($arguments) && isset($arguments['action']) && in_array((string)$arguments['action'], ['index', 'groups', 'online']) if (
&& (string)($backendUser->uc['beuser']['defaultAction'] ?? '') !== (string)$arguments['action'] isset($arguments['action'])
&& in_array((string)$arguments['action'], ['index', 'groups', 'online'])
&& (string)$moduleData->get('defaultAction') !== (string)$arguments['action']
) { ) {
$backendUser->uc['beuser']['defaultAction'] = (string)$arguments['action']; $moduleData->set('defaultAction', (string)$arguments['action']);
$backendUser->writeUC(); $this->getBackendUser()->pushModuleData($moduleData->getModuleIdentifier(), $moduleData->toArray());
} elseif (!isset($arguments['action']) && isset($backendUser->uc['beuser']['defaultAction']) } elseif (
&& in_array((string)$backendUser->uc['beuser']['defaultAction'], ['index', 'groups', 'online']) !isset($arguments['action'])
&& $moduleData->has('defaultAction')
&& in_array((string)$moduleData->get('defaultAction'), ['index', 'groups', 'online'])
) { ) {
if ($request instanceof Request) { $request->setControllerActionName((string)$moduleData->get('defaultAction'));
$request->setControllerActionName((string)$backendUser->uc['beuser']['defaultAction']);
}
} }
return parent::processRequest($request); return parent::processRequest($request);
} }
...@@ -98,7 +101,7 @@ class BackendUserController extends ActionController ...@@ -98,7 +101,7 @@ class BackendUserController extends ActionController
*/ */
public function initializeAction(): void public function initializeAction(): void
{ {
$this->moduleData = ModuleData::fromUc((array)($this->getBackendUser()->getModuleData('tx_beuser'))); $this->moduleData = $this->request->getAttribute('moduleData');
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request, 'typo3/cms-beuser'); $this->moduleTemplate = $this->moduleTemplateFactory->create($this->request, 'typo3/cms-beuser');
$this->moduleTemplate->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab')); $this->moduleTemplate->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'));
} }
...@@ -132,17 +135,18 @@ class BackendUserController extends ActionController ...@@ -132,17 +135,18 @@ class BackendUserController extends ActionController
if ($operation === 'reset-filters') { if ($operation === 'reset-filters') {
// Reset the module data demand object // Reset the module data demand object
$this->moduleData->setDemand(new Demand()); $this->moduleData->set('demand', []);
$demand = null; $demand = null;
} }
if ($demand === null) { if ($demand === null) {
$demand = $this->moduleData->getDemand(); $demand = Demand::fromUc((array)$this->moduleData->get('demand', []));
} else { } else {
$this->moduleData->setDemand($demand); $this->moduleData->set('demand', $demand->forUc());
} }
$backendUser->pushModuleData('tx_beuser', $this->moduleData->forUc()); $backendUser->pushModuleData($this->moduleData->getModuleIdentifier(), $this->moduleData->toArray());
$compareUserList = array_keys((array)$this->moduleData->get('compareUserList', []));
$compareUserList = $this->moduleData->getCompareUserList();
$backendUsers = $this->backendUserRepository->findDemanded($demand); $backendUsers = $this->backendUserRepository->findDemanded($demand);
$paginator = new QueryResultPaginator($backendUsers, $currentPage, 50); $paginator = new QueryResultPaginator($backendUsers, $currentPage, 50);
$pagination = new SimplePagination($paginator); $pagination = new SimplePagination($paginator);
...@@ -254,7 +258,7 @@ class BackendUserController extends ActionController ...@@ -254,7 +258,7 @@ class BackendUserController extends ActionController
*/ */
public function compareAction(): ResponseInterface public function compareAction(): ResponseInterface
{ {
$compareUserList = $this->moduleData->getCompareUserList(); $compareUserList = array_keys((array)$this->moduleData->get('compareUserList', []));
if (empty($compareUserList)) { if (empty($compareUserList)) {
return $this->redirect('index'); return $this->redirect('index');
} }
...@@ -321,26 +325,19 @@ class BackendUserController extends ActionController ...@@ -321,26 +325,19 @@ class BackendUserController extends ActionController
/** /**
* Attaches one backend user to the compare list * Attaches one backend user to the compare list
*
* @param int $uid
*/ */
public function addToCompareListAction($uid): ResponseInterface public function addToCompareListAction(int $uid): ResponseInterface
{ {
$this->moduleData->attachUidCompareUser($uid); $this->addToCompareList('compareUserList', $uid);
$this->getBackendUser()->pushModuleData('tx_beuser', $this->moduleData->forUc());
return new ForwardResponse('index'); return new ForwardResponse('index');
} }
/** /**
* Removes given backend user to the compare list * Removes given backend user to the compare list
*
* @param int $uid
* @param int $redirectToCompare
*/ */
public function removeFromCompareListAction($uid, int $redirectToCompare = 0): ResponseInterface public function removeFromCompareListAction(int $uid, int $redirectToCompare = 0): ResponseInterface
{ {
$this->moduleData->detachUidCompareUser($uid); $this->removeFromCompareList('compareUserList', $uid);
$this->getBackendUser()->pushModuleData('tx_beuser', $this->moduleData->forUc());
if ($redirectToCompare) { if ($redirectToCompare) {
return $this->redirect('compare'); return $this->redirect('compare');
} }
...@@ -352,8 +349,7 @@ class BackendUserController extends ActionController ...@@ -352,8 +349,7 @@ class BackendUserController extends ActionController
*/ */
public function removeAllFromCompareListAction(): ResponseInterface public function removeAllFromCompareListAction(): ResponseInterface
{ {
$this->moduleData->resetCompareUserList(); $this->cleanCompareList('compareUserList');
$this->getBackendUser()->pushModuleData('tx_beuser', $this->moduleData->forUc());
return $this->redirect('index'); return $this->redirect('index');
} }
...@@ -385,7 +381,7 @@ class BackendUserController extends ActionController ...@@ -385,7 +381,7 @@ class BackendUserController extends ActionController
$backendUsers = $this->backendUserGroupRepository->findAll(); $backendUsers = $this->backendUserGroupRepository->findAll();
$paginator = new QueryResultPaginator($backendUsers, $currentPage, 50); $paginator = new QueryResultPaginator($backendUsers, $currentPage, 50);
$pagination = new SimplePagination($paginator); $pagination = new SimplePagination($paginator);
$compareGroupUidList = array_keys($this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? []); $compareGroupUidList = array_keys((array)$this->moduleData->get('compareGroupUidList', []));
$this->moduleTemplate->assignMultiple( $this->moduleTemplate->assignMultiple(
[ [
'paginator' => $paginator, 'paginator' => $paginator,
...@@ -419,7 +415,7 @@ class BackendUserController extends ActionController ...@@ -419,7 +415,7 @@ class BackendUserController extends ActionController
public function compareGroupsAction(): ResponseInterface public function compareGroupsAction(): ResponseInterface
{ {
$compareGroupUidList = array_keys($this->getBackendUser()->uc['beuser']['compareGroupUidList'] ?? []); $compareGroupUidList = array_keys((array)$this->moduleData->get('compareGroupUidList', []));
$compareData = []; $compareData = [];
foreach ($compareGroupUidList as $uid) { foreach ($compareGroupUidList as $uid) {
...@@ -451,33 +447,19 @@ class BackendUserController extends ActionController ...@@ -451,33 +447,19 @@ class BackendUserController extends ActionController
/** /**
* Attaches one backend user group to the compare list * Attaches one backend user group to the compare list
*
* @param int $uid
*/ */
public function addGroupToCompareListAction(int $uid): ResponseInterface public function addGroupToCompareListAction(int $uid): ResponseInterface
{ {
$backendUser = $this->getBackendUser(); $this->addToCompareList('compareGroupUidList', $uid);
$list = $backendUser->uc['beuser']['compareGroupUidList'] ?? [];
$list[$uid] = true;
$backendUser->uc['beuser']['compareGroupUidList'] = $list;
$backendUser->writeUC();
return $this->redirect('groups'); return $this->redirect('groups');
} }
/** /**
* Removes given backend user group to the compare list * Removes given backend user group to the compare list
*
* @param int $uid
* @param int $redirectToCompare
*/ */
public function removeGroupFromCompareListAction(int $uid, int $redirectToCompare = 0): ResponseInterface public function removeGroupFromCompareListAction(int $uid, int $redirectToCompare = 0): ResponseInterface
{ {
$backendUser = $this->getBackendUser(); $this->removeFromCompareList('compareGroupUidList', $uid);
$list = $backendUser->uc['beuser']['compareGroupUidList'] ?? [];
unset($list[$uid]);
$backendUser->uc['beuser']['compareGroupUidList'] = $list;
$backendUser->writeUC();
if ($redirectToCompare) { if ($redirectToCompare) {
return $this->redirect('compareGroups'); return $this->redirect('compareGroups');
} }
...@@ -489,9 +471,7 @@ class BackendUserController extends ActionController ...@@ -489,9 +471,7 @@ class BackendUserController extends ActionController
*/ */
public function removeAllGroupsFromCompareListAction(): ResponseInterface public function removeAllGroupsFromCompareListAction(): ResponseInterface
{ {
$backendUser = $this->getBackendUser(); $this->cleanCompareList('compareGroupUidList');
$backendUser->uc['beuser']['compareGroupUidList'] = [];
$backendUser->writeUC();
return $this->redirect('groups'); return $this->redirect('groups');
} }
...@@ -568,6 +548,37 @@ class BackendUserController extends ActionController ...@@ -568,6 +548,37 @@ class BackendUserController extends ActionController
$this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); $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 protected function getBackendUser(): BackendUserAuthentication
{ {
return $GLOBALS['BE_USER']; return $GLOBALS['BE_USER'];
......
<?php
declare(strict_types=1);
/*
* 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!
*/
namespace TYPO3\CMS\Beuser\Domain\Model;
/**
* Module data object
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class ModuleData
{
protected Demand $demand;
protected array $compareUserList = [];
public function __construct()
{
$this->demand = new Demand();
}
public static function fromUc(array $uc): self
{
$moduleData = new self();
$moduleData->compareUserList = (array)($uc['compareUserList'] ?? []);
$moduleData->demand = Demand::fromUc($uc['demand'] ?? []);
return $moduleData;
}
public function forUc(): array
{
return [
'compareUserList' => $this->compareUserList,
'demand' => $this->demand->forUc(),
];
}
public function getDemand(): Demand
{
return $this->demand;
}
public function setDemand(Demand $demand): void
{
$this->demand = $demand;
}
protected function setCompareUserList(array $compareUserList): void
{
$this->compareUserList = $compareUserList;
}
/**
* Returns the compare list as array of user uids
*/
public function getCompareUserList(): array
{
return array_keys($this->compareUserList);
}
public function resetCompareUserList(): void
{
$this->compareUserList = [];
}
/**
* Adds one backend user (by uid) to the compare user list
* Cannot be ObjectStorage, must be array
*
* @param int $uid
*/
public function attachUidCompareUser(int $uid): void
{
$this->compareUserList[$uid] = true;
}
/**
* Strip one backend user from the compare user list
*
* @param int $uid
*/
public function detachUidCompareUser(int $uid): void
{
unset($this->compareUserList[$uid]);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment