Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] feat: Add back searching in disabled user list #45478

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,14 @@ public function getUsersDetails(string $search = '', int $limit = null, int $off
*
* Get the list of disabled users and their details
*
* @param string $search Text to search for
* @param ?int $limit Limit the amount of users returned
* @param int $offset Offset
* @return DataResponse<Http::STATUS_OK, array{users: array<string, Provisioning_APIUserDetails|array{id: string}>}, array{}>
*
* 200: Disabled users details returned
*/
public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): DataResponse {
public function getDisabledUsersDetails(string $search = '', ?int $limit = null, int $offset = 0): DataResponse {
$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
return new DataResponse(['users' => []]);
Expand All @@ -267,7 +268,7 @@ public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): Da
$uid = $currentUser->getUID();
$subAdminManager = $this->groupManager->getSubAdmin();
if ($this->groupManager->isAdmin($uid)) {
$users = $this->userManager->getDisabledUsers($limit, $offset);
$users = $this->userManager->getDisabledUsers($limit, $offset, $search);
$users = array_map(fn (IUser $user): string => $user->getUID(), $users);
} elseif ($subAdminManager->isSubAdmin($currentUser)) {
$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
Expand All @@ -281,7 +282,7 @@ public function getDisabledUsersDetails(?int $limit = null, int $offset = 0): Da
array_map(
fn (IUser $user): string => $user->getUID(),
array_filter(
$group->searchUsers('', ($tempLimit === null ? null : $tempLimit - count($users))),
$group->searchUsers($search, ($tempLimit === null ? null : $tempLimit - count($users))),
fn (IUser $user): bool => !$user->isEnabled()
)
)
Expand Down
9 changes: 9 additions & 0 deletions apps/provisioning_api/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,15 @@
}
],
"parameters": [
{
"name": "search",
"in": "query",
"description": "Text to search for",
"schema": {
"type": "string",
"default": ""
}
},
{
"name": "limit",
"in": "query",
Expand Down
9 changes: 9 additions & 0 deletions apps/provisioning_api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,15 @@
}
],
"parameters": [
{
"name": "search",
"in": "query",
"description": "Text to search for",
"schema": {
"type": "string",
"default": ""
}
},
{
"name": "limit",
"in": "query",
Expand Down
1 change: 1 addition & 0 deletions apps/settings/src/components/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export default {
await this.$store.dispatch('getDisabledUsers', {
offset: this.disabledUsersOffset,
limit: this.disabledUsersLimit,
search: this.searchQuery,
})
} else {
await this.$store.dispatch('getUsers', {
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ const actions = {
* @param {number} options.limit List number to return from offset
* @return {Promise<number>}
*/
async getDisabledUsers(context, { offset, limit }) {
const url = generateOcsUrl('cloud/users/disabled?offset={offset}&limit={limit}', { offset, limit })
async getDisabledUsers(context, { offset, limit, search }) {
const url = generateOcsUrl('cloud/users/disabled?offset={offset}&limit={limit}&search={search}', { offset, limit, search })
try {
const response = await api.get(url)
const usersCount = Object.keys(response.data.ocs.data.users).length
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
return $enabled;
}

public function getDisabledUserList(?int $limit = null, int $offset = 0): array {
public function getDisabledUserList(?int $limit = null, int $offset = 0, string $search = ''): array {
throw new \Exception('This is implemented directly in User_Proxy');
}
}
15 changes: 13 additions & 2 deletions apps/user_ldap/lib/User_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,22 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
return $this->handleRequest($uid, 'setUserEnabled', [$uid, $enabled, $queryDatabaseValue, $setDatabaseValue]);
}

public function getDisabledUserList(?int $limit = null, int $offset = 0): array {
public function getDisabledUserList(?int $limit = null, int $offset = 0, string $search = ''): array {
$disabledUsers = $this->deletedUsersIndex->getUsers();
if ($search !== '') {
$disabledUsers = array_filter(
$disabledUsers,
fn (OfflineUser $user): bool =>
mb_stripos($user->getOCName(), $search) !== false ||
mb_stripos($user->getUID(), $search) !== false ||
mb_stripos($user->getDisplayName(), $search) !== false ||
mb_stripos($user->getEmail(), $search) !== false,
);
}
return array_map(
fn (OfflineUser $user) => $user->getOCName(),
array_slice(
$this->deletedUsersIndex->getUsers(),
$disabledUsers,
$offset,
$limit
)
Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-users-3239.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-users-3239.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function searchDisplayName($pattern, $limit = null, $offset = null) {
/**
* @return IUser[]
*/
public function getDisabledUsers(?int $limit = null, int $offset = 0): array {
public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array {
$users = $this->config->getUsersForUserValue('core', 'enabled', 'false');
$users = array_combine(
$users,
Expand All @@ -350,14 +350,23 @@ public function getDisabledUsers(?int $limit = null, int $offset = 0): array {
$users
)
);
if ($search !== '') {
$users = array_filter(
$users,
fn (IUser $user): bool =>
mb_stripos($user->getUID(), $search) !== false ||
mb_stripos($user->getDisplayName(), $search) !== false ||
mb_stripos($user->getEMailAddress() ?? '', $search) !== false,
);
}

$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)));
$backendUsers = $backend->getDisabledUserList(($tempLimit === null ? null : $tempLimit - count($users)), 0, $search);
foreach ($backendUsers as $uid) {
$users[$uid] = new LazyUser($uid, $this, null, $backend);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public function searchDisplayName($pattern, $limit = null, $offset = null);
/**
* @return IUser[]
* @since 28.0.0
* @since 28.0.7 $search parameter added
*/
public function getDisabledUsers(?int $limit = null, int $offset = 0): array;
public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array;

/**
* Search known users (from phonebook sync) by displayName
Expand Down
3 changes: 2 additions & 1 deletion lib/public/User/Backend/IProvideEnabledStateBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
* Get the list of disabled users, to merge with the ones disabled in database
*
* @since 28.0.0
* @since 28.0.7 $search parameter added
*
* @return string[]
*/
public function getDisabledUserList(?int $limit = null, int $offset = 0): array;
public function getDisabledUserList(?int $limit = null, int $offset = 0, string $search = ''): array;
}
Loading