Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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#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'],
Expand Down
66 changes: 64 additions & 2 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public function getUsersDetails(string $search = '', int $limit = null, int $off
$users = array_merge(...$users);
}

/** @var array<string, ProvisioningApiUserDetails|array{id: string}> $usersDetails */
$usersDetails = [];
foreach ($users as $userId) {
$userId = (string) $userId;
Expand All @@ -231,6 +230,70 @@ public function getUsersDetails(string $search = '', int $limit = null, int $off
]);
}

/**
* @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{}>
*/
public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): DataResponse {
$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
return new DataResponse(['users' => []]);
}
$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
Expand Down Expand Up @@ -852,7 +915,6 @@ public function editUser(string $userId, string $key, string $value): DataRespon
if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
$permittedFields[] = self::USER_FIELD_QUOTA;
$permittedFields[] = self::USER_FIELD_MANAGER;

}
} else {
// Check if admin / subadmin
Expand Down
106 changes: 106 additions & 0 deletions apps/provisioning_api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,112 @@
}
}
},
"/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",
"required": true,
"schema": {
"type": "string",
"default": "true"
}
}
],
"responses": {
"200": {
"description": "",
"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",
Expand Down
30 changes: 30 additions & 0 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCP\User\Backend\ISearchKnownUsersBackend;
use OCP\User\Backend\ICheckPasswordBackend;
use OCP\User\Backend\ICountUsersBackend;
use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\User\Events\BeforeUserCreatedEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\UserInterface;
Expand Down Expand Up @@ -337,6 +338,35 @@ public function searchDisplayName($pattern, $limit = null, $offset = null) {
return $users;
}

/**
* @return IUser[]
*/
public function getDisabledUsers(?int $limit = null, int $offset = 0): array {
$users = $this->config->getUsersForUserValue('core', 'enabled', 'false');
$users = array_combine(
$users,
array_map(
fn (string $uid): IUser => new LazyUser($uid, $this),
$users
)
);

$tempLimit = ($limit === null ? null : $limit + $offset);
foreach ($this->backends as $backend) {
if (($tempLimit !== null) && (count($users) >= $tempLimit)) {
break;
}
if ($backend instanceof IProvideEnabledStateBackend) {
$backendUsers = $backend->getDisabledUserList(($tempLimit === null ? null : $tempLimit - count($users)));
foreach ($backendUsers as $uid) {
$users[$uid] = new LazyUser($uid, $this, null, $backend);
}
}
}

return array_slice($users, $offset, $limit);
}

/**
* Search known users (from phonebook sync) by displayName
*
Expand Down
6 changes: 6 additions & 0 deletions lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public function search($pattern, $limit = null, $offset = null);
*/
public function searchDisplayName($pattern, $limit = null, $offset = null);

/**
* @return IUser[]
* @since 28.0.0
*/
public function getDisabledUsers(?int $limit = null, int $offset = 0): array;

/**
* Search known users (from phonebook sync) by displayName
*
Expand Down