Skip to content

Commit

Permalink
FEATURE: [AdminBundle] Sylius#15890 Introduce sylius:admin-user:list …
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
crydotsnake committed Mar 4, 2024
1 parent e203a51 commit 3c7890d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Console\Command;

use Sylius\Component\Core\Model\AdminUser;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Attribute\AsCommand;
use Sylius\Component\Core\Model\AdminUserInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;

#[AsCommand(
name: 'sylius:admin-users:list',
description: 'List all admin users',
)]
final class ListAdminUsersCommand extends Command
{
protected SymfonyStyle $io;

/** @param UserRepositoryInterface<AdminUserInterface> $userRepositoryInterface */
public function __construct(
private readonly UserRepositoryInterface $userRepositoryInterface
) {
parent::__construct();
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io->title('List available admin users');

$adminUsers = $this->userRepositoryInterface->findAll();
/** @var AdminUser $adminUser */
foreach ($adminUsers as $adminUser) {
$this->io->table(
[
'ID', 'E-Mail', 'Username', 'First name', 'Last name', 'Locale code', 'Enabled',
],
[
[
$adminUser->getId(),
$adminUser->getEmail(),
$adminUser->getUsername(),
$adminUser->getFirstname() ?? 'No Firstname Set',
$adminUser->getLastName() ?? 'No Lastname Set',
$adminUser->getLocaleCode(),
$adminUser->isEnabled() ? 'Enabled' : 'Disabled',
],
],
);
}
return Command::SUCCESS;
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/AdminBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<tag name="console.command" />
</service>

<service id="Sylius\Bundle\AdminBundle\Console\Command\ListAdminUsersCommand">
<argument type="service" id="sylius.repository.admin_user" />
<tag name="console.command" />
</service>

<service id="Sylius\Bundle\AdminBundle\MessageHandler\CreateAdminUserHandler">
<argument type="service" id="sylius.repository.admin_user" />
<argument type="service" id="sylius.factory.admin_user" />
Expand Down

0 comments on commit 3c7890d

Please sign in to comment.