|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl> |
| 4 | + * |
| 5 | + * @license GNU AGPL version 3 or any later version |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as |
| 9 | + * published by the Free Software Foundation, either version 3 of the |
| 10 | + * License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +namespace OC\Core\Command\User; |
| 23 | + |
| 24 | +use OC\Core\Command\Base; |
| 25 | +use OCP\IGroupManager; |
| 26 | +use OCP\IUser; |
| 27 | +use OCP\IUserManager; |
| 28 | +use Symfony\Component\Console\Command\Command; |
| 29 | +use Symfony\Component\Console\Input\InputArgument; |
| 30 | +use Symfony\Component\Console\Input\InputInterface; |
| 31 | +use Symfony\Component\Console\Input\InputOption; |
| 32 | +use Symfony\Component\Console\Output\OutputInterface; |
| 33 | + |
| 34 | +class Info extends Base { |
| 35 | + /** @var IUserManager */ |
| 36 | + protected $userManager; |
| 37 | + /** @var IGroupManager */ |
| 38 | + protected $groupManager; |
| 39 | + |
| 40 | + /** |
| 41 | + * @param IUserManager $userManager |
| 42 | + * @param IGroupManager $groupManager |
| 43 | + */ |
| 44 | + public function __construct(IUserManager $userManager, IGroupManager $groupManager) { |
| 45 | + $this->userManager = $userManager; |
| 46 | + $this->groupManager = $groupManager; |
| 47 | + parent::__construct(); |
| 48 | + } |
| 49 | + |
| 50 | + protected function configure() { |
| 51 | + $this |
| 52 | + ->setName('user:info') |
| 53 | + ->setDescription('show user info') |
| 54 | + ->addArgument( |
| 55 | + 'user', |
| 56 | + InputArgument::REQUIRED, |
| 57 | + 'user to show' |
| 58 | + )->addOption( |
| 59 | + 'output', |
| 60 | + null, |
| 61 | + InputOption::VALUE_OPTIONAL, |
| 62 | + 'Output format (plain, json or json_pretty, default is plain)', |
| 63 | + $this->defaultOutputFormat |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + protected function execute(InputInterface $input, OutputInterface $output) { |
| 68 | + $user = $this->userManager->get($input->getArgument('user')); |
| 69 | + if (is_null($user)) { |
| 70 | + $output->writeln('<error>user not found</error>'); |
| 71 | + return 1; |
| 72 | + } |
| 73 | + $groups = $this->groupManager->getUserGroupIds($user); |
| 74 | + $data = [ |
| 75 | + 'user_id' => $user->getUID(), |
| 76 | + 'display_name' => $user->getDisplayName(), |
| 77 | + 'email' => ($user->getEMailAddress()) ? $user->getEMailAddress() : '', |
| 78 | + 'cloud_id' => $user->getCloudId(), |
| 79 | + 'enabled' => $user->isEnabled(), |
| 80 | + 'groups' => $groups, |
| 81 | + 'quota' => $user->getQuota(), |
| 82 | + 'last_seen' => date(\DateTime::ATOM, $user->getLastLogin()), // ISO-8601 |
| 83 | + 'user_directory' => $user->getHome(), |
| 84 | + 'backend' => $user->getBackendClassName() |
| 85 | + ]; |
| 86 | + $this->writeArrayInOutputFormat($input, $output, $data); |
| 87 | + } |
| 88 | +} |
0 commit comments