first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
namespace TYPO3\CMS\Beuser\ContextMenu;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\PageProvider;
|
||||
|
||||
/**
|
||||
* @internal This class is a TYPO3 core-internal hook implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class ItemProvider extends PageProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $itemsConfiguration = [
|
||||
'permissions' => [
|
||||
'type' => 'item',
|
||||
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:CM_perms',
|
||||
'iconIdentifier' => 'actions-lock',
|
||||
'callbackAction' => 'openPermissionsModule'
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $itemName
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
protected function canRender(string $itemName, string $type): bool
|
||||
{
|
||||
if (in_array($itemName, $this->disabledItems, true)) {
|
||||
return false;
|
||||
}
|
||||
return $this->canShowPermissionsModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items
|
||||
* @return array
|
||||
*/
|
||||
public function addItems(array $items): array
|
||||
{
|
||||
$this->initDisabledItems();
|
||||
$localItems = $this->prepareItems($this->itemsConfiguration);
|
||||
if (isset($items['more']['childItems'])) {
|
||||
$items['more']['childItems'] = $items['more']['childItems'] + $localItems;
|
||||
} else {
|
||||
$items += $localItems;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* This priority should be lower than priority of the PageProvider, so it's evaluated after the PageProvider
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPriority(): int
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemName
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdditionalAttributes(string $itemName): array
|
||||
{
|
||||
return ['data-callback-module' => 'TYPO3/CMS/Beuser/ContextMenuActions'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the page is allowed to show permission module
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canShowPermissionsModule(): bool
|
||||
{
|
||||
return $this->canBeEdited() && $this->backendUser->check('modules', 'system_BeuserTxPermission');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Controller;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
|
||||
use TYPO3\CMS\Core\Session\Backend\HashableSessionBackendInterface;
|
||||
use TYPO3\CMS\Core\Session\Backend\SessionBackendInterface;
|
||||
use TYPO3\CMS\Core\Session\SessionManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
/**
|
||||
* Backend module user administration controller
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserController extends ActionController
|
||||
{
|
||||
use PublicMethodDeprecationTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $deprecatedPublicMethods = [
|
||||
'initializeView' => 'Using BackendUserController::initializeView() is deprecated and will not be possible anymore in TYPO3 v10.0.',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const RECENT_USERS_LIMIT = 3;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Model\ModuleData
|
||||
*/
|
||||
protected $moduleData;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Service\ModuleDataStorageService
|
||||
*/
|
||||
protected $moduleDataStorageService;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository
|
||||
*/
|
||||
protected $backendUserRepository;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
|
||||
*/
|
||||
protected $backendUserGroupRepository;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
|
||||
*/
|
||||
protected $backendUserSessionRepository;
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Service\ModuleDataStorageService $moduleDataStorageService
|
||||
*/
|
||||
public function injectModuleDataStorageService(\TYPO3\CMS\Beuser\Service\ModuleDataStorageService $moduleDataStorageService)
|
||||
{
|
||||
$this->moduleDataStorageService = $moduleDataStorageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository $backendUserRepository
|
||||
*/
|
||||
public function injectBackendUserRepository(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository $backendUserRepository)
|
||||
{
|
||||
$this->backendUserRepository = $backendUserRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository
|
||||
*/
|
||||
public function injectBackendUserGroupRepository(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository)
|
||||
{
|
||||
$this->backendUserGroupRepository = $backendUserGroupRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository $backendUserSessionRepository
|
||||
*/
|
||||
public function injectBackendUserSessionRepository(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository $backendUserSessionRepository)
|
||||
{
|
||||
$this->backendUserSessionRepository = $backendUserSessionRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and persist module data
|
||||
*
|
||||
* @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request
|
||||
* @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response
|
||||
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
|
||||
*/
|
||||
public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
|
||||
{
|
||||
$this->moduleData = $this->moduleDataStorageService->loadModuleData();
|
||||
// We "finally" persist the module data.
|
||||
try {
|
||||
parent::processRequest($request, $response);
|
||||
$this->moduleDataStorageService->persistModuleData($this->moduleData);
|
||||
} catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
|
||||
$this->moduleDataStorageService->persistModuleData($this->moduleData);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign default variables to view
|
||||
* @param ViewInterface $view
|
||||
*/
|
||||
protected function initializeView(ViewInterface $view)
|
||||
{
|
||||
$view->assignMultiple([
|
||||
'shortcutLabel' => 'backendUsers',
|
||||
'dateFormat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],
|
||||
'timeFormat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all BackendUsers
|
||||
* - Switch session to different user
|
||||
*
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
|
||||
*/
|
||||
public function indexAction(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand = null)
|
||||
{
|
||||
if ($demand === null) {
|
||||
$demand = $this->moduleData->getDemand();
|
||||
} else {
|
||||
$this->moduleData->setDemand($demand);
|
||||
}
|
||||
// Switch user until logout
|
||||
$switchUser = (int)GeneralUtility::_GP('SwitchUser');
|
||||
if ($switchUser > 0) {
|
||||
$this->switchUser($switchUser);
|
||||
}
|
||||
$compareUserList = $this->moduleData->getCompareUserList();
|
||||
|
||||
// Create online user list for easy parsing
|
||||
$onlineUsers = $this->backendUserSessionRepository->findAllActive();
|
||||
$onlineBackendUsers = [];
|
||||
if (is_array($onlineUsers)) {
|
||||
foreach ($onlineUsers as $onlineUser) {
|
||||
$onlineBackendUsers[$onlineUser['ses_userid']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->assignMultiple([
|
||||
'onlineBackendUsers' => $onlineBackendUsers,
|
||||
'demand' => $demand,
|
||||
'backendUsers' => $this->backendUserRepository->findDemanded($demand),
|
||||
'backendUserGroups' => array_merge([''], $this->backendUserGroupRepository->findAll()->toArray()),
|
||||
'compareUserUidList' => array_combine($compareUserList, $compareUserList),
|
||||
'currentUserUid' => $this->getBackendUserAuthentication()->user['uid'],
|
||||
'compareUserList' => !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Views all currently logged in BackendUsers and their sessions
|
||||
*/
|
||||
public function onlineAction()
|
||||
{
|
||||
$onlineUsersAndSessions = [];
|
||||
$onlineUsers = $this->backendUserRepository->findOnline();
|
||||
foreach ($onlineUsers as $onlineUser) {
|
||||
$onlineUsersAndSessions[] = [
|
||||
'backendUser' => $onlineUser,
|
||||
'sessions' => $this->backendUserSessionRepository->findByBackendUser($onlineUser)
|
||||
];
|
||||
}
|
||||
|
||||
$currentSessionId = $this->getBackendUserAuthentication()->getSessionId();
|
||||
$sessionBackend = $this->getSessionBackend();
|
||||
if ($sessionBackend instanceof HashableSessionBackendInterface) {
|
||||
$currentSessionId = $sessionBackend->hash($currentSessionId);
|
||||
}
|
||||
$this->view->assignMultiple([
|
||||
'shortcutLabel' => 'onlineUsers',
|
||||
'onlineUsersAndSessions' => $onlineUsersAndSessions,
|
||||
'currentSessionId' => $currentSessionId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare backend users from demand
|
||||
*/
|
||||
public function compareAction()
|
||||
{
|
||||
$compareUserList = $this->moduleData->getCompareUserList();
|
||||
if (empty($compareUserList)) {
|
||||
$this->redirect('index');
|
||||
}
|
||||
|
||||
$this->view->assignMultiple([
|
||||
'shortcutLabel' => 'compareUsers',
|
||||
'compareUserList' => $this->backendUserRepository->findByUidList($compareUserList),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches one backend user to the compare list
|
||||
*
|
||||
* @param int $uid
|
||||
*/
|
||||
public function addToCompareListAction($uid)
|
||||
{
|
||||
$this->moduleData->attachUidCompareUser($uid);
|
||||
$this->moduleDataStorageService->persistModuleData($this->moduleData);
|
||||
$this->forward('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes given backend user to the compare list
|
||||
*
|
||||
* @param int $uid
|
||||
*/
|
||||
public function removeFromCompareListAction($uid)
|
||||
{
|
||||
$this->moduleData->detachUidCompareUser($uid);
|
||||
$this->moduleDataStorageService->persistModuleData($this->moduleData);
|
||||
$this->forward('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate BackendUser session and logout corresponding client
|
||||
* Redirects to onlineAction with message
|
||||
*
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser
|
||||
* @param string $sessionId
|
||||
*/
|
||||
protected function terminateBackendUserSessionAction(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser, $sessionId)
|
||||
{
|
||||
// terminating value of persisted session ID (probably hashed value)
|
||||
$sessionBackend = $this->getSessionBackend();
|
||||
$success = $sessionBackend->remove($sessionId);
|
||||
|
||||
if ($success) {
|
||||
$this->addFlashMessage(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:terminateSessionSuccess', 'beuser'));
|
||||
}
|
||||
$this->forward('online');
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to a given user (SU-mode) and then redirects to the start page of the backend to refresh the navigation etc.
|
||||
*
|
||||
* @param string $switchUser BE-user record that will be switched to
|
||||
*/
|
||||
protected function switchUser($switchUser)
|
||||
{
|
||||
$targetUser = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $switchUser);
|
||||
if (is_array($targetUser) && $this->getBackendUserAuthentication()->isAdmin()) {
|
||||
// Set backend user listing module as starting module for switchback
|
||||
$this->getBackendUserAuthentication()->uc['startModuleOnFirstLogin'] = 'system_BeuserTxBeuser';
|
||||
$this->getBackendUserAuthentication()->uc['recentSwitchedToUsers'] = $this->generateListOfMostRecentSwitchedUsers($targetUser['uid']);
|
||||
$this->getBackendUserAuthentication()->writeUC();
|
||||
|
||||
$this->getSessionBackend()->update(
|
||||
$this->getBackendUserAuthentication()->getSessionId(),
|
||||
[
|
||||
'ses_userid' => (int)$targetUser['uid'],
|
||||
'ses_backuserid' => (int)$this->getBackendUserAuthentication()->user['uid']
|
||||
]
|
||||
);
|
||||
|
||||
$this->emitSwitchUserSignal($targetUser);
|
||||
|
||||
$redirectUrl = 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
|
||||
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of users to whom where switched in the past. This is limited by RECENT_USERS_LIMIT.
|
||||
*
|
||||
* @param int $targetUserUid
|
||||
* @return int[]
|
||||
*/
|
||||
protected function generateListOfMostRecentSwitchedUsers(int $targetUserUid): array
|
||||
{
|
||||
$latestUserUids = [];
|
||||
$backendUser = $this->getBackendUserAuthentication();
|
||||
|
||||
if (isset($backendUser->uc['recentSwitchedToUsers']) && is_array($backendUser->uc['recentSwitchedToUsers'])) {
|
||||
$latestUserUids = $backendUser->uc['recentSwitchedToUsers'];
|
||||
}
|
||||
|
||||
// Remove potentially existing user in that list
|
||||
$index = array_search($targetUserUid, $latestUserUids, true);
|
||||
if ($index !== false) {
|
||||
unset($latestUserUids[$index]);
|
||||
}
|
||||
|
||||
array_unshift($latestUserUids, $targetUserUid);
|
||||
$latestUserUids = array_slice($latestUserUids, 0, static::RECENT_USERS_LIMIT);
|
||||
|
||||
return $latestUserUids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a signal when using the "switch to user" functionality
|
||||
*
|
||||
* @param array $targetUser
|
||||
*/
|
||||
protected function emitSwitchUserSignal(array $targetUser)
|
||||
{
|
||||
$this->signalSlotDispatcher->dispatch(__CLASS__, 'switchUser', [$targetUser]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUserAuthentication(): BackendUserAuthentication
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SessionBackendInterface
|
||||
*/
|
||||
protected function getSessionBackend()
|
||||
{
|
||||
$loginType = $this->getBackendUserAuthentication()->getLoginType();
|
||||
return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend($loginType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Controller;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
|
||||
/**
|
||||
* Backend module user group administration controller
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserGroupController extends ActionController
|
||||
{
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
|
||||
*/
|
||||
protected $backendUserGroupRepository;
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository
|
||||
*/
|
||||
public function injectBackendUserGroupRepository(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository $backendUserGroupRepository)
|
||||
{
|
||||
$this->backendUserGroupRepository = $backendUserGroupRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all BackendUserGroups
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->assignMultiple(
|
||||
[
|
||||
'shortcutLabel' => 'backendUserGroupsMenu',
|
||||
'backendUserGroups' => $this->backendUserGroupRepository->findAll(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Controller;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
||||
use TYPO3\CMS\Core\Http\HtmlResponse;
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\View\StandaloneView;
|
||||
|
||||
/**
|
||||
* This class extends the permissions module in the TYPO3 Backend to provide
|
||||
* convenient methods of editing of page permissions (including page ownership
|
||||
* (user and group)) via new AjaxRequestHandler facility
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class PermissionAjaxController
|
||||
{
|
||||
/**
|
||||
* The local configuration array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $conf;
|
||||
|
||||
/**
|
||||
* @var IconFactory
|
||||
*/
|
||||
protected $iconFactory;
|
||||
|
||||
/**
|
||||
* The constructor of this class
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
$this->getLanguageService()->includeLLFile('EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf');
|
||||
}
|
||||
|
||||
/**
|
||||
* The main dispatcher function. Collect data and prepare HTML output.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function dispatch(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$parsedBody = $request->getParsedBody();
|
||||
$this->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),
|
||||
];
|
||||
|
||||
$extPath = ExtensionManagementUtility::extPath('beuser');
|
||||
|
||||
$view = GeneralUtility::makeInstance(StandaloneView::class);
|
||||
$view->setPartialRootPaths(['default' => ExtensionManagementUtility::extPath('beuser') . 'Resources/Private/Partials']);
|
||||
$view->assign('pageId', $this->conf['page']);
|
||||
|
||||
$response = new HtmlResponse('');
|
||||
|
||||
// Basic test for required value
|
||||
if ($this->conf['page'] <= 0) {
|
||||
$response->getBody()->write('This script cannot be called directly');
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
$content = '';
|
||||
// Init TCE for execution of update
|
||||
$tce = GeneralUtility::makeInstance(DataHandler::class);
|
||||
// Determine the scripts to execute
|
||||
switch ($this->conf['action']) {
|
||||
case 'show_change_owner_selector':
|
||||
$content = $this->renderUserSelector($this->conf['page'], $this->conf['ownerUid'], $this->conf['username']);
|
||||
break;
|
||||
case 'change_owner':
|
||||
$userId = $this->conf['new_owner_uid'];
|
||||
if (is_int($userId)) {
|
||||
// Prepare data to change
|
||||
$data = [];
|
||||
$data['pages'][$this->conf['page']]['perms_userid'] = $userId;
|
||||
// Execute TCE Update
|
||||
$tce->start($data, []);
|
||||
$tce->process_datamap();
|
||||
|
||||
$view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeOwner.html');
|
||||
$view->assign('userId', $userId);
|
||||
$usernameArray = BackendUtility::getUserNames('username', ' AND uid = ' . $userId);
|
||||
$view->assign('username', $usernameArray[$userId]['username']);
|
||||
$content = $view->render();
|
||||
} else {
|
||||
$response->getBody()->write('An error occurred: No page owner uid specified');
|
||||
$response = $response->withStatus(500);
|
||||
}
|
||||
break;
|
||||
case 'show_change_group_selector':
|
||||
$content = $this->renderGroupSelector($this->conf['page'], $this->conf['groupUid'], $this->conf['groupname']);
|
||||
break;
|
||||
case 'change_group':
|
||||
$groupId = $this->conf['new_group_uid'];
|
||||
if (is_int($groupId)) {
|
||||
// Prepare data to change
|
||||
$data = [];
|
||||
$data['pages'][$this->conf['page']]['perms_groupid'] = $groupId;
|
||||
// Execute TCE Update
|
||||
$tce->start($data, []);
|
||||
$tce->process_datamap();
|
||||
|
||||
$view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeGroup.html');
|
||||
$view->assign('groupId', $groupId);
|
||||
$groupnameArray = BackendUtility::getGroupNames('title', ' AND uid = ' . $groupId);
|
||||
$view->assign('groupname', $groupnameArray[$groupId]['title']);
|
||||
$content = $view->render();
|
||||
} else {
|
||||
$response->getBody()->write('An error occurred: No page group uid specified');
|
||||
$response = $response->withStatus(500);
|
||||
}
|
||||
break;
|
||||
case 'toggle_edit_lock':
|
||||
// Prepare data to change
|
||||
$data = [];
|
||||
$data['pages'][$this->conf['page']]['editlock'] = $this->conf['editLockState'] === 1 ? 0 : 1;
|
||||
// Execute TCE Update
|
||||
$tce->start($data, []);
|
||||
$tce->process_datamap();
|
||||
$content = $this->renderToggleEditLock($this->conf['page'], $data['pages'][$this->conf['page']]['editlock']);
|
||||
break;
|
||||
default:
|
||||
if ($this->conf['mode'] === 'delete') {
|
||||
$this->conf['permissions'] = (int)($this->conf['permissions'] - $this->conf['bits']);
|
||||
} else {
|
||||
$this->conf['permissions'] = (int)($this->conf['permissions'] + $this->conf['bits']);
|
||||
}
|
||||
// Prepare data to change
|
||||
$data = [];
|
||||
$data['pages'][$this->conf['page']]['perms_' . $this->conf['who']] = $this->conf['permissions'];
|
||||
// Execute TCE Update
|
||||
$tce->start($data, []);
|
||||
$tce->process_datamap();
|
||||
|
||||
$view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangePermission.html');
|
||||
$view->assign('permission', $this->conf['permissions']);
|
||||
$view->assign('scope', $this->conf['who']);
|
||||
$content = $view->render();
|
||||
}
|
||||
$response->getBody()->write($content);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the user selector element
|
||||
*
|
||||
* @param int $page The page id to change the user for
|
||||
* @param int $ownerUid The page owner uid
|
||||
* @param string $username The username to display
|
||||
* @return string The html select element
|
||||
*/
|
||||
protected function renderUserSelector($page, $ownerUid, $username = '')
|
||||
{
|
||||
$page = (int)$page;
|
||||
$ownerUid = (int)$ownerUid;
|
||||
// Get usernames
|
||||
$beUsers = BackendUtility::getUserNames();
|
||||
// Owner selector:
|
||||
$options = '';
|
||||
// Loop through the users
|
||||
foreach ($beUsers as $uid => $row) {
|
||||
$uid = (int)$uid;
|
||||
$selected = $uid === $ownerUid ? ' selected="selected"' : '';
|
||||
$options .= '<option value="' . $uid . '"' . $selected . '>' . htmlspecialchars($row['username']) . '</option>';
|
||||
}
|
||||
$elementId = 'o_' . $page;
|
||||
$options = '<option value="0"></option>' . $options;
|
||||
$selector = '<select name="new_page_owner" id="new_page_owner">' . $options . '</select>';
|
||||
$saveButton = '<a class="saveowner btn btn-default" data-page="' . $page . '" data-owner="' . $ownerUid
|
||||
. '" data-element-id="' . $elementId . '" title="Change owner">'
|
||||
. $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render()
|
||||
. '</a>';
|
||||
$cancelButton = '<a class="restoreowner btn btn-default" data-page="' . $page . '" data-owner="' . $ownerUid
|
||||
. '" data-element-id="' . $elementId . '"'
|
||||
. (!empty($username) ? ' data-username="' . htmlspecialchars($username) . '"' : '')
|
||||
. ' title="Cancel">'
|
||||
. $this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)->render()
|
||||
. '</a>';
|
||||
return '<span id="' . $elementId . '">'
|
||||
. $selector
|
||||
. '<span class="btn-group">'
|
||||
. $saveButton
|
||||
. $cancelButton
|
||||
. '</span>'
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the group selector element
|
||||
*
|
||||
* @param int $page The page id to change the user for
|
||||
* @param int $groupUid The page group uid
|
||||
* @param string $groupname The groupname to display
|
||||
* @return string The html select element
|
||||
*/
|
||||
protected function renderGroupSelector($page, $groupUid, $groupname = '')
|
||||
{
|
||||
$page = (int)$page;
|
||||
$groupUid = (int)$groupUid;
|
||||
|
||||
// Get group names
|
||||
$beGroupsO = $beGroups = BackendUtility::getGroupNames();
|
||||
// Group selector:
|
||||
$options = '';
|
||||
// flag: is set if the page-groupid equals one from the group-list
|
||||
$userset = 0;
|
||||
// Loop through the groups
|
||||
foreach ($beGroups as $uid => $row) {
|
||||
$uid = (int)$uid;
|
||||
if ($uid === $groupUid) {
|
||||
$userset = 1;
|
||||
$selected = ' selected="selected"';
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
$options .= '<option value="' . $uid . '"' . $selected . '>' . htmlspecialchars($row['title']) . '</option>';
|
||||
}
|
||||
// If the group was not set AND there is a group for the page
|
||||
if (!$userset && $groupUid) {
|
||||
$options = '<option value="' . $groupUid . '" selected="selected">' .
|
||||
htmlspecialchars($beGroupsO[$groupUid]['title']) . '</option>' . $options;
|
||||
}
|
||||
$elementId = 'g_' . $page;
|
||||
$options = '<option value="0"></option>' . $options;
|
||||
$selector = '<select name="new_page_group" id="new_page_group">' . $options . '</select>';
|
||||
$saveButton = '<a class="savegroup btn btn-default" data-page="' . $page . '" data-group-id="' . $groupUid
|
||||
. '" data-element-id="' . $elementId . '" title="Change group">'
|
||||
. $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render()
|
||||
. '</a>';
|
||||
$cancelButton = '<a class="restoregroup btn btn-default" data-page="' . $page . '" data-group-id="' . $groupUid
|
||||
. '" data-element-id="' . $elementId . '"'
|
||||
. (!empty($groupname) ? ' data-groupname="' . htmlspecialchars($groupname) . '"' : '')
|
||||
. ' title="Cancel">'
|
||||
. $this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)->render()
|
||||
. '</a>';
|
||||
return '<span id="' . $elementId . '">'
|
||||
. $selector
|
||||
. '<span class="btn-group">'
|
||||
. $saveButton
|
||||
. $cancelButton
|
||||
. '</span>'
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the string with the new edit lock state of a page record
|
||||
*
|
||||
* @param int $page The TYPO3 page id
|
||||
* @param string $editLockState The state of the TYPO3 page (locked, unlocked)
|
||||
* @return string The new edit lock string wrapped in HTML
|
||||
*/
|
||||
protected function renderToggleEditLock($page, $editLockState)
|
||||
{
|
||||
$page = (int)$page;
|
||||
if ($editLockState === 1) {
|
||||
$ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page
|
||||
. '" data-lockstate="1" title="The page and all content is locked for editing by all non-Admin users.">'
|
||||
. $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL)->render() . '</a></span>';
|
||||
} else {
|
||||
$ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page .
|
||||
'" data-lockstate="0" title="Enable the »Admin-only« edit lock for this page">'
|
||||
. $this->iconFactory->getIcon('actions-unlock', Icon::SIZE_SMALL)->render() . '</a></span>';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Core\Localization\LanguageService
|
||||
*/
|
||||
protected function getLanguageService()
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUser()
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Controller;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
|
||||
use TYPO3\CMS\Backend\Tree\View\PageTreeView;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Backend\View\BackendTemplateView;
|
||||
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
/**
|
||||
* Backend module page permissions
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class PermissionController extends ActionController
|
||||
{
|
||||
/**
|
||||
* @var string prefix for session
|
||||
*/
|
||||
const SESSION_PREFIX = 'tx_Beuser_';
|
||||
|
||||
/**
|
||||
* @var int the current page id
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $returnUrl = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $depth;
|
||||
|
||||
/**
|
||||
* Number of levels to enable recursive settings for
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $getLevels = 10;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $pageInfo = [];
|
||||
|
||||
/**
|
||||
* Backend Template Container
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $defaultViewObjectName = BackendTemplateView::class;
|
||||
|
||||
/**
|
||||
* BackendTemplateContainer
|
||||
*
|
||||
* @var BackendTemplateView
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
/**
|
||||
* Initialize action
|
||||
*/
|
||||
protected function initializeAction()
|
||||
{
|
||||
// determine depth parameter
|
||||
$this->depth = (int)GeneralUtility::_GP('depth') > 0
|
||||
? (int)GeneralUtility::_GP('depth')
|
||||
: (int)$this->getBackendUser()->getSessionData(self::SESSION_PREFIX . 'depth');
|
||||
if ($this->request->hasArgument('depth')) {
|
||||
$this->depth = (int)$this->request->getArgument('depth');
|
||||
}
|
||||
$this->getBackendUser()->setAndSaveSessionData(self::SESSION_PREFIX . 'depth', $this->depth);
|
||||
|
||||
// determine id parameter
|
||||
$this->id = (int)GeneralUtility::_GP('id');
|
||||
if ($this->request->hasArgument('id')) {
|
||||
$this->id = (int)$this->request->getArgument('id');
|
||||
}
|
||||
|
||||
if (!BackendUtility::getRecord('pages', $this->id)) {
|
||||
$this->id = 0;
|
||||
}
|
||||
|
||||
$this->returnUrl = GeneralUtility::_GP('returnUrl');
|
||||
if ($this->request->hasArgument('returnUrl')) {
|
||||
$this->returnUrl = $this->request->getArgument('returnUrl');
|
||||
}
|
||||
|
||||
$this->setPageInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes view
|
||||
*
|
||||
* @param ViewInterface $view The view to be initialized
|
||||
*/
|
||||
protected function initializeView(ViewInterface $view)
|
||||
{
|
||||
parent::initializeView($view);
|
||||
$this->setPageInfo();
|
||||
$view->assign(
|
||||
'previewUrl',
|
||||
BackendUtility::viewOnClick(
|
||||
(int)$this->pageInfo['uid'],
|
||||
'',
|
||||
BackendUtility::BEgetRootLine((int)$this->pageInfo['uid'])
|
||||
)
|
||||
);
|
||||
|
||||
// the view of the update action has a different view class
|
||||
if ($view instanceof BackendTemplateView) {
|
||||
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Beuser/Permissions');
|
||||
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
|
||||
|
||||
$this->registerDocHeaderButtons();
|
||||
$this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageInfo);
|
||||
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the Icons into the docheader
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function registerDocHeaderButtons()
|
||||
{
|
||||
/** @var ButtonBar $buttonBar */
|
||||
$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
|
||||
$currentRequest = $this->request;
|
||||
$moduleName = $currentRequest->getPluginName();
|
||||
$getVars = $this->request->getArguments();
|
||||
$lang = $this->getLanguageService();
|
||||
|
||||
$extensionName = $currentRequest->getControllerExtensionName();
|
||||
if (empty($getVars)) {
|
||||
$modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
|
||||
$getVars = ['id', 'route', $modulePrefix];
|
||||
}
|
||||
|
||||
if ($currentRequest->getControllerActionName() === 'edit') {
|
||||
// CLOSE button:
|
||||
if (!empty($this->returnUrl)) {
|
||||
$closeButton = $buttonBar->makeLinkButton()
|
||||
->setHref($this->returnUrl)
|
||||
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.closeDoc'))
|
||||
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon(
|
||||
'actions-close',
|
||||
Icon::SIZE_SMALL
|
||||
));
|
||||
$buttonBar->addButton($closeButton);
|
||||
}
|
||||
|
||||
// SAVE button:
|
||||
$saveButton = $buttonBar->makeInputButton()
|
||||
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.saveCloseDoc'))
|
||||
->setName('tx_beuser_system_beusertxpermission[submit]')
|
||||
->setValue('Save')
|
||||
->setForm('PermissionControllerEdit')
|
||||
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon(
|
||||
'actions-document-save',
|
||||
Icon::SIZE_SMALL
|
||||
))
|
||||
->setShowLabelText(true);
|
||||
|
||||
$buttonBar->addButton($saveButton);
|
||||
}
|
||||
|
||||
// SHORTCUT botton:
|
||||
$shortcutButton = $buttonBar->makeShortcutButton()
|
||||
->setModuleName($moduleName)
|
||||
->setGetVariables($getVars);
|
||||
$buttonBar->addButton($shortcutButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
if (!$this->id) {
|
||||
$this->pageInfo = ['title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], 'uid' => 0, 'pid' => 0];
|
||||
}
|
||||
|
||||
if ($this->getBackendUser()->workspace != 0) {
|
||||
// Adding section with the permission setting matrix:
|
||||
$this->addFlashMessage(
|
||||
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarningText', 'beuser'),
|
||||
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarning', 'beuser'),
|
||||
FlashMessage::WARNING
|
||||
);
|
||||
}
|
||||
|
||||
// depth options
|
||||
$depthOptions = [];
|
||||
$url = $this->uriBuilder->reset()->setArguments([
|
||||
'action' => 'index',
|
||||
'depth' => '__DEPTH__',
|
||||
'id' => $this->id
|
||||
])->buildBackendUri();
|
||||
foreach ([1, 2, 3, 4, 10] as $depthLevel) {
|
||||
$levelLabel = $depthLevel === 1 ? 'level' : 'levels';
|
||||
$depthOptions[$depthLevel] = $depthLevel . ' ' . LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $levelLabel, 'beuser');
|
||||
}
|
||||
$this->view->assign('currentId', $this->id);
|
||||
$this->view->assign('depthBaseUrl', $url);
|
||||
$this->view->assign('depth', $this->depth);
|
||||
$this->view->assign('depthOptions', $depthOptions);
|
||||
|
||||
$beUserArray = BackendUtility::getUserNames();
|
||||
$this->view->assign('beUsers', $beUserArray);
|
||||
$beGroupArray = BackendUtility::getGroupNames();
|
||||
$this->view->assign('beGroups', $beGroupArray);
|
||||
|
||||
/** @var PageTreeView $tree */
|
||||
$tree = GeneralUtility::makeInstance(PageTreeView::class);
|
||||
$tree->init();
|
||||
$tree->addField('perms_user', true);
|
||||
$tree->addField('perms_group', true);
|
||||
$tree->addField('perms_everybody', true);
|
||||
$tree->addField('perms_userid', true);
|
||||
$tree->addField('perms_groupid', true);
|
||||
$tree->addField('hidden');
|
||||
$tree->addField('fe_group');
|
||||
$tree->addField('starttime');
|
||||
$tree->addField('endtime');
|
||||
$tree->addField('editlock');
|
||||
|
||||
// Create the tree from $this->id
|
||||
if ($this->id) {
|
||||
$tree->tree[] = ['row' => $this->pageInfo, 'HTML' => $tree->getIcon($this->id)];
|
||||
} else {
|
||||
$tree->tree[] = ['row' => $this->pageInfo, 'HTML' => $tree->getRootIcon($this->pageInfo)];
|
||||
}
|
||||
$tree->getTree($this->id, $this->depth);
|
||||
$this->view->assign('viewTree', $tree->tree);
|
||||
|
||||
// CSH for permissions setting
|
||||
$this->view->assign('cshItem', BackendUtility::cshItem('xMOD_csh_corebe', 'perm_module', null, '<span class="btn btn-default btn-sm">|</span>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*/
|
||||
public function editAction()
|
||||
{
|
||||
$this->view->assign('id', $this->id);
|
||||
$this->view->assign('depth', $this->depth);
|
||||
|
||||
if (!$this->id) {
|
||||
$this->pageInfo = ['title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], 'uid' => 0, 'pid' => 0];
|
||||
}
|
||||
if ($this->getBackendUser()->workspace != 0) {
|
||||
// Adding FlashMessage with the permission setting matrix:
|
||||
$this->addFlashMessage(
|
||||
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarningText', 'beuser'),
|
||||
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarning', 'beuser'),
|
||||
FlashMessage::WARNING
|
||||
);
|
||||
}
|
||||
// Get user names and group names
|
||||
$beGroupArray = BackendUtility::getGroupNames();
|
||||
$beUserArray = BackendUtility::getUserNames();
|
||||
|
||||
// Owner selector
|
||||
$beUserDataArray = [0 => LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone', 'beuser')];
|
||||
foreach ($beUserArray as $uid => &$row) {
|
||||
$beUserDataArray[$uid] = $row['username'];
|
||||
}
|
||||
$beUserDataArray[-1] = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectUnchanged', 'beuser');
|
||||
$this->view->assign('currentBeUser', $this->pageInfo['perms_userid']);
|
||||
$this->view->assign('beUserData', $beUserDataArray);
|
||||
|
||||
// Group selector
|
||||
$beGroupDataArray = [0 => LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone', 'beuser')];
|
||||
foreach ($beGroupArray as $uid => $row) {
|
||||
$beGroupDataArray[$uid] = $row['title'];
|
||||
}
|
||||
$beGroupDataArray[-1] = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectUnchanged', 'beuser');
|
||||
$this->view->assign('currentBeGroup', $this->pageInfo['perms_groupid']);
|
||||
$this->view->assign('beGroupData', $beGroupDataArray);
|
||||
$this->view->assign('pageInfo', $this->pageInfo);
|
||||
$this->view->assign('returnUrl', $this->returnUrl);
|
||||
$this->view->assign('recursiveSelectOptions', $this->getRecursiveSelectOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update action
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $mirror
|
||||
*/
|
||||
protected function updateAction(array $data, array $mirror)
|
||||
{
|
||||
$dataHandlerInput = [];
|
||||
// Prepare the input data for data handler
|
||||
if (!empty($data['pages'])) {
|
||||
foreach ($data['pages'] as $pageUid => $properties) {
|
||||
// if the owner and group field shouldn't be touched, unset the option
|
||||
if ((int)$properties['perms_userid'] === -1) {
|
||||
unset($properties['perms_userid']);
|
||||
}
|
||||
if ((int)$properties['perms_groupid'] === -1) {
|
||||
unset($properties['perms_groupid']);
|
||||
}
|
||||
$dataHandlerInput[$pageUid] = $properties;
|
||||
if (!empty($mirror['pages'][$pageUid])) {
|
||||
$mirrorPages = GeneralUtility::intExplode(',', $mirror['pages'][$pageUid]);
|
||||
foreach ($mirrorPages as $mirrorPageUid) {
|
||||
$dataHandlerInput[$mirrorPageUid] = $properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
|
||||
$dataHandler->start(
|
||||
[
|
||||
'pages' => $dataHandlerInput
|
||||
],
|
||||
[]
|
||||
);
|
||||
$dataHandler->process_datamap();
|
||||
|
||||
$this->redirectToUri($this->returnUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUser()
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finding tree and offer setting of values recursively.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getRecursiveSelectOptions()
|
||||
{
|
||||
// Initialize tree object:
|
||||
$tree = GeneralUtility::makeInstance(PageTreeView::class);
|
||||
$tree->init();
|
||||
$tree->addField('perms_userid', true);
|
||||
$tree->makeHTML = 0;
|
||||
$tree->setRecs = 1;
|
||||
// Make tree:
|
||||
$tree->getTree($this->id, $this->getLevels, '');
|
||||
$options = [];
|
||||
$options[''] = '';
|
||||
// If there are a hierarchy of page ids, then...
|
||||
if ($this->getBackendUser()->user['uid'] && !empty($tree->orig_ids_hierarchy)) {
|
||||
// Init:
|
||||
$labelRecursive = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:recursive', 'beuser');
|
||||
$labelLevel = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:level', 'beuser');
|
||||
$labelLevels = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:levels', 'beuser');
|
||||
$labelPageAffected = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:page_affected', 'beuser');
|
||||
$labelPagesAffected = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:pages_affected', 'beuser');
|
||||
$theIdListArr = [];
|
||||
// Traverse the number of levels we want to allow recursive
|
||||
// setting of permissions for:
|
||||
for ($a = $this->getLevels; $a > 0; $a--) {
|
||||
if (is_array($tree->orig_ids_hierarchy[$a])) {
|
||||
foreach ($tree->orig_ids_hierarchy[$a] as $theId) {
|
||||
$theIdListArr[] = $theId;
|
||||
}
|
||||
$lKey = $this->getLevels - $a + 1;
|
||||
$pagesCount = count($theIdListArr);
|
||||
$options[implode(',', $theIdListArr)] = $labelRecursive . ' ' . $lKey . ' ' . ($lKey === 1 ? $labelLevel : $labelLevels) .
|
||||
' (' . $pagesCount . ' ' . ($pagesCount === 1 ? $labelPageAffected : $labelPagesAffected) . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if page record exists and set pageInfo
|
||||
*/
|
||||
protected function setPageInfo(): void
|
||||
{
|
||||
$this->pageInfo = BackendUtility::readPageAccess(BackendUtility::getRecord('pages', $this->id) ? $this->id : 0, ' 1=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns LanguageService
|
||||
*
|
||||
* @return \TYPO3\CMS\Core\Localization\LanguageService
|
||||
*/
|
||||
protected function getLanguageService()
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Model for backend user
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUser extends \TYPO3\CMS\Extbase\Domain\Model\BackendUser
|
||||
{
|
||||
/**
|
||||
* Comma separated list of uids in multi-select
|
||||
* Might retrieve the labels from TCA/DataMapper
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $allowedLanguages = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dbMountPoints = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fileMountPoints = '';
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup>
|
||||
*/
|
||||
protected $backendUserGroups;
|
||||
|
||||
/**
|
||||
* @param string $allowedLanguages
|
||||
*/
|
||||
public function setAllowedLanguages($allowedLanguages)
|
||||
{
|
||||
$this->allowedLanguages = $allowedLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAllowedLanguages()
|
||||
{
|
||||
return $this->allowedLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dbMountPoints
|
||||
*/
|
||||
public function setDbMountPoints($dbMountPoints)
|
||||
{
|
||||
$this->dbMountPoints = $dbMountPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDbMountPoints()
|
||||
{
|
||||
return $this->dbMountPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileMountPoints
|
||||
*/
|
||||
public function setFileMountPoints($fileMountPoints)
|
||||
{
|
||||
$this->fileMountPoints = $fileMountPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileMountPoints()
|
||||
{
|
||||
return $this->fileMountPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is active, not disabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
if ($this->getIsDisabled()) {
|
||||
return false;
|
||||
}
|
||||
$now = new \DateTime('now');
|
||||
return !$this->getStartDateAndTime() && !$this->getEndDateAndTime() || $this->getStartDateAndTime() <= $now && (!$this->getEndDateAndTime() || $this->getEndDateAndTime() > $now);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $backendUserGroups
|
||||
*/
|
||||
public function setBackendUserGroups($backendUserGroups)
|
||||
{
|
||||
$this->backendUserGroups = $backendUserGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
||||
*/
|
||||
public function getBackendUserGroups()
|
||||
{
|
||||
return $this->backendUserGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is currently logged in
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCurrentlyLoggedIn()
|
||||
{
|
||||
return $this->getUid() === (int)$this->getBackendUser()->user['uid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently logged in backend user
|
||||
*
|
||||
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
|
||||
*/
|
||||
public function getBackendUser()
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
|
||||
/**
|
||||
* Model for backend user group
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $hidden;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup>
|
||||
* @Extbase\ORM\Lazy
|
||||
*/
|
||||
protected $subGroups;
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $hidden
|
||||
*/
|
||||
public function setHidden($hidden)
|
||||
{
|
||||
$this->hidden = $hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getHidden()
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $subGroups
|
||||
*/
|
||||
public function setSubGroups($subGroups)
|
||||
{
|
||||
$this->subGroups = $subGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
|
||||
*/
|
||||
public function getSubGroups()
|
||||
{
|
||||
return $this->subGroups;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Demand filter for listings
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class Demand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const ALL = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const USERTYPE_ADMINONLY = 1;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const USERTYPE_USERONLY = 2;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const STATUS_ACTIVE = 1;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const STATUS_INACTIVE = 2;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const LOGIN_SOME = 1;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
const LOGIN_NONE = 2;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $userName = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $userType = self::ALL;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $status = self::ALL;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $logins = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $backendUserGroup = 0;
|
||||
|
||||
/**
|
||||
* @param string $userName
|
||||
*/
|
||||
public function setUserName($userName)
|
||||
{
|
||||
$this->userName = $userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUserName()
|
||||
{
|
||||
return $this->userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userType
|
||||
*/
|
||||
public function setUserType($userType)
|
||||
{
|
||||
$this->userType = $userType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getUserType()
|
||||
{
|
||||
return $this->userType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $logins
|
||||
*/
|
||||
public function setLogins($logins)
|
||||
{
|
||||
$this->logins = $logins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLogins()
|
||||
{
|
||||
return $this->logins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $backendUserGroup
|
||||
*/
|
||||
public function setBackendUserGroup($backendUserGroup)
|
||||
{
|
||||
$this->backendUserGroup = $backendUserGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBackendUserGroup()
|
||||
{
|
||||
return $this->backendUserGroup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module data object
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class ModuleData
|
||||
{
|
||||
/**
|
||||
* @var \TYPO3\CMS\Beuser\Domain\Model\Demand
|
||||
*/
|
||||
protected $demand;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $compareUserList = [];
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
|
||||
*/
|
||||
public function injectDemand(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)
|
||||
{
|
||||
$this->demand = $demand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \TYPO3\CMS\Beuser\Domain\Model\Demand
|
||||
*/
|
||||
public function getDemand()
|
||||
{
|
||||
return $this->demand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
|
||||
*/
|
||||
public function setDemand(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)
|
||||
{
|
||||
$this->demand = $demand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compare list as array of user uis
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCompareUserList()
|
||||
{
|
||||
return array_keys($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($uid)
|
||||
{
|
||||
$this->compareUserList[$uid] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip one backend user from the compare user list
|
||||
*
|
||||
* @param int $uid
|
||||
*/
|
||||
public function detachUidCompareUser($uid)
|
||||
{
|
||||
unset($this->compareUserList[$uid]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Repository for \TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserGroupRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
||||
{
|
||||
/**
|
||||
* @var array Default order is by title ascending
|
||||
*/
|
||||
protected $defaultOrderings = [
|
||||
'title' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
|
||||
];
|
||||
|
||||
/**
|
||||
* Overwrite createQuery to don't respect enable fields
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
|
||||
*/
|
||||
public function createQuery()
|
||||
{
|
||||
$query = parent::createQuery();
|
||||
$query->getQuerySettings()->setIgnoreEnableFields(true);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\Demand;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Session\Backend\SessionBackendInterface;
|
||||
use TYPO3\CMS\Core\Session\SessionManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\MathUtility;
|
||||
use TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||
|
||||
/**
|
||||
* Repository for \TYPO3\CMS\Beuser\Domain\Model\BackendUser
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserRepository extends BackendUserGroupRepository
|
||||
{
|
||||
/**
|
||||
* Finds Backend Users on a given list of uids
|
||||
*
|
||||
* @param array $uidList
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult<\TYPO3\CMS\Beuser\Domain\Model\BackendUser>
|
||||
*/
|
||||
public function findByUidList(array $uidList)
|
||||
{
|
||||
$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
|
||||
*
|
||||
* @param Demand $demand
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult<\TYPO3\CMS\Beuser\Domain\Model\BackendUser>
|
||||
*/
|
||||
public function findDemanded(Demand $demand)
|
||||
{
|
||||
$constraints = [];
|
||||
$query = $this->createQuery();
|
||||
// Find invisible as well, but not deleted
|
||||
$constraints[] = $query->equals('deleted', 0);
|
||||
$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());
|
||||
}
|
||||
$constraints[] = $query->logicalOr($searchConstraints);
|
||||
}
|
||||
// Only display admin users
|
||||
if ($demand->getUserType() == Demand::USERTYPE_ADMINONLY) {
|
||||
$constraints[] = $query->equals('admin', 1);
|
||||
}
|
||||
// Only display non-admin users
|
||||
if ($demand->getUserType() == Demand::USERTYPE_USERONLY) {
|
||||
$constraints[] = $query->equals('admin', 0);
|
||||
}
|
||||
// Only display active users
|
||||
if ($demand->getStatus() == Demand::STATUS_ACTIVE) {
|
||||
$constraints[] = $query->equals('disable', 0);
|
||||
}
|
||||
// Only display in-active users
|
||||
if ($demand->getStatus() == Demand::STATUS_INACTIVE) {
|
||||
$constraints[] = $query->logicalOr($query->equals('disable', 1));
|
||||
}
|
||||
// Not logged in before
|
||||
if ($demand->getLogins() == Demand::LOGIN_NONE) {
|
||||
$constraints[] = $query->equals('lastlogin', 0);
|
||||
}
|
||||
// At least one login
|
||||
if ($demand->getLogins() == Demand::LOGIN_SOME) {
|
||||
$constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
|
||||
}
|
||||
// In backend user group
|
||||
// @TODO: Refactor for real n:m relations
|
||||
if ($demand->getBackendUserGroup()) {
|
||||
$constraints[] = $query->logicalOr([
|
||||
$query->equals('usergroup', (int)$demand->getBackendUserGroup()),
|
||||
$query->like('usergroup', (int)$demand->getBackendUserGroup() . ',%'),
|
||||
$query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()),
|
||||
$query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup() . ',%')
|
||||
]);
|
||||
}
|
||||
$query->matching($query->logicalAnd($constraints));
|
||||
/** @var QueryResult $result */
|
||||
$result = $query->execute();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Backend Users currently online
|
||||
*
|
||||
* @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult<\TYPO3\CMS\Beuser\Domain\Model\BackendUser>
|
||||
*/
|
||||
public function findOnline()
|
||||
{
|
||||
$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
|
||||
*
|
||||
* @return QueryInterface
|
||||
*/
|
||||
public function createQuery()
|
||||
{
|
||||
$query = parent::createQuery();
|
||||
$query->getQuerySettings()->setIgnoreEnableFields(true);
|
||||
$query->getQuerySettings()->setIncludeDeleted(true);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SessionBackendInterface
|
||||
*/
|
||||
protected function getSessionBackend()
|
||||
{
|
||||
$loginType = $this->getBackendUserAuthentication()->getLoginType();
|
||||
return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend($loginType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUserAuthentication()
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
|
||||
use TYPO3\CMS\Core\Session\Backend\SessionBackendInterface;
|
||||
use TYPO3\CMS\Core\Session\SessionManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* Repository for \TYPO3\CMS\Extbase\Domain\Model\BackendUser
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserSessionRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Find all active sessions for all backend users
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findAllActive()
|
||||
{
|
||||
$sessionBackend = $this->getSessionBackend();
|
||||
$allSessions = $sessionBackend->getAll();
|
||||
|
||||
// Map array to correct keys
|
||||
$allSessions = array_map(
|
||||
function ($session) {
|
||||
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, function ($session1, $session2) {
|
||||
return $session1['timestamp'] <=> $session2['timestamp'];
|
||||
});
|
||||
|
||||
return $allSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Sessions for specific BackendUser
|
||||
*
|
||||
* @param BackendUser $backendUser
|
||||
* @return array
|
||||
*/
|
||||
public function findByBackendUser(BackendUser $backendUser)
|
||||
{
|
||||
$allActive = $this->findAllActive();
|
||||
|
||||
return array_filter(
|
||||
$allActive,
|
||||
function ($session) use ($backendUser) {
|
||||
return (int)$session['ses_userid'] === $backendUser->getUid();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update current session to move back to the original user.
|
||||
*
|
||||
* @param AbstractUserAuthentication $authentication
|
||||
*/
|
||||
public function switchBackToOriginalUser(AbstractUserAuthentication $authentication)
|
||||
{
|
||||
$sessionBackend = $this->getSessionBackend();
|
||||
$sessionId = $this->getBackendSessionId();
|
||||
$sessionBackend->update(
|
||||
$sessionId,
|
||||
[
|
||||
'ses_userid' => $authentication->user['ses_backuserid'],
|
||||
'ses_backuserid' => 0
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBackendSessionId(): string
|
||||
{
|
||||
return $GLOBALS['BE_USER']->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SessionBackendInterface
|
||||
*/
|
||||
protected function getSessionBackend(): SessionBackendInterface
|
||||
{
|
||||
return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Exception as CoreException;
|
||||
|
||||
/**
|
||||
* Generic Beuser exception
|
||||
* @internal
|
||||
*/
|
||||
class Exception extends CoreException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Hook;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\Controller\BackendController;
|
||||
use TYPO3\CMS\Core\Page\PageRenderer;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This class adds Access-permission related JavaScript to the backend
|
||||
* @internal This class is a TYPO3 core-internal hook implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendControllerHook
|
||||
{
|
||||
/**
|
||||
* Adds beuser permission specific JavaScript
|
||||
*
|
||||
* @param array $configuration
|
||||
* @param BackendController $backendController
|
||||
*/
|
||||
public function addJavaScript(array $configuration, BackendController $backendController)
|
||||
{
|
||||
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
|
||||
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
|
||||
$this->getPageRenderer()->addInlineSetting('AccessPermissions', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('system_BeuserTxPermission'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageRenderer
|
||||
*/
|
||||
protected function getPageRenderer()
|
||||
{
|
||||
return GeneralUtility::makeInstance(PageRenderer::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Hook;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\HttpUtility;
|
||||
|
||||
/**
|
||||
* Backend user switchback, for logoff_pre_processing hook within
|
||||
* \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication class
|
||||
* @internal This class is a TYPO3 core-internal hook implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class SwitchBackUserHook
|
||||
{
|
||||
/**
|
||||
* Switch backend user session.
|
||||
*
|
||||
* @param array $params
|
||||
* @param AbstractUserAuthentication $authentication
|
||||
* @see AbstractUserAuthentication
|
||||
*/
|
||||
public function switchBack($params, AbstractUserAuthentication $authentication)
|
||||
{
|
||||
if ($this->isAHandledBackendSession($authentication)) {
|
||||
$objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
|
||||
$backendUserSessionRepository = $objectManager->get(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository::class);
|
||||
$backendUserSessionRepository->switchBackToOriginalUser($authentication);
|
||||
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
|
||||
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
|
||||
HttpUtility::redirect((string)$uriBuilder->buildUriFromRoute('main'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given authentication object is a backend session and
|
||||
* contains all necessary information to allow switching.
|
||||
*
|
||||
* @param AbstractUserAuthentication $authentication
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAHandledBackendSession(AbstractUserAuthentication $authentication)
|
||||
{
|
||||
return ($authentication instanceof BackendUserAuthentication)
|
||||
&& is_array($authentication->user)
|
||||
&& (int)$authentication->user['uid'] > 0
|
||||
&& (int)$authentication->user['ses_backuserid'] > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\Service;
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\Demand;
|
||||
use TYPO3\CMS\Beuser\Domain\Model\ModuleData;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module data storage service.
|
||||
* Used to store and retrieve module state (eg. checkboxes, selections).
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class ModuleDataStorageService implements \TYPO3\CMS\Core\SingletonInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const KEY = 'tx_beuser';
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads module data for user settings or returns a fresh object if module data is invalid or unset
|
||||
*
|
||||
* @return \TYPO3\CMS\Beuser\Domain\Model\ModuleData
|
||||
*/
|
||||
public function loadModuleData()
|
||||
{
|
||||
$moduleData = $GLOBALS['BE_USER']->getModuleData(self::KEY) ?? '';
|
||||
if ($moduleData !== '') {
|
||||
$moduleData = @unserialize($moduleData, ['allowed_classes' => [ModuleData::class, Demand::class]]);
|
||||
if ($moduleData instanceof ModuleData) {
|
||||
return $moduleData;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->objectManager->get(ModuleData::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists serialized module data to user settings
|
||||
*
|
||||
* @param \TYPO3\CMS\Beuser\Domain\Model\ModuleData $moduleData
|
||||
*/
|
||||
public function persistModuleData(\TYPO3\CMS\Beuser\Domain\Model\ModuleData $moduleData)
|
||||
{
|
||||
$GLOBALS['BE_USER']->pushModuleData(self::KEY, serialize($moduleData));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Exception;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Get a value from an array by given key.
|
||||
* @internal
|
||||
*/
|
||||
class ArrayElementViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$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)
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @throws Exception
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$array = $arguments['array'];
|
||||
$key = $arguments['key'];
|
||||
$subKey = $arguments['subKey'];
|
||||
$result = '';
|
||||
if (is_array($array) && 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 $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of pages uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class PagesViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for pages
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title')
|
||||
->from('pages')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('uid', 'ASC')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of sys_filemounts uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class SysFileMountsViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for sys_filemounts
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_filemounts');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title')
|
||||
->from('sys_filemounts')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('title', 'ASC')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of sys_language uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class SysLanguageViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for sys_language
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title', 'flag')
|
||||
->from('sys_language')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('sorting')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Render a link to DataHandler command
|
||||
* @internal
|
||||
*/
|
||||
class IssueCommandViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('parameters', 'string', 'Is a set of GET params to send to route tce_db (SimpleDataHandlerController). Example: "&cmd[tt_content][123][move]=456" or "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World', true);
|
||||
$this->registerArgument('redirectUrl', 'string', 'Redirect URL if any other that \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(\'REQUEST_URI\') is preferred', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL with a command to TYPO3 Core Engine - DataHandler (route tce_db)
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string URL to tce_db + parameters
|
||||
* @see \TYPO3\CMS\Backend\Utility\BackendUtility::getLinkToDataHandlerAction()
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$urlParameters = [
|
||||
'redirect' => $arguments['redirectUrl'] ?: GeneralUtility::getIndpEnv('REQUEST_URI')
|
||||
];
|
||||
if (isset($arguments['parameters'])) {
|
||||
$parametersArray = GeneralUtility::explodeUrl2Array($arguments['parameters']);
|
||||
$urlParameters += $parametersArray;
|
||||
}
|
||||
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
|
||||
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
|
||||
return (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Render permission icon group (user / group / others) of the "Access" module.
|
||||
*
|
||||
* Most of that could be done in fluid directly, but this ViewHelper
|
||||
* is much better performance wise.
|
||||
* @internal
|
||||
*/
|
||||
class PermissionsViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* @var array Cached labels for a single permission mask like "Delete page"
|
||||
*/
|
||||
protected static $permissionLabels = [];
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('permission', 'int', 'Current permission', true);
|
||||
$this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true);
|
||||
$this->registerArgument('pageId', 'int', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return permissions.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string
|
||||
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$masks = [1, 16, 2, 4, 8];
|
||||
|
||||
if (empty(static::$permissionLabels)) {
|
||||
foreach ($masks as $mask) {
|
||||
static::$permissionLabels[$mask] = LocalizationUtility::translate(
|
||||
'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask,
|
||||
'be_user'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$icon = '';
|
||||
foreach ($masks as $mask) {
|
||||
if ($arguments['permission'] & $mask) {
|
||||
$permissionClass = 'fa-check text-success';
|
||||
$mode = 'delete';
|
||||
} else {
|
||||
$permissionClass = 'fa-times text-danger';
|
||||
$mode = 'add';
|
||||
}
|
||||
|
||||
$label = static::$permissionLabels[$mask];
|
||||
$icon .= '<span style="cursor:pointer"'
|
||||
. ' title="' . htmlspecialchars($label) . '"'
|
||||
. ' data-toggle="tooltip"'
|
||||
. ' data-page="' . htmlspecialchars($arguments['pageId']) . '"'
|
||||
. ' data-permissions="' . htmlspecialchars($arguments['permission']) . '"'
|
||||
. ' data-who="' . htmlspecialchars($arguments['scope']) . '"'
|
||||
. ' data-bits="' . htmlspecialchars($mask) . '"'
|
||||
. ' data-mode="' . htmlspecialchars($mode) . '"'
|
||||
. ' class="t3-icon change-permission fa ' . htmlspecialchars($permissionClass) . '"></span>';
|
||||
}
|
||||
|
||||
return '<span id="' . htmlspecialchars($arguments['pageId'] . '_' . $arguments['scope']) . '">' . $icon . '</span>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Renders 'Delete user' link
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RemoveUserViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the URL to remove a user.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$urlParameters = [
|
||||
'cmd[be_users][' . $arguments['backendUser']->getUid() . '][delete]' => 1,
|
||||
'redirect' => GeneralUtility::getIndpEnv('REQUEST_URI')
|
||||
];
|
||||
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
|
||||
return (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
/**
|
||||
* Views sprite icon for a record (object)
|
||||
* @internal
|
||||
*/
|
||||
class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper
|
||||
{
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('table', 'string', '', true);
|
||||
$this->registerArgument('object', 'object', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays spriteIcon for database table and object
|
||||
*
|
||||
* @return string
|
||||
* @see IconFactory::getIconForRecord()
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$object = $arguments['object'];
|
||||
$table = $arguments['table'];
|
||||
|
||||
if (!is_object($object) || !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 ($table === 'be_users' && $object instanceof BackendUser) {
|
||||
$row['admin'] = $object->getIsAdministrator();
|
||||
}
|
||||
if (method_exists($object, 'getStartDateAndTime')) {
|
||||
$row['startTime'] = $object->getStartDateAndTime();
|
||||
}
|
||||
if (method_exists($object, 'getEndDateAndTime')) {
|
||||
$row['endTime'] = $object->getEndDateAndTime();
|
||||
}
|
||||
/** @var IconFactory $iconFactory */
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
return $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* 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!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Displays 'SwitchUser' link with sprite icon to change current backend user to target (non-admin) backendUser
|
||||
* @internal
|
||||
*/
|
||||
class SwitchUserViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render link with sprite icon to change current backend user to target
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$backendUser = $arguments['backendUser'];
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
if ($backendUser->getUid() == $GLOBALS['BE_USER']->user['uid'] || !$backendUser->isActive() || $GLOBALS['BE_USER']->user['ses_backuserid']) {
|
||||
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
|
||||
}
|
||||
$title = LocalizationUtility::translate('switchBackMode', 'beuser');
|
||||
return '<a class="btn btn-default" href="' .
|
||||
htmlspecialchars(GeneralUtility::linkThisScript(['SwitchUser' => $backendUser->getUid()])) .
|
||||
'" target="_top" title="' . htmlspecialchars($title) . '">' .
|
||||
$iconFactory->getIcon('actions-system-backend-user-switch', Icon::SIZE_SMALL)->render() . '</a>';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user