diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index 66d1fb699a9f6..4552121d0d650 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -27,6 +27,7 @@ // Users ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'], + ['root' => '/cloud', 'name' => 'Users#searchAllUsers', 'url' => '/users/search', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getDisabledUsersDetails', 'url' => '/users/disabled', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getLastLoggedInUsers', 'url' => '/users/recent', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#searchByPhoneNumbers', 'url' => '/users/search/by-phone', 'verb' => 'POST'], diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 4b3db45f51895..13b7b58f2b68c 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -339,6 +339,45 @@ public function getLastLoggedInUsers(string $search = '', } + /** + * Search all users by id or display name + * + * Allows subadmins to look up existing users that are not yet part of + * their groups so they can add them. + * + * @param string $search Text to search for + * @param ?int $limit Limit the amount of users returned + * @param int $offset Offset for searching for users + * @return DataResponse}, array{}> + * + * 200: Users returned + */ + #[NoAdminRequired] + public function searchAllUsers(string $search = '', ?int $limit = null, int $offset = 0): DataResponse { + $currentUser = $this->userSession->getUser(); + + $uid = $currentUser->getUID(); + $subAdminManager = $this->groupManager->getSubAdmin(); + $isAdmin = $this->groupManager->isAdmin($uid); + $isDelegatedAdmin = $this->groupManager->isDelegatedAdmin($uid); + + if ($isAdmin || $isDelegatedAdmin || $subAdminManager->isSubAdmin($currentUser)) { + $users = $this->userManager->searchDisplayName($search, $limit, $offset); + $result = []; + foreach ($users as $user) { + /** @var IUser $user */ + $result[$user->getUID()] = $user->getDisplayName(); + } + + return new DataResponse([ + 'users' => $result, + ]); + } + + throw new OCSForbiddenException(); + } + + /** * @NoSubAdminRequired diff --git a/apps/settings/src/components/UserList.vue b/apps/settings/src/components/UserList.vue index 84c204805cc4c..13b6cfe973e5e 100644 --- a/apps/settings/src/components/UserList.vue +++ b/apps/settings/src/components/UserList.vue @@ -2,15 +2,18 @@ - SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors - SPDX-License-Identifier: AGPL-3.0-or-later --> -