handle hidden users in teams (#1841)
* allow to add disabled users to team * allow to include disabled users in user-select * include disabled users when editing team members ONLY if they are already part of team
This commit is contained in:
@@ -247,6 +247,17 @@ abstract class BaseFormTypeQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Team[] $teams
|
||||
* @return self
|
||||
*/
|
||||
public function setTeams(array $teams): self
|
||||
{
|
||||
$this->teams = $teams;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Team[]
|
||||
*/
|
||||
|
||||
@@ -9,9 +9,40 @@
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
/**
|
||||
* Can be used for pre-filling form types with the: UserRepository
|
||||
* Can be used to pre-fill form types with: UserRepository::getQueryBuilderForFormType()
|
||||
*/
|
||||
final class UserFormTypeQuery extends BaseFormTypeQuery
|
||||
{
|
||||
use VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private $includeUsers = [];
|
||||
|
||||
/**
|
||||
* Sets a list of users which must be included in the result always.
|
||||
*
|
||||
* @param array $users
|
||||
* @return UserFormTypeQuery
|
||||
*/
|
||||
public function setUsersAlwaysIncluded(array $users): UserFormTypeQuery
|
||||
{
|
||||
$this->includeUsers = $users;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of users which should always be included in the result.
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function getUsersAlwaysIncluded(): array
|
||||
{
|
||||
return $this->includeUsers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +141,22 @@ class UserRepository extends EntityRepository implements UserLoaderInterface
|
||||
{
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
|
||||
$qb->andWhere($qb->expr()->eq('u.enabled', ':enabled'));
|
||||
$qb->setParameter('enabled', true, \PDO::PARAM_BOOL);
|
||||
$or = $qb->expr()->orX();
|
||||
|
||||
if ($query->isShowVisible()) {
|
||||
$or->add($qb->expr()->eq('u.enabled', ':enabled'));
|
||||
$qb->setParameter('enabled', true, \PDO::PARAM_BOOL);
|
||||
}
|
||||
|
||||
$includeAlways = $query->getUsersAlwaysIncluded();
|
||||
if (!empty($includeAlways)) {
|
||||
$or->add($qb->expr()->in('u', ':users'));
|
||||
$qb->setParameter('users', $includeAlways);
|
||||
}
|
||||
|
||||
if ($or->count() > 0) {
|
||||
$qb->andWhere($or);
|
||||
}
|
||||
|
||||
$qb->orderBy('u.username', 'ASC');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user