summaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-17 10:38:53 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-17 10:38:53 +0200
commit5d01850dce1b3b290631f88ecaa80e8791072971 (patch)
treedf060d150d981045b59cd620c3b9e89ddd4ab2dc /core/Command
parentbd5189f29fc5b4340298f98f2f7a49aa3a157131 (diff)
downloadnextcloud-server-5d01850dce1b3b290631f88ecaa80e8791072971.tar.gz
nextcloud-server-5d01850dce1b3b290631f88ecaa80e8791072971.zip
Add detailed users listing in occ user:info command
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/User/ListCommand.php43
1 files changed, 38 insertions, 5 deletions
diff --git a/core/Command/User/ListCommand.php b/core/Command/User/ListCommand.php
index 06ba1f0b858..4bc1ff14eb6 100644
--- a/core/Command/User/ListCommand.php
+++ b/core/Command/User/ListCommand.php
@@ -1,8 +1,10 @@
<?php
+
/**
* @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
*
* @author Robin Appelman <robin@icewind.nl>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -24,6 +26,7 @@
namespace OC\Core\Command\User;
use OC\Core\Command\Base;
+use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputInterface;
@@ -31,14 +34,21 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ListCommand extends Base {
+
/** @var IUserManager */
protected $userManager;
+ /** @var IGroupManager */
+ protected $groupManager;
+
/**
* @param IUserManager $userManager
+ * @param IGroupManager $groupManager
*/
- public function __construct(IUserManager $userManager) {
+ public function __construct(IUserManager $userManager,
+ IGroupManager $groupManager) {
$this->userManager = $userManager;
+ $this->groupManager = $groupManager;
parent::__construct();
}
@@ -64,23 +74,46 @@ class ListCommand extends Base {
InputOption::VALUE_OPTIONAL,
'Output format (plain, json or json_pretty, default is plain)',
$this->defaultOutputFormat
+ )->addOption(
+ 'info',
+ 'i',
+ InputOption::VALUE_NONE,
+ 'Show detailed info'
);
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset'));
- $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users));
+ $users = $this->userManager->search('', (int) $input->getOption('limit'), (int) $input->getOption('offset'));
+
+ $this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users, (bool)$input->getOption('info')));
}
/**
* @param IUser[] $users
+ * @param bool [$detailed=false]
* @return array
*/
- private function formatUsers(array $users) {
+ private function formatUsers(array $users, bool $detailed = false) {
$keys = array_map(function (IUser $user) {
return $user->getUID();
}, $users);
- $values = array_map(function (IUser $user) {
+
+ $values = array_map(function (IUser $user) use ($detailed) {
+ if ($detailed) {
+ $groups = $this->groupManager->getUserGroupIds($user);
+ return [
+ 'user_id' => $user->getUID(),
+ 'display_name' => $user->getDisplayName(),
+ 'email' => $user->getEMailAddress() ? $user->getEMailAddress() : '',
+ 'cloud_id' => $user->getCloudId(),
+ 'enabled' => $user->isEnabled(),
+ 'groups' => $groups,
+ 'quota' => $user->getQuota(),
+ 'last_seen' => date(\DateTime::ATOM, $user->getLastLogin()), // ISO-8601
+ 'user_directory' => $user->getHome(),
+ 'backend' => $user->getBackendClassName()
+ ];
+ }
return $user->getDisplayName();
}, $users);
return array_combine($keys, $values);