Info.php 2.8 KB

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