Skip to content

Commit

Permalink
FEATURE: add more details to user list and user show command
Browse files Browse the repository at this point in the history
  • Loading branch information
crydotsnake committed Dec 2, 2023
1 parent 50b6540 commit 5484b08
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions Neos.Neos/Classes/Command/UserCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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('<b>First name:</b> %s', [$user->getName()->getFirstName()]);
$this->outputLine('<b>Last name:</b> %s', [$user->getName()->getLastName()]);
$this->outputLine('<b>Backend Language:</b> %s', [$user->getPreferences()->getInterfaceLanguage() ?? 'Use system default']);

$this->outputLine();
$this->outputLine('<b>Electronic address(es):</b>');
$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('<b>Account:</b>');
$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',

Check failure on line 115 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Else branch is unreachable because ternary operator condition is always true.
], $user->getAccounts()->toArray()),

Check failure on line 116 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Cannot call method toArray() on array<Neos\Flow\Security\Account>|(Doctrine\Common\Collections\Collection&iterable<Neos\Flow\Security\Account>).
['Identifier', 'Role', 'Provider', 'Active', 'Created at', 'Expires at'],
);
}

/**
Expand Down Expand Up @@ -444,10 +468,12 @@ protected function getTableRowForUser(User $user)
}
return [
$user->getName()->getFullName(),
$user->getPrimaryElectronicAddress(),
$user->getPrimaryElectronicAddress() ?? 'No Primary Electronic Address set',

Check failure on line 471 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Expression on left side of ?? is not nullable.
implode(', ', $accountIdentifiers),
implode(', ', $roleNames),
($user->isActive() ? 'yes' : 'no')
($user->isActive() ? 'yes' : 'no'),
$account->getCreationDate()->format('Y-m-d'),

Check failure on line 475 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Variable $account might not be defined.
$account->getExpirationDate() !== null ? $account->getExpirationDate()->format('Y-m-d') : 'never',

Check failure on line 476 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Else branch is unreachable because ternary operator condition is always true.

Check failure on line 476 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Variable $account might not be defined.

Check failure on line 476 in Neos.Neos/Classes/Command/UserCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Variable $account might not be defined.
];
}
}

0 comments on commit 5484b08

Please sign in to comment.