Move back to IGroupManager::displayNamesInGroup()

The problem is that despite it's name IGroup::searchDisplayName()
only searches by userid and this is less fixable than changing back to this method here

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-06-17 11:59:56 +02:00 committed by backportbot[bot]
parent 86fdf17eed
commit 7a36a4b99c
1 changed files with 6 additions and 10 deletions

View File

@ -73,20 +73,19 @@ class UserPlugin implements ISearchPlugin {
$users = []; $users = [];
$hasMoreResults = false; $hasMoreResults = false;
$userGroups = []; $currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
if ($this->shareWithGroupOnly) { if ($this->shareWithGroupOnly) {
// Search in all the groups this user is part of // Search in all the groups this user is part of
$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); foreach ($currentUserGroups as $userGroupId) {
foreach ($userGroups as $userGroup) { $usersInGroup = $this->groupManager->displayNamesInGroup($userGroupId, $search, $limit, $offset);
$usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset); foreach ($usersInGroup as $userId => $displayName) {
foreach ($usersInGroup as $user) { $userId = (string) $userId;
$users[$user->getUID()] = $user; $users[$userId] = $this->userManager->get($userId);
} }
} }
} else { } else {
// Search in all users // Search in all users
$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
foreach ($usersTmp as $user) { foreach ($usersTmp as $user) {
if ($user->isEnabled()) { // Don't keep deactivated users if ($user->isEnabled()) { // Don't keep deactivated users
$users[$user->getUID()] = $user; $users[$user->getUID()] = $user;
@ -155,9 +154,6 @@ class UserPlugin implements ISearchPlugin {
if ($this->shareWithGroupOnly) { if ($this->shareWithGroupOnly) {
// Only add, if we have a common group // Only add, if we have a common group
$userGroupIds = array_map(function (IGroup $group) {
return $group->getGID();
}, $userGroups);
$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user)); $commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
$addUser = !empty($commonGroups); $addUser = !empty($commonGroups);
} }