Release 2.10 (#4549)
This commit is contained in:
@@ -9,64 +9,10 @@
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
/**
|
||||
* Can be used to pre-fill form types with: UserRepository::getQueryBuilderForFormType()
|
||||
*/
|
||||
final class UserFormTypeQuery extends BaseFormTypeQuery
|
||||
{
|
||||
use VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private array $includeUsers = [];
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private array $ignoredUsers = [];
|
||||
|
||||
/**
|
||||
* Sets a list of users which must be included in the result always.
|
||||
*
|
||||
* @param array<User> $users
|
||||
*/
|
||||
public function setUsersAlwaysIncluded(array $users): void
|
||||
{
|
||||
$this->includeUsers = $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of users which should always be included in the result.
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function getUsersAlwaysIncluded(): array
|
||||
{
|
||||
return $this->includeUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given user will be excluded from the result set.
|
||||
*
|
||||
* @param User $user
|
||||
* @return $this
|
||||
*/
|
||||
public function addUserToIgnore(User $user): UserFormTypeQuery
|
||||
{
|
||||
$this->ignoredUsers[] = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of users that should not be loaded.
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function getUsersToIgnore(): array
|
||||
{
|
||||
return $this->ignoredUsers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class UserQuery extends BaseQuery implements VisibilityInterface
|
||||
{
|
||||
use VisibilityTrait;
|
||||
|
||||
public const USER_ORDER_ALLOWED = ['alias', 'user', 'username', 'title', 'email'];
|
||||
public const USER_ORDER_ALLOWED = ['username', 'alias', 'title', 'email', 'systemAccount'];
|
||||
|
||||
private ?string $role = null;
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ class UserQuery extends BaseQuery implements VisibilityInterface
|
||||
public function __construct()
|
||||
{
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'user',
|
||||
'orderBy' => 'username',
|
||||
'searchTeams' => [],
|
||||
'visibility' => VisibilityInterface::SHOW_VISIBLE,
|
||||
'systemAccount' => null,
|
||||
|
||||
@@ -180,35 +180,15 @@ class UserRepository extends EntityRepository implements UserLoaderInterface, Us
|
||||
{
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
|
||||
$or = $qb->expr()->orX();
|
||||
|
||||
if ($query->isShowVisible()) {
|
||||
$or->add($qb->expr()->eq('u.enabled', ':enabled'));
|
||||
$qb->andWhere($qb->expr()->eq('u.enabled', ':enabled'));
|
||||
$qb->setParameter('enabled', true, ParameterType::BOOLEAN);
|
||||
}
|
||||
|
||||
$includeAlways = $query->getUsersAlwaysIncluded();
|
||||
if (!empty($includeAlways)) {
|
||||
$or->add($qb->expr()->in('u', ':users'));
|
||||
$qb->setParameter('users', $includeAlways);
|
||||
}
|
||||
|
||||
if ($or->count() > 0) {
|
||||
$qb->andWhere($or);
|
||||
}
|
||||
|
||||
if (\count($query->getUsersToIgnore()) > 0) {
|
||||
$ids = array_map(function (User $user) {
|
||||
return $user->getId();
|
||||
}, $query->getUsersToIgnore());
|
||||
|
||||
$qb->andWhere($qb->expr()->notIn('u.id', $ids));
|
||||
}
|
||||
|
||||
$qb->andWhere($qb->expr()->eq('u.systemAccount', ':system'));
|
||||
$qb->setParameter('system', false, Types::BOOLEAN);
|
||||
|
||||
$qb->orderBy('u.username', 'ASC');
|
||||
$qb->addSelect("COALESCE(NULLIF(u.alias, ''), u.username) as HIDDEN userOrder");
|
||||
$qb->orderBy('userOrder', 'ASC');
|
||||
|
||||
$this->addPermissionCriteria($qb, $query->getUser(), $query->getTeams());
|
||||
|
||||
@@ -307,10 +287,6 @@ class UserRepository extends EntityRepository implements UserLoaderInterface, Us
|
||||
|
||||
foreach ($query->getOrderGroups() as $orderBy => $order) {
|
||||
switch ($orderBy) {
|
||||
case 'user':
|
||||
$qb->addSelect('COALESCE(u.alias, u.username) as HIDDEN userOrder');
|
||||
$orderBy = 'userOrder';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'u.' . $orderBy;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user