first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -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');
}
}