UserController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Attribute\FrontpageRoute;
  28. use OCP\AppFramework\Http\JSONResponse;
  29. use OCP\IRequest;
  30. use OCP\IUserManager;
  31. class UserController extends Controller {
  32. public function __construct(
  33. string $appName,
  34. IRequest $request,
  35. protected IUserManager $userManager,
  36. ) {
  37. parent::__construct($appName, $request);
  38. }
  39. /**
  40. * Lookup user display names
  41. *
  42. * @NoAdminRequired
  43. *
  44. * @param array $users
  45. *
  46. * @return JSONResponse
  47. */
  48. #[FrontpageRoute(verb: 'POST', url: '/displaynames')]
  49. public function getDisplayNames($users) {
  50. $result = [];
  51. foreach ($users as $user) {
  52. $userObject = $this->userManager->get($user);
  53. if (is_object($userObject)) {
  54. $result[$user] = $userObject->getDisplayName();
  55. } else {
  56. $result[$user] = $user;
  57. }
  58. }
  59. $json = [
  60. 'users' => $result,
  61. 'status' => 'success'
  62. ];
  63. return new JSONResponse($json);
  64. }
  65. }