UserController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  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, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Core\Controller;
  26. use OCP\AppFramework\Controller;
  27. use OCP\AppFramework\Http\JSONResponse;
  28. use OCP\IRequest;
  29. use OCP\IUserManager;
  30. class UserController extends Controller {
  31. public function __construct(
  32. string $appName,
  33. IRequest $request,
  34. protected IUserManager $userManager,
  35. ) {
  36. parent::__construct($appName, $request);
  37. }
  38. /**
  39. * Lookup user display names
  40. *
  41. * @NoAdminRequired
  42. *
  43. * @param array $users
  44. *
  45. * @return JSONResponse
  46. */
  47. public function getDisplayNames($users) {
  48. $result = [];
  49. foreach ($users as $user) {
  50. $userObject = $this->userManager->get($user);
  51. if (is_object($userObject)) {
  52. $result[$user] = $userObject->getDisplayName();
  53. } else {
  54. $result[$user] = $user;
  55. }
  56. }
  57. $json = [
  58. 'users' => $result,
  59. 'status' => 'success'
  60. ];
  61. return new JSONResponse($json);
  62. }
  63. }