From 5484b0819522cfcb62febc386523be2a8591d45a Mon Sep 17 00:00:00 2001 From: Simon Krull Date: Mon, 13 Nov 2023 21:02:10 +0100 Subject: [PATCH] FEATURE: add more details to user list and user show command --- .../Classes/Command/UserCommandController.php | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Neos.Neos/Classes/Command/UserCommandController.php b/Neos.Neos/Classes/Command/UserCommandController.php index 36866f646f8..95cbe9cf08e 100644 --- a/Neos.Neos/Classes/Command/UserCommandController.php +++ b/Neos.Neos/Classes/Command/UserCommandController.php @@ -19,6 +19,7 @@ use Neos\Flow\Security\Account; use Neos\Flow\Security\Exception\NoSuchRoleException; use Neos\Flow\Security\Policy\Role; +use Neos\Party\Domain\Model\ElectronicAddress; use Neos\Utility\Arrays; use Neos\Neos\Domain\Model\User; use Neos\Neos\Domain\Service\UserService; @@ -55,7 +56,7 @@ public function listCommand() $users = $this->userService->getUsers(); $tableRows = []; - $headerRow = ['Name', 'Email', 'Account(s)', 'Role(s)', 'Active']; + $headerRow = ['Name', 'Primary Electronic Address', 'Account(s)', 'Role(s)', 'Active', 'Created at', 'Expires at']; foreach ($users as $user) { $tableRows[] = $this->getTableRowForUser($user); @@ -83,15 +84,38 @@ public function showCommand($username, $authenticationProvider = null) { $user = $this->userService->getUser($username, $authenticationProvider); if (!$user instanceof User) { - $this->outputLine('The username "%s" is not in use', [$username]); + $this->outputLine('The username "%s" does not exist', [$username]); $this->quit(1); } - /** @var User $user */ - - $headerRow = ['Name', 'Email', 'Account(s)', 'Role(s)', 'Active']; - $tableRows = [$this->getTableRowForUser($user)]; - $this->output->outputTable($tableRows, $headerRow); + $this->outputLine('First name: %s', [$user->getName()->getFirstName()]); + $this->outputLine('Last name: %s', [$user->getName()->getLastName()]); + $this->outputLine('Backend Language: %s', [$user->getPreferences()->getInterfaceLanguage() ?? 'Use system default']); + + $this->outputLine(); + $this->outputLine('Electronic address(es):'); + $this->output->outputTable( + array_map(static fn (ElectronicAddress $electronicAddress) => [ + $electronicAddress->getType(), + $electronicAddress->getIdentifier(), + $electronicAddress->getUsage(), + $electronicAddress === $user->getPrimaryElectronicAddress() ? 'yes' : 'no', + ], $user->getElectronicAddresses()->toArray()), + ['Type', 'Identifier', 'Usage', 'Primary?'], + ); + $this->outputLine(); + $this->outputLine('Account:'); + $this->output->outputTable( + array_map(static fn (Account $account) => [ + $account->getAccountIdentifier(), + implode(', ', $account->getRoles()), + $account->getAuthenticationProviderName(), + $account->isActive() ? 'yes' : 'no', + $account->getCreationDate()->format('Y-m-d'), + $account->getExpirationDate() !== null ? $account->getExpirationDate()->format('Y-m-d') : 'never', + ], $user->getAccounts()->toArray()), + ['Identifier', 'Role', 'Provider', 'Active', 'Created at', 'Expires at'], + ); } /** @@ -444,10 +468,12 @@ protected function getTableRowForUser(User $user) } return [ $user->getName()->getFullName(), - $user->getPrimaryElectronicAddress(), + $user->getPrimaryElectronicAddress() ?? 'No Primary Electronic Address set', implode(', ', $accountIdentifiers), implode(', ', $roleNames), - ($user->isActive() ? 'yes' : 'no') + ($user->isActive() ? 'yes' : 'no'), + $account->getCreationDate()->format('Y-m-d'), + $account->getExpirationDate() !== null ? $account->getExpirationDate()->format('Y-m-d') : 'never', ]; } }