UserController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Controller;
  8. use OCP\AppFramework\Controller;
  9. use OCP\AppFramework\Http\Attribute\FrontpageRoute;
  10. use OCP\AppFramework\Http\JSONResponse;
  11. use OCP\IRequest;
  12. use OCP\IUserManager;
  13. class UserController extends Controller {
  14. public function __construct(
  15. string $appName,
  16. IRequest $request,
  17. protected IUserManager $userManager,
  18. ) {
  19. parent::__construct($appName, $request);
  20. }
  21. /**
  22. * Lookup user display names
  23. *
  24. * @NoAdminRequired
  25. *
  26. * @param array $users
  27. *
  28. * @return JSONResponse
  29. */
  30. #[FrontpageRoute(verb: 'POST', url: '/displaynames')]
  31. public function getDisplayNames($users) {
  32. $result = [];
  33. foreach ($users as $user) {
  34. $userObject = $this->userManager->get($user);
  35. if (is_object($userObject)) {
  36. $result[$user] = $userObject->getDisplayName();
  37. } else {
  38. $result[$user] = $user;
  39. }
  40. }
  41. $json = [
  42. 'users' => $result,
  43. 'status' => 'success'
  44. ];
  45. return new JSONResponse($json);
  46. }
  47. }