mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-15 09:57:41 +01:00
Add list user command
This commit is contained in:
parent
882da5c5eb
commit
af31cfed76
43
src/Wallabag/CoreBundle/Command/ListUserCommand.php
Normal file
43
src/Wallabag/CoreBundle/Command/ListUserCommand.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
class ListUserCommand extends ContainerAwareCommand
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('wallabag:user:list')
|
||||||
|
->setDescription('List all users')
|
||||||
|
->setHelp('This command list all existing users')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$users = $this->getContainer()->get('wallabag_user.user_repository')->findAll();
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$rows[] = [
|
||||||
|
$user->getUsername(),
|
||||||
|
$user->getEmail(),
|
||||||
|
$user->isEnabled() ? 'yes' : 'no',
|
||||||
|
$user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_ADMIN') ? 'yes' : 'no',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows);
|
||||||
|
|
||||||
|
$io->success(sprintf('%s user(s) displayed.', count($users)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
26
tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php
Normal file
26
tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
|
||||||
|
use Wallabag\CoreBundle\Command\ListUserCommand;
|
||||||
|
|
||||||
|
class ListUserCommandTest extends WallabagCoreTestCase
|
||||||
|
{
|
||||||
|
public function testRunListUserCommand()
|
||||||
|
{
|
||||||
|
$application = new Application($this->getClient()->getKernel());
|
||||||
|
$application->add(new ListUserCommand());
|
||||||
|
|
||||||
|
$command = $application->find('wallabag:user:list');
|
||||||
|
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->execute([
|
||||||
|
'command' => $command->getName(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertContains('3 user(s) displayed.', $tester->getDisplay());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user