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

Manually search for displayname by iterating over group members #27531

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 8 additions & 12 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,17 @@ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0

if (!empty($search)) {
// only user backends have the capability to do a complex search for users
$searchOffset = 0;
$searchLimit = $limit * 100;
if ($limit === -1) {
$searchLimit = 500;
}

$chunkOffset = 0;
$chunkLimit = 500;
do {
$filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset);
foreach ($filteredUsers as $filteredUser) {
if ($group->inGroup($filteredUser)) {
$groupUsers[] = $filteredUser;
$userChunk = $group->searchUsers('', $chunkLimit, $chunkOffset);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, searchUsers allows to filter by uid and display name.
I guess we could filter a bit with it:

Suggested change
$userChunk = $group->searchUsers('', $chunkLimit, $chunkOffset);
$userChunk = $group->searchUsers($search, $chunkLimit, $chunkOffset);

foreach ($userChunk as $user) {
if (mb_stripos($user->getDisplayName(), $search) > -1) {
$groupUsers[] = $user;
}
}
$searchOffset += $searchLimit;
} while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit);
$chunkOffset += $chunkLimit;
} while (count($userChunk) !== 0);

if ($limit === -1) {
$groupUsers = array_slice($groupUsers, $offset);
Expand Down
Loading