Merge pull request #3377 from alchemy-fr/PHRAS-2941-user-list-model-option

PHRAS-2941 #comment merge  4.1 bin/console user:list --models
This commit is contained in:
Nicolas Maillat
2020-02-26 19:15:10 +01:00
committed by GitHub
2 changed files with 28 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ class UserListCommand extends Command
{
parent::__construct('user:list');
$this->setDescription('List of all user')
$this->setDescription('List of all user (experimental)')
->addOption('user_id', null, InputOption::VALUE_OPTIONAL, ' The id of user export only info this user ')
->addOption('user_email', null, InputOption::VALUE_OPTIONAL, 'The mail of user export only info this user .')
->addOption('database_id', null, InputOption::VALUE_OPTIONAL, 'Id of database.')
@@ -42,6 +42,7 @@ class UserListCommand extends Command
->addOption('application', null, InputOption::VALUE_NONE, 'List application of user work only if --user_id is set')
->addOption('right', null, InputOption::VALUE_NONE, 'Show right information')
->addOption('adress', null, InputOption::VALUE_NONE, 'Show adress information')
->addOption('models', null, InputOption::VALUE_NONE, "Show only defined models, if --user_id is set with --models it's the template owner")
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
->setHelp('');
@@ -62,6 +63,7 @@ class UserListCommand extends Command
$created = $input->getOption('created');
$updated = $input->getOption('updated');
$withRight = $input->getOption('right');
$models = $input->getOption('models');
$jsonformat = $input->getOption('jsonformat');
$query = $this->container['phraseanet.user-query'];
@@ -70,18 +72,26 @@ class UserListCommand extends Command
if($collectionId) $query->on_sbas_ids([$collectionId]);
if($created) $this->addFilterDate($created,'created',$query);
if($updated) $this->addFilterDate($updated,'updated',$query);
if($userId) $query->addSqlFilter('Users.id = ?' ,[$userId]);
if($userEmail) $query->addSqlFilter('Users.email = ?' ,[$userEmail]);
if($lockStatus) $query->addSqlFilter('Users.mail_locked = 1');
if($guest) $query->include_invite(true)->addSqlFilter('Users.guest = 1');
if($userId && !$models) $query->addSqlFilter('Users.id = ?' ,[$userId]);
if($userEmail && !$models) $query->addSqlFilter('Users.email = ?' ,[$userEmail]);
if($lockStatus && !$models) $query->addSqlFilter('Users.mail_locked = 1');
if($guest && !$models) $query->include_invite(true)->addSqlFilter('Users.guest = 1');
if ($application and !$userId) {
$output->writeln('<error>You must provide --user_id when using --application option</error>');
return 0;
}
$users = $query
->execute()->get_results();
/** @var UserRepository $userRepository */
$userRepository = $this->container['repo.users'];
if ($models && $userId) {
$users = $userRepository->findBy(['templateOwner' => $userId]);
} elseif ($models) {
$users = $userRepository->findTemplate();
} else {
$users = $query->execute()->get_results();
}
$userList = [];
$showApplication = false;

View File

@@ -122,4 +122,15 @@ class UserRepository extends EntityRepository
{
return $this->findBy(['templateOwner' => $user->getId()]);
}
/**
* Finds all templates
*/
public function findTemplate()
{
$qb = $this->createQueryBuilder('u');
$qb->where('u.templateOwner is NOT NULL');
return $qb->getQuery()->getResult();
}
}