UserController.php 1.2 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\Attribute\NoAdminRequired;
  11. use OCP\AppFramework\Http\JSONResponse;
  12. use OCP\IRequest;
  13. use OCP\IUserManager;
  14. class UserController extends Controller {
  15. public function __construct(
  16. string $appName,
  17. IRequest $request,
  18. protected IUserManager $userManager,
  19. ) {
  20. parent::__construct($appName, $request);
  21. }
  22. /**
  23. * Lookup user display names
  24. *
  25. * @param array $users
  26. *
  27. * @return JSONResponse
  28. */
  29. #[NoAdminRequired]
  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. }