diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-05-16 16:13:31 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-05-27 15:03:03 +0200 |
commit | 896c539705be3c420fd983e36a84ffac1c84ad94 (patch) | |
tree | a9a1db5131c56bd2e4d0ae8b68d89369cdf58eb0 | |
parent | 1e9a7e47792673bb6fd111ff2d75e70bef9eb5f9 (diff) | |
download | nextcloud-server-896c539705be3c420fd983e36a84ffac1c84ad94.tar.gz nextcloud-server-896c539705be3c420fd983e36a84ffac1c84ad94.zip |
feat: Add back searching in disabled user list
When disabled users where moved to their own endpoint we overlooked
search, so adding it back.
The search is done case-insensitive in uid and display name.
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 7 | ||||
-rw-r--r-- | apps/settings/src/components/UserList.vue | 1 | ||||
-rw-r--r-- | apps/settings/src/store/users.js | 4 | ||||
-rw-r--r-- | apps/user_ldap/lib/User_LDAP.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/lib/User_Proxy.php | 14 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 12 | ||||
-rw-r--r-- | lib/public/IUserManager.php | 3 | ||||
-rw-r--r-- | lib/public/User/Backend/IProvideEnabledStateBackend.php | 3 |
8 files changed, 34 insertions, 12 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 24ac097f6bb..dd5114a106e 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -243,13 +243,14 @@ class UsersController extends AUserData { * * 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' => []]); @@ -267,7 +268,7 @@ class UsersController extends AUserData { $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); @@ -281,7 +282,7 @@ class UsersController extends AUserData { 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() ) ) diff --git a/apps/settings/src/components/UserList.vue b/apps/settings/src/components/UserList.vue index 92c823e8bc5..a1835dc9294 100644 --- a/apps/settings/src/components/UserList.vue +++ b/apps/settings/src/components/UserList.vue @@ -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', { diff --git a/apps/settings/src/store/users.js b/apps/settings/src/store/users.js index 499aa73170d..44b6ec1292c 100644 --- a/apps/settings/src/store/users.js +++ b/apps/settings/src/store/users.js @@ -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 diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index d787bfea4d4..68945600da9 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -682,7 +682,7 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I 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'); } } diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 934bed7d450..0dd62ccce8f 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -463,11 +463,21 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP 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, + ); + } return array_map( fn (OfflineUser $user) => $user->getOCName(), array_slice( - $this->deletedUsersIndex->getUsers(), + $disabledUsers, $offset, $limit ) diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index ea460739f60..a316708ddef 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -341,7 +341,7 @@ class Manager extends PublicEmitter implements IUserManager { /** * @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, @@ -350,6 +350,14 @@ class Manager extends PublicEmitter implements IUserManager { $users ) ); + if ($search !== '') { + $users = array_filter( + $users, + fn (IUser $user): bool => + mb_stripos($user->getUID(), $search) !== false || + mb_stripos($user->getDisplayName(), $search) !== false, + ); + } $tempLimit = ($limit === null ? null : $limit + $offset); foreach ($this->backends as $backend) { @@ -357,7 +365,7 @@ class Manager extends PublicEmitter implements IUserManager { 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); } diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php index 0a94c5ad928..94ab487d318 100644 --- a/lib/public/IUserManager.php +++ b/lib/public/IUserManager.php @@ -142,8 +142,9 @@ interface IUserManager { /** * @return IUser[] * @since 28.0.0 + * @since 30.0.0 $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 diff --git a/lib/public/User/Backend/IProvideEnabledStateBackend.php b/lib/public/User/Backend/IProvideEnabledStateBackend.php index f12d99fd1a6..3fd517048fb 100644 --- a/lib/public/User/Backend/IProvideEnabledStateBackend.php +++ b/lib/public/User/Backend/IProvideEnabledStateBackend.php @@ -49,8 +49,9 @@ interface IProvideEnabledStateBackend { * Get the list of disabled users, to merge with the ones disabled in database * * @since 28.0.0 + * @since 30.0.0 $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; } |