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:
Kevin Papst
2020-07-26 13:13:06 +02:00
committed by GitHub
parent ecea92942c
commit 130e6ac057
9 changed files with 99 additions and 15 deletions

View File

@@ -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[]
*/

View File

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

View File

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