TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Dto;
|
||||
|
||||
/**
|
||||
* @internal not part of the TYPO3 Core API.
|
||||
*/
|
||||
class BackendUserGroup
|
||||
{
|
||||
public function __construct(protected string $title = '') {}
|
||||
|
||||
public static function fromUc(array $uc): self
|
||||
{
|
||||
$demand = new self();
|
||||
$demand->title = (string)($uc['title'] ?? '');
|
||||
return $demand;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function forUc(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->title,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Backend\Authentication\PasswordReset;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Attribute as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
||||
/**
|
||||
* 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 AbstractEntity
|
||||
{
|
||||
#[Extbase\Validate(validator: 'NotEmpty')]
|
||||
protected string $userName = '';
|
||||
|
||||
/**
|
||||
* @var ObjectStorage<BackendUserGroup>
|
||||
*/
|
||||
protected ObjectStorage $backendUserGroups;
|
||||
|
||||
/**
|
||||
* Comma separated list of uids in multi-select
|
||||
* Might retrieve the labels from TCA/DataMapper
|
||||
*/
|
||||
protected string $allowedLanguages = '';
|
||||
|
||||
protected string $dbMountPoints = '';
|
||||
protected string $description = '';
|
||||
protected string $fileMountPoints = '';
|
||||
protected bool $isAdministrator = false;
|
||||
protected bool $isDisabled = false;
|
||||
protected ?\DateTime $startDateAndTime = null;
|
||||
protected ?\DateTime $endDateAndTime = null;
|
||||
protected string $email = '';
|
||||
protected string $realName = '';
|
||||
protected ?\DateTime $lastLoginDateAndTime = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
public function initializeObject(): void
|
||||
{
|
||||
$this->backendUserGroups = new ObjectStorage();
|
||||
}
|
||||
|
||||
public function setAllowedLanguages(string $allowedLanguages): void
|
||||
{
|
||||
$this->allowedLanguages = $allowedLanguages;
|
||||
}
|
||||
|
||||
public function getAllowedLanguages(): string
|
||||
{
|
||||
return $this->allowedLanguages;
|
||||
}
|
||||
|
||||
public function setDbMountPoints(string $dbMountPoints): void
|
||||
{
|
||||
$this->dbMountPoints = $dbMountPoints;
|
||||
}
|
||||
|
||||
public function getDbMountPoints(): string
|
||||
{
|
||||
return $this->dbMountPoints;
|
||||
}
|
||||
|
||||
public function setFileMountPoints(string $fileMountPoints): void
|
||||
{
|
||||
$this->fileMountPoints = $fileMountPoints;
|
||||
}
|
||||
|
||||
public function getFileMountPoints(): string
|
||||
{
|
||||
return $this->fileMountPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is active, not disabled
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
if ($this->getIsDisabled()) {
|
||||
return false;
|
||||
}
|
||||
$now = new \DateTime('now');
|
||||
return (!$this->getStartDateAndTime() && !$this->getEndDateAndTime()) || ($this->getStartDateAndTime() <= $now && (!$this->getEndDateAndTime() || $this->getEndDateAndTime() > $now));
|
||||
}
|
||||
|
||||
public function setBackendUserGroups(ObjectStorage $backendUserGroups): void
|
||||
{
|
||||
$this->backendUserGroups = $backendUserGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ObjectStorage<BackendUserGroup>
|
||||
*/
|
||||
public function getBackendUserGroups(): ObjectStorage
|
||||
{
|
||||
return $this->backendUserGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is currently logged in
|
||||
*/
|
||||
public function isCurrentlyLoggedIn(): bool
|
||||
{
|
||||
return $this->getUid() === (int)($this->getBackendUser()->user['uid'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is allowed to trigger a password reset
|
||||
*
|
||||
* Requirements:
|
||||
* 1. The user for which the password reset should be triggered is not the currently logged in user
|
||||
* 2. Password reset is enabled for the user (Email+Password are set)
|
||||
* 3. The currently logged in user is allowed to reset passwords in the backend (Enabled in user TSconfig)
|
||||
*/
|
||||
public function isPasswordResetEnabled(): bool
|
||||
{
|
||||
return !$this->isCurrentlyLoggedIn()
|
||||
&& GeneralUtility::makeInstance(PasswordReset::class)->isEnabledForUser((int)$this->getUid())
|
||||
&& ($this->getBackendUser()->getTSConfig()['options.']['passwordReset'] ?? true);
|
||||
}
|
||||
|
||||
public function getUserName(): string
|
||||
{
|
||||
return $this->userName;
|
||||
}
|
||||
|
||||
public function setUserName(string $userName): void
|
||||
{
|
||||
$this->userName = $userName;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getIsAdministrator(): bool
|
||||
{
|
||||
return $this->isAdministrator;
|
||||
}
|
||||
|
||||
public function setIsAdministrator(bool $isAdministrator): void
|
||||
{
|
||||
$this->isAdministrator = $isAdministrator;
|
||||
}
|
||||
|
||||
public function getIsDisabled(): bool
|
||||
{
|
||||
return $this->isDisabled;
|
||||
}
|
||||
|
||||
public function setIsDisabled(bool $isDisabled): void
|
||||
{
|
||||
$this->isDisabled = $isDisabled;
|
||||
}
|
||||
|
||||
public function getStartDateAndTime(): ?\DateTime
|
||||
{
|
||||
return $this->startDateAndTime;
|
||||
}
|
||||
|
||||
public function setStartDateAndTime(?\DateTime $dateAndTime = null): void
|
||||
{
|
||||
$this->startDateAndTime = $dateAndTime;
|
||||
}
|
||||
|
||||
public function getEndDateAndTime(): ?\DateTime
|
||||
{
|
||||
return $this->endDateAndTime;
|
||||
}
|
||||
|
||||
public function setEndDateAndTime(?\DateTime $dateAndTime = null): void
|
||||
{
|
||||
$this->endDateAndTime = $dateAndTime;
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function getRealName(): string
|
||||
{
|
||||
return $this->realName;
|
||||
}
|
||||
|
||||
public function setRealName(string $name): void
|
||||
{
|
||||
$this->realName = $name;
|
||||
}
|
||||
|
||||
public function getLastLoginDateAndTime(): ?\DateTime
|
||||
{
|
||||
return $this->lastLoginDateAndTime;
|
||||
}
|
||||
|
||||
public function setLastLoginDateAndTime(?\DateTime $dateAndTime = null): void
|
||||
{
|
||||
$this->lastLoginDateAndTime = $dateAndTime;
|
||||
}
|
||||
|
||||
public function getBackendUser(): BackendUserAuthentication
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Extbase\Attribute as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
||||
/**
|
||||
* 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 AbstractEntity
|
||||
{
|
||||
protected string $title = '';
|
||||
protected string $description = '';
|
||||
protected bool $hidden = false;
|
||||
|
||||
/**
|
||||
* @var ObjectStorage<BackendUserGroup>
|
||||
*/
|
||||
#[Extbase\ORM\Lazy]
|
||||
protected ObjectStorage $subGroups;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initializeObject();
|
||||
}
|
||||
|
||||
public function initializeObject(): void
|
||||
{
|
||||
$this->subGroups = new ObjectStorage();
|
||||
}
|
||||
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function setHidden(bool $hidden): void
|
||||
{
|
||||
$this->hidden = $hidden;
|
||||
}
|
||||
|
||||
public function getHidden(): bool
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
public function setSubGroups(ObjectStorage $subGroups): void
|
||||
{
|
||||
$this->subGroups = $subGroups;
|
||||
}
|
||||
|
||||
public function getSubGroups(): ObjectStorage
|
||||
{
|
||||
return $this->subGroups;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
/**
|
||||
* Demand filter for listings
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class Demand
|
||||
{
|
||||
public const ALL = 0;
|
||||
|
||||
public const USERTYPE_ADMINONLY = 1;
|
||||
public const USERTYPE_USERONLY = 2;
|
||||
|
||||
public const STATUS_ACTIVE = 1;
|
||||
public const STATUS_INACTIVE = 2;
|
||||
|
||||
public const LOGIN_SOME = 1;
|
||||
public const LOGIN_NONE = 2;
|
||||
public const LOGIN_CURRENT = 3;
|
||||
|
||||
protected string $userName = '';
|
||||
protected int $userType = self::ALL;
|
||||
protected int $status = self::ALL;
|
||||
protected int $logins = 0;
|
||||
protected int $backendUserGroup = 0;
|
||||
|
||||
public static function fromUc(array $uc): self
|
||||
{
|
||||
$demand = new self();
|
||||
$demand->userName = (string)($uc['userName'] ?? '');
|
||||
$demand->userType = (int)($uc['userType'] ?? 0);
|
||||
$demand->status = (int)($uc['status'] ?? 0);
|
||||
$demand->logins = (int)($uc['logins'] ?? 0);
|
||||
$demand->backendUserGroup = (int)($uc['backendUserGroup'] ?? 0);
|
||||
return $demand;
|
||||
}
|
||||
|
||||
public function forUc(): array
|
||||
{
|
||||
return [
|
||||
'userName' => $this->getUserName(),
|
||||
'userType' => $this->getUserType(),
|
||||
'status' => $this->getStatus(),
|
||||
'logins' => $this->getLogins(),
|
||||
'backendUserGroup' => $this->getBackendUserGroup(),
|
||||
];
|
||||
}
|
||||
|
||||
public function setUserName(string $userName): void
|
||||
{
|
||||
$this->userName = $userName;
|
||||
}
|
||||
|
||||
public function getUserName(): string
|
||||
{
|
||||
return $this->userName;
|
||||
}
|
||||
|
||||
public function setUserType(int $userType): void
|
||||
{
|
||||
$this->userType = $userType;
|
||||
}
|
||||
|
||||
public function getUserType(): int
|
||||
{
|
||||
return $this->userType;
|
||||
}
|
||||
|
||||
public function setStatus(int $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setLogins(int $logins): void
|
||||
{
|
||||
$this->logins = $logins;
|
||||
}
|
||||
|
||||
public function getLogins(): int
|
||||
{
|
||||
return $this->logins;
|
||||
}
|
||||
|
||||
public function setBackendUserGroup(int $backendUserGroup): void
|
||||
{
|
||||
$this->backendUserGroup = $backendUserGroup;
|
||||
}
|
||||
|
||||
public function getBackendUserGroup(): int
|
||||
{
|
||||
return $this->backendUserGroup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Model;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\ResourceStorage;
|
||||
use TYPO3\CMS\Core\Resource\StorageRepository;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Attribute as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
|
||||
/**
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class FileMount extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* Title of the file mount.
|
||||
*/
|
||||
#[Extbase\Validate(validator: 'NotEmpty')]
|
||||
protected string $title = '';
|
||||
|
||||
/**
|
||||
* Description of the file mount.
|
||||
*/
|
||||
protected string $description = '';
|
||||
|
||||
/**
|
||||
* Identifier of the file mount
|
||||
*/
|
||||
protected string $identifier = '';
|
||||
|
||||
/**
|
||||
* Status of the file mount
|
||||
*/
|
||||
protected bool $hidden = false;
|
||||
|
||||
/**
|
||||
* Determines whether this file mount should be read only.
|
||||
*/
|
||||
protected bool $readOnly = false;
|
||||
|
||||
/**
|
||||
* Getter for the title of the file mount.
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the title of the file mount.
|
||||
*/
|
||||
public function setTitle(string $value): void
|
||||
{
|
||||
$this->title = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the description of the file mount.
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the description of the file mount.
|
||||
*/
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the readOnly property of the file mount.
|
||||
*/
|
||||
public function setReadOnly(bool $readOnly): void
|
||||
{
|
||||
$this->readOnly = $readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the readOnly property of the file mount.
|
||||
*/
|
||||
public function isReadOnly(): bool
|
||||
{
|
||||
return $this->readOnly;
|
||||
}
|
||||
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
public function setIdentifier(string $identifier): void
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
|
||||
public function isHidden(): bool
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
public function setHidden(bool $hidden): void
|
||||
{
|
||||
$this->hidden = $hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the path segment of the file mount (without the storage id)
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return explode(':/', $this->identifier)[1] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo This should be part of the ORM not the model class
|
||||
*/
|
||||
public function getStorage(): ?ResourceStorage
|
||||
{
|
||||
return GeneralUtility::makeInstance(StorageRepository::class)->findByCombinedIdentifier($this->identifier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Dto\BackendUserGroup;
|
||||
use TYPO3\CMS\Beuser\Event\AfterBackendGroupListConstraintsAssembledFromDemandEvent;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\MathUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @extends Repository<\TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup>
|
||||
*/
|
||||
class BackendUserGroupRepository extends Repository
|
||||
{
|
||||
public const TABLE_NAME = 'be_groups';
|
||||
|
||||
protected $defaultOrderings = [
|
||||
'title' => QueryInterface::ORDER_ASCENDING,
|
||||
];
|
||||
|
||||
/**
|
||||
* Overwrite createQuery to don't respect enable fields
|
||||
*/
|
||||
public function createQuery(): QueryInterface
|
||||
{
|
||||
$query = parent::createQuery();
|
||||
$query->getQuerySettings()->setIgnoreEnableFields(true);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get QueryBuilder without restrictions for table be_groups
|
||||
*/
|
||||
public function getQueryBuilder(bool $removeRestrictions = true): QueryBuilder
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
|
||||
if ($removeRestrictions === true) {
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
}
|
||||
|
||||
return $queryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Backend Usergroups on a given list of uids
|
||||
*/
|
||||
public function findByUidList(array $uidList): array
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
// being explicit here, albeit `Typo3DbQueryParser::parseDynamicOperand` uses prepared parameters
|
||||
$uidList = array_map(intval(...), $uidList);
|
||||
$query->matching($query->in('uid', $uidList));
|
||||
return $query->execute(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preforms a query on be_groups, matching the field title with like
|
||||
* @throws InvalidQueryException
|
||||
*/
|
||||
public function findByFilter(BackendUserGroup $backendUserGroupDto): QueryResult
|
||||
{
|
||||
$constraints = [];
|
||||
$query = $this->createQuery();
|
||||
$query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
|
||||
if ($backendUserGroupDto->getTitle() !== '') {
|
||||
$searchConstraints = [];
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
|
||||
$searchConstraints[] = $query->like(
|
||||
'title',
|
||||
'%' . $queryBuilder->escapeLikeWildcards($backendUserGroupDto->getTitle()) . '%'
|
||||
);
|
||||
|
||||
if (MathUtility::canBeInterpretedAsInteger($backendUserGroupDto->getTitle())) {
|
||||
$searchConstraints[] = $query->equals('uid', (int)$backendUserGroupDto->getTitle());
|
||||
}
|
||||
|
||||
if (count($searchConstraints) >= 2) {
|
||||
$constraints[] = $query->logicalOr(...$searchConstraints);
|
||||
} else {
|
||||
$constraints = $searchConstraints;
|
||||
}
|
||||
}
|
||||
$constraints = $this->eventDispatcher->dispatch(
|
||||
new AfterBackendGroupListConstraintsAssembledFromDemandEvent(
|
||||
$backendUserGroupDto,
|
||||
$query,
|
||||
$constraints
|
||||
)
|
||||
)->constraints;
|
||||
$query->matching($query->logicalAnd(...$constraints));
|
||||
/** @var QueryResult $result */
|
||||
$result = $query->execute();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Beuser\Domain\Model\Demand;
|
||||
use TYPO3\CMS\Beuser\Event\AfterBackendUserListConstraintsAssembledFromDemandEvent;
|
||||
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\Persistence\Generic\QueryResult;
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @extends Repository<BackendUser>
|
||||
*/
|
||||
class BackendUserRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Finds Backend Users on a given list of uids
|
||||
*/
|
||||
public function findByUidList(array $uidList): QueryResult
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
$query->matching($query->in('uid', array_map(intval(...), $uidList)));
|
||||
/** @var QueryResult $result */
|
||||
$result = $query->execute();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Backend Users matching to Demand object properties
|
||||
*/
|
||||
public function findDemanded(Demand $demand): QueryResult
|
||||
{
|
||||
$constraints = [];
|
||||
$query = $this->createQuery();
|
||||
$query->setOrderings(['userName' => QueryInterface::ORDER_ASCENDING]);
|
||||
// Username
|
||||
if ($demand->getUserName() !== '') {
|
||||
$searchConstraints = [];
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
|
||||
foreach (['userName', 'realName'] as $field) {
|
||||
$searchConstraints[] = $query->like(
|
||||
$field,
|
||||
'%' . $queryBuilder->escapeLikeWildcards($demand->getUserName()) . '%'
|
||||
);
|
||||
}
|
||||
if (MathUtility::canBeInterpretedAsInteger($demand->getUserName())) {
|
||||
$searchConstraints[] = $query->equals('uid', (int)$demand->getUserName());
|
||||
}
|
||||
if (count($searchConstraints) === 1) {
|
||||
$constraints[] = reset($searchConstraints);
|
||||
} else {
|
||||
$constraints[] = $query->logicalOr(...$searchConstraints);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($demand->getUserType()) {
|
||||
case Demand::USERTYPE_ADMINONLY:
|
||||
// Only display admin users
|
||||
$constraints[] = $query->equals('admin', 1);
|
||||
break;
|
||||
case Demand::USERTYPE_USERONLY:
|
||||
// Only display non-admin users
|
||||
$constraints[] = $query->equals('admin', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($demand->getStatus()) {
|
||||
case Demand::STATUS_ACTIVE:
|
||||
// Only display active users
|
||||
$constraints[] = $query->equals('disable', 0);
|
||||
break;
|
||||
case Demand::STATUS_INACTIVE:
|
||||
// Only display in-active users
|
||||
$constraints[] = $query->equals('disable', 1);
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($demand->getLogins()) {
|
||||
case Demand::LOGIN_NONE:
|
||||
// Not logged in before
|
||||
$constraints[] = $query->equals('lastlogin', 0);
|
||||
break;
|
||||
case Demand::LOGIN_SOME:
|
||||
// At least one login
|
||||
$constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
|
||||
break;
|
||||
|
||||
case Demand::LOGIN_CURRENT:
|
||||
// Currently logged-in users
|
||||
$sessionTimeout = (int)($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] ?? 28800);
|
||||
$constraints[] = $query->greaterThanOrEqual('lastlogin', time() - $sessionTimeout);
|
||||
}
|
||||
|
||||
// In backend user group
|
||||
if ($demand->getBackendUserGroup()) {
|
||||
$constraints[] = $query->logicalOr(
|
||||
$query->equals('usergroup', $demand->getBackendUserGroup()),
|
||||
$query->like('usergroup', $demand->getBackendUserGroup() . ',%'),
|
||||
$query->like('usergroup', '%,' . $demand->getBackendUserGroup()),
|
||||
$query->like('usergroup', '%,' . $demand->getBackendUserGroup() . ',%'),
|
||||
);
|
||||
}
|
||||
$constraints = $this->eventDispatcher->dispatch(
|
||||
new AfterBackendUserListConstraintsAssembledFromDemandEvent(
|
||||
$demand,
|
||||
$query,
|
||||
$constraints
|
||||
)
|
||||
)->constraints;
|
||||
$query->matching($query->logicalAnd(...$constraints));
|
||||
|
||||
/** @var QueryResult $result */
|
||||
$result = $query->execute();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Backend Users currently online
|
||||
*/
|
||||
public function findOnline(): QueryResult
|
||||
{
|
||||
$uids = [];
|
||||
foreach ($this->getSessionBackend()->getAll() as $sessionRecord) {
|
||||
if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) {
|
||||
$uids[] = $sessionRecord['ses_userid'];
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->createQuery();
|
||||
$query->matching($query->in('uid', $uids));
|
||||
/** @var QueryResult $result */
|
||||
$result = $query->execute();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite createQuery to don't respect enable fields
|
||||
*/
|
||||
public function createQuery(): QueryInterface
|
||||
{
|
||||
$query = parent::createQuery();
|
||||
$query->getQuerySettings()->setIgnoreEnableFields(true);
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getSessionBackend(): SessionBackendInterface
|
||||
{
|
||||
return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class BackendUserSessionRepository
|
||||
{
|
||||
protected SessionBackendInterface $sessionBackend;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sessionBackend = GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all active sessions for all backend users
|
||||
*/
|
||||
public function findAllActive(): array
|
||||
{
|
||||
$allSessions = $this->sessionBackend->getAll();
|
||||
|
||||
// Map array to correct keys
|
||||
$allSessions = array_map(
|
||||
static function (array $session): array {
|
||||
return [
|
||||
'id' => $session['ses_id'], // this is the hashed sessionId
|
||||
'ip' => $session['ses_iplock'],
|
||||
'timestamp' => $session['ses_tstamp'],
|
||||
'ses_userid' => $session['ses_userid'],
|
||||
];
|
||||
},
|
||||
$allSessions
|
||||
);
|
||||
|
||||
// Sort by timestamp
|
||||
usort($allSessions, static function ($session1, $session2) {
|
||||
return $session1['timestamp'] <=> $session2['timestamp'];
|
||||
});
|
||||
|
||||
return $allSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Sessions for specific BackendUser
|
||||
*/
|
||||
public function findByBackendUser(BackendUser $backendUser): array
|
||||
{
|
||||
$allActive = $this->findAllActive();
|
||||
|
||||
return array_filter(
|
||||
$allActive,
|
||||
static function (array $session) use ($backendUser): bool {
|
||||
return (int)$session['ses_userid'] === $backendUser->getUid();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function getPersistedSessionIdentifier(AbstractUserAuthentication $userObject): string
|
||||
{
|
||||
$currentSessionId = $userObject->getSession()->getIdentifier();
|
||||
if ($this->sessionBackend instanceof HashableSessionBackendInterface) {
|
||||
$currentSessionId = $this->sessionBackend->hash($currentSessionId);
|
||||
}
|
||||
return $currentSessionId;
|
||||
}
|
||||
|
||||
public function terminateSessionByIdentifier(string $sessionIdentifier): bool
|
||||
{
|
||||
return $this->sessionBackend->remove($sessionIdentifier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Beuser\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\FileMount;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* Repository for \TYPO3\CMS\Extbase\Domain\Model\FileMount.
|
||||
* @extends Repository<FileMount>
|
||||
*/
|
||||
class FileMountRepository extends Repository
|
||||
{
|
||||
public function initializeObject(): void
|
||||
{
|
||||
/** @var Typo3QuerySettings $querySettings */
|
||||
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
|
||||
$querySettings->setRespectStoragePage(false);
|
||||
$querySettings->setIgnoreEnableFields(true);
|
||||
$this->setDefaultQuerySettings($querySettings);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user