diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-10-10 13:33:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 13:33:49 +0200 |
commit | 43971f6a5cd833895a28293e62d55c6eb60117dc (patch) | |
tree | 979233cc0550768fa302337ed62a4d31f6530754 /apps | |
parent | 025cdb35cb58c854c9875748a5efd24ac1f312e3 (diff) | |
parent | e51d20479e70320486385a4787f5d09abdd6ed4e (diff) | |
download | nextcloud-server-43971f6a5cd833895a28293e62d55c6eb60117dc.tar.gz nextcloud-server-43971f6a5cd833895a28293e62d55c6eb60117dc.zip |
Merge pull request #39756 from nextcloud/enh/add-disabled-users-endpoint
Add endpoint for getting disabled user list
Diffstat (limited to 'apps')
-rw-r--r-- | apps/provisioning_api/appinfo/routes.php | 1 | ||||
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 75 | ||||
-rw-r--r-- | apps/provisioning_api/openapi.json | 107 |
3 files changed, 181 insertions, 2 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index ab404ff8459..6d9be753d45 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -47,6 +47,7 @@ return [ // Users ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'], + ['root' => '/cloud', 'name' => 'Users#getDisabledUsersDetails', 'url' => '/users/disabled', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#searchByPhoneNumbers', 'url' => '/users/search/by-phone', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index b7e9b5d0de0..97d94ecb407 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -211,7 +211,6 @@ class UsersController extends AUserData { $users = array_merge(...$users); } - /** @var array<string, ProvisioningApiUserDetails|array{id: string}> $usersDetails */ $usersDetails = []; foreach ($users as $userId) { $userId = (string) $userId; @@ -231,6 +230,79 @@ class UsersController extends AUserData { ]); } + /** + * @NoAdminRequired + * + * Get the list of disabled users and their details + * + * @param ?int $limit Limit the amount of users returned + * @param int $offset Offset + * @return DataResponse<Http::STATUS_OK, array{users: array<string, ProvisioningApiUserDetails|array{id: string}>}, array{}> + * + * 200: Disabled users details returned + */ + public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): DataResponse { + $currentUser = $this->userSession->getUser(); + if ($currentUser === null) { + return new DataResponse(['users' => []]); + } + if ($limit !== null && $limit < 0) { + throw new InvalidArgumentException("Invalid limit value: $limit"); + } + if ($offset < 0) { + throw new InvalidArgumentException("Invalid offset value: $offset"); + } + + $users = []; + + // Admin? Or SubAdmin? + $uid = $currentUser->getUID(); + $subAdminManager = $this->groupManager->getSubAdmin(); + if ($this->groupManager->isAdmin($uid)) { + $users = $this->userManager->getDisabledUsers($limit, $offset); + $users = array_map(fn (IUser $user): string => $user->getUID(), $users); + } elseif ($subAdminManager->isSubAdmin($currentUser)) { + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser); + + $users = []; + /* We have to handle offset ourselve for correctness */ + $tempLimit = ($limit === null ? null : $limit + $offset); + foreach ($subAdminOfGroups as $group) { + $users = array_merge( + $users, + array_map( + fn (IUser $user): string => $user->getUID(), + array_filter( + $group->searchUsers('', ($tempLimit === null ? null : $tempLimit - count($users))), + fn (IUser $user): bool => $user->isEnabled() + ) + ) + ); + if (($tempLimit !== null) && (count($users) >= $tempLimit)) { + break; + } + } + $users = array_slice($users, $offset); + } + + $usersDetails = []; + foreach ($users as $userId) { + $userData = $this->getUserData($userId); + // Do not insert empty entry + if ($userData !== null) { + $usersDetails[$userId] = $userData; + } else { + // Logged user does not have permissions to see this user + // only showing its id + $usersDetails[$userId] = ['id' => $userId]; + } + } + + return new DataResponse([ + 'users' => $usersDetails + ]); + } + /** * @NoAdminRequired @@ -852,7 +924,6 @@ class UsersController extends AUserData { if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { $permittedFields[] = self::USER_FIELD_QUOTA; $permittedFields[] = self::USER_FIELD_MANAGER; - } } else { // Check if admin / subadmin diff --git a/apps/provisioning_api/openapi.json b/apps/provisioning_api/openapi.json index cb30b5faad4..566e907bac1 100644 --- a/apps/provisioning_api/openapi.json +++ b/apps/provisioning_api/openapi.json @@ -2028,6 +2028,113 @@ } } }, + "/ocs/v2.php/cloud/users/disabled": { + "get": { + "operationId": "users-get-disabled-users-details", + "summary": "Get the list of disabled users and their details", + "tags": [ + "users" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "limit", + "in": "query", + "description": "Limit the amount of users returned", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "offset", + "in": "query", + "description": "Offset", + "schema": { + "type": "integer", + "format": "int64", + "default": 0 + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Disabled users details returned", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "users" + ], + "properties": { + "users": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/components/schemas/UserDetails" + }, + { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string" + } + } + } + ] + } + } + } + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/cloud/users/search/by-phone": { "post": { "operationId": "users-search-by-phone-numbers", |