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

@@ -23,6 +23,9 @@ class TeamEditForm extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Team|null $team */
$team = $options['data'] ?? null;
$builder
->add('name', TextType::class, [
'label' => 'label.name',
@@ -55,6 +58,8 @@ class TeamEditForm extends AbstractType
'title' => 'Team member',
'description' => 'Array of team member IDs',
],
// make sure that disabled users show up in the result list
'include_users' => (null !== $team && $team->getUsers()->count() > 0 ? $team->getUsers()->toArray() : [])
])
;
}

View File

@@ -11,6 +11,7 @@ namespace App\Form\Type;
use App\Entity\User;
use App\Repository\Query\UserFormTypeQuery;
use App\Repository\Query\VisibilityInterface;
use App\Repository\UserRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
@@ -34,6 +35,13 @@ class UserType extends AbstractType
return $user->getDisplayName();
},
'choice_translation_domain' => false,
// whether disabled users should be included in the result list
'include_disabled' => false,
// an array of users, which will always be included in the result list
// why? if the base entity could include disabled users, which should not be hidden in/removed from the list
// eg. when editing a team that has disabled users, these users would be removed silently
// see https://github.com/kevinpapst/kimai2/pull/1841
'include_users' => [],
'documentation' => [
'type' => 'integer',
'description' => 'User ID',
@@ -45,6 +53,14 @@ class UserType extends AbstractType
$query = new UserFormTypeQuery();
$query->setUser($options['user']);
if ($options['include_disabled'] === true) {
$query->setVisibility(VisibilityInterface::SHOW_BOTH);
}
if (!empty($options['include_users'])) {
$query->setUsersAlwaysIncluded($options['include_users']);
}
return $repo->getQueryBuilderForFormType($query);
};
});