Commit 57a3cb39 authored by Felix Kopp's avatar Felix Kopp Committed by Christian Kuhn
Browse files

[FEATURE] Migrate EXT: beuser to Extbase

This patchset includes a new backend user administration.

Based on extbase a model for BackendUsers is included.
All users can be listed and the listing can be filtered by
* username
* usergroup
* admin/non-admin
* active/inactive
* ever logged in.

The user listing includes the last login column also the
limit of 1.000 users was removed and pagination integrated.

Selected users can be compared in a table view.
All active backend user sessions are listed - can be terminated.

Of course the SU/change user feature was migrated.
Clickmenu was widely integrated to allow editing right away.

Change-Id: I32569c848581a49b3948e093d717dad50e973c5d
Resolves: #39141
Resolves: #5288
Resolves: #37949
Resolves: #33427
Resolves: #18602
Resolves: #15494
Releases: 6.0
Reviewed-on: http://review.typo3.org/12935
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent 6dac2bc4
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Felix Kopp <felix-source@phorax.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Backend module user administration controller
*
* @author Felix Kopp <felix-source@phorax.com>
* @package TYPO3
* @subpackage beuser
*/
class Tx_Beuser_Controller_BackendUserController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var Tx_Beuser_Domain_Model_ModuleData
*/
protected $moduleData;
/**
* @var Tx_Beuser_Service_ModuleDataStorageService
* @inject
*/
protected $moduleDataStorageService;
/**
* @var Tx_Beuser_Domain_Repository_BackendUserRepository
* @inject
*/
protected $backendUserRepository;
/**
* @var Tx_Beuser_Domain_Repository_BackendUserGroupRepository
* @inject
*/
protected $backendUserGroupRepository;
/**
* @var Tx_Beuser_Domain_Repository_BackendUserSessionRepository
* @inject
*/
protected $backendUserSessionRepository;
/**
* Load and persist module data
*
* @param Tx_Extbase_MVC_RequestInterface $request
* @param Tx_Extbase_MVC_ResponseInterface $response
* @throws Tx_Extbase_MVC_Exception_StopAction
* @return void
*/
public function processRequest(Tx_Extbase_MVC_RequestInterface $request, Tx_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 (Tx_Extbase_MVC_Exception_StopAction $e) {
$this->moduleDataStorageService->persistModuleData($this->moduleData);
throw $e;
}
}
/**
* Displays all BackendUsers
* - Switch session to different user
*
* @param Tx_Beuser_Domain_Model_Demand $demand
* @return void
*/
public function indexAction(Tx_Beuser_Domain_Model_Demand $demand = NULL) {
if ($demand === NULL) {
$demand = $this->moduleData->getDemand();
} else {
$this->moduleData->setDemand($demand);
}
// Switch user permanently or only until logout
if (t3lib_div::_GP('SwitchUser')) {
$this->switchUser(t3lib_div::_GP('SwitchUser'), t3lib_div::_GP('switchBackUser'));
}
$compareUserList = $this->moduleData->getCompareUserList();
$this->view->assign('demand', $demand);
$this->view->assign('returnUrl', 'mod.php?M=tools_BeuserTxBeuser');
$this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
$this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
$this->view->assign('backendUsers', $this->backendUserRepository->findDemanded($demand));
$this->view->assign('backendUserGroups', array_merge(array(''), $this->backendUserGroupRepository->findAll()->toArray()));
$this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
}
/**
* Views all currently logged in BackendUsers and their sessions
*
* @return void
*/
public function onlineAction() {
$onlineUsersAndSessions = array();
$onlineUsers = $this->backendUserRepository->findOnline();
foreach ($onlineUsers as $onlineUser) {
$onlineUsersAndSessions[] = array(
'backendUser' => $onlineUser,
'sessions' => $this->backendUserSessionRepository->findByBackendUser($onlineUser)
);
}
$this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
$this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
$this->view->assign('onlineUsersAndSessions', $onlineUsersAndSessions);
$this->view->assign('currentSessionId', $GLOBALS['BE_USER']->user['ses_id']);
}
/**
* Compare backend users from demand
*
* @return void
*/
public function compareAction() {
$compareUserList = $this->moduleData->getCompareUserList();
$this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
$this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
$this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
}
/**
* Attaches one backend user to the compare list
*
* @param integer $uid
* @retun void
*/
public function addToCompareListAction($uid) {
$this->moduleData->attachUidCompareUser($uid);
$this->forward('index');
}
/**
* Removes given backend user to the compare list
*
* @param integer $uid
* @retun void
*/
public function removeFromCompareListAction($uid) {
$this->moduleData->detachUidCompareUser($uid);
$this->forward('index');
}
/**
* Terminate BackendUser session and logout corresponding client
* Redirects to onlineAction with message
*
* @param Tx_Beuser_Domain_Model_BackendUser $backendUser
* @param string $sessionId
* @return void
*/
protected function terminateBackendUserSessionAction(Tx_Beuser_Domain_Model_BackendUser $backendUser, $sessionId) {
$GLOBALS['TYPO3_DB']->exec_DELETEquery(
'be_sessions',
'ses_userid = "' . $backendUser->getUid() . '"' .
' AND ses_id = "' . $sessionId . '"' .
' LIMIT 1'
);
if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
$message = 'Session successfully terminated.';
$this->flashMessageContainer->add($message, '', t3lib_FlashMessage::OK);
}
$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 array $switchUser BE-user record that will be switched to
* @param boolean $switchBack
* @return void
*/
protected function switchUser($switchUser, $switchBack = FALSE) {
$targetUser = t3lib_BEfunc::getRecord('be_users', $switchUser);
if (is_array($targetUser) && $GLOBALS['BE_USER']->isAdmin()) {
$updateData['ses_userid'] = $targetUser['uid'];
// User switchback or replace current session?
if ($switchBack) {
$updateData['ses_backuserid'] = intval($GLOBALS['BE_USER']->user['uid']);
}
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_sessions', 'ses_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') . ' AND ses_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(t3lib_beUserAuth::getCookieName(), 'be_sessions') . ' AND ses_userid=' . intval($GLOBALS['BE_USER']->user['uid']), $updateData);
$redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
t3lib_utility_Http::redirect($redirectUrl);
}
}
}
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Felix Kopp <felix-source@phorax.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Model for backend user
*
* @author Felix Kopp <felix-source@phorax.com>
* @package TYPO3
* @subpackage beuser
*/
class Tx_Beuser_Domain_Model_BackendUser extends Tx_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 $fileMountPoints = '';
/**
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Beuser_Domain_Model_BackendUserGroup>
*/
protected $backendUserGroups;
/**
* @param string $allowedLanguages
* @return void
*/
public function setAllowedLanguages($allowedLanguages) {
$this->allowedLanguages= $allowedLanguages;
}
/**
* @return string
*/
public function getAllowedLanguages() {
return $this->allowedLanguages;
}
/**
* @param string
* @return void
*/
public function setDbMountPoints($dbMountPoints) {
$this->dbMountPoints = $dbMountPoints;
}
/**
* @return string
*/
public function getDbMountPoints() {
return $this->dbMountPoints;
}
/**
* @param string $fileMountPoints
* @return void
*/
public function setFileMountPoints($fileMountPoints) {
$this->fileMountPoints = $fileMountPoints;
}
/**
* @return string
*/
public function getFileMountPoints() {
return $this->fileMountPoints;
}
/**
* Check if user is active, not disabled
*
* @return boolean
*/
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 \Tx_Extbase_Persistence_ObjectStorage $backendUserGroups
*/
public function setBackendUserGroups($backendUserGroups) {
$this->backendUserGroups = $backendUserGroups;
}
/**
* @return \Tx_Extbase_Persistence_ObjectStorage
*/
public function getBackendUserGroups() {
return $this->backendUserGroups;
}
}
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Felix Kopp <felix-source@phorax.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Model for backend user group
*
* @author Felix Kopp <felix-source@phorax.com>
* @package TYPO3
* @subpackage beuser
*/
class Tx_Beuser_Domain_Model_BackendUserGroup extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* @var string
*/
protected $title;
/**
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Beuser_Domain_Model_BackendUserGroup>
* @lazy
*/
protected $subGroups;
/**
* @param string $title
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param \Tx_Extbase_Persistence_ObjectStorage $subGroups
*/
public function setSubGroups($subGroups) {
$this->subGroups = $subGroups;
}
/**
* @return \Tx_Extbase_Persistence_ObjectStorage
*/
public function getSubGroups() {
return $this->subGroups;
}
}
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Felix Kopp <felix-source@phorax.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Demand filter for listings
*
* @author Felix Kopp <felix-source@phorax.com>
* @package TYPO3
* @subpackage beuser
*/
class Tx_Beuser_Domain_Model_Demand extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* @var integer
*/
const ALL = 0;
/**
* @var integer
*/
const USERTYPE_ADMINONLY = 1;
/**
* @var integer
*/
const USERTYPE_USERONLY = 2;
/**
* @var integer
*/
const STATUS_ACTIVE = 1;
/**
* @var integer
*/
const STATUS_INACTIVE = 2;
/**
* @var integer
*/
const LOGIN_SOME = 1;
/**
* @var integer
*/
const LOGIN_NONE = 2;
/**
* @var string
*/
protected $userName = '';
/**
* @var integer
*/
protected $userType = self::ALL;
/**
* @var integer
*/
protected $status = self::ALL;
/**
* @var integer
*/
protected $logins = 0;
/**
* @var Tx_Beuser_Domain_Model_BackendUserGroup
*/
protected $backendUserGroup;
/**
* @param string $userName
* @return void
*/
public function setUserName($userName) {
$this->userName = $userName;
}
/**
* @return string
*/
public function getUserName() {
return $this->userName;
}
/**
* @param integer $userType
* @return void
*/
public function setUserType($userType) {
$this->userType = $userType;
}
/**
* @return integer
*/
public function getUserType() {
return $this->userType;
}
/**
* @param integer $status
* @return void
*/
public function setStatus($status) {
$this->status = $status;
}
/**
* @return integer
*/
public function getStatus() {
return $this->status;
}
/**
* @param integer $logins
* @return void
*/
public function setLogins($logins) {
$this->logins = $logins;
}
/**
* @return integer
*/
public function getLogins() {
return $this->logins;
}
/**
* @param \Tx_Beuser_Domain_Model_BackendUserGroup $backendUserGroup
*/
public function setBackendUserGroup($backendUserGroup) {
$this->backendUserGroup = $backendUserGroup;
}
/**
* @return \Tx_Beuser_Domain_Model_BackendUserGroup
*/