Also limit to user group in case enumeration is enabled for groups and phonenumbers
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
e9ea4a0f01
commit
3fd9d0dc50
|
@ -97,7 +97,7 @@ class UserPlugin implements ISearchPlugin {
|
||||||
|
|
||||||
$currentUserId = $this->userSession->getUser()->getUID();
|
$currentUserId = $this->userSession->getUser()->getUID();
|
||||||
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
|
$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
|
||||||
if ($this->shareWithGroupOnly) {
|
if ($this->shareWithGroupOnly || $this->shareeEnumerationInGroupOnly) {
|
||||||
// Search in all the groups this user is part of
|
// Search in all the groups this user is part of
|
||||||
foreach ($currentUserGroups as $userGroupId) {
|
foreach ($currentUserGroups as $userGroupId) {
|
||||||
$usersInGroup = $this->groupManager->displayNamesInGroup($userGroupId, $search, $limit, $offset);
|
$usersInGroup = $this->groupManager->displayNamesInGroup($userGroupId, $search, $limit, $offset);
|
||||||
|
@ -114,6 +114,25 @@ class UserPlugin implements ISearchPlugin {
|
||||||
$hasMoreResults = true;
|
$hasMoreResults = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->shareWithGroupOnly && $this->shareeEnumerationPhone) {
|
||||||
|
$usersTmp = $this->userManager->searchKnownUsersByDisplayName($currentUserId, $search, $limit, $offset);
|
||||||
|
if (!empty($usersTmp)) {
|
||||||
|
foreach ($usersTmp as $user) {
|
||||||
|
if ($user->isEnabled()) { // Don't keep deactivated users
|
||||||
|
$users[$user->getUID()] = $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uasort($users, function ($a, $b) {
|
||||||
|
/**
|
||||||
|
* @var \OC\User\User $a
|
||||||
|
* @var \OC\User\User $b
|
||||||
|
*/
|
||||||
|
return strcasecmp($a->getDisplayName(), $b->getDisplayName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Search in all users
|
// Search in all users
|
||||||
if ($this->shareeEnumerationPhone) {
|
if ($this->shareeEnumerationPhone) {
|
||||||
|
|
|
@ -659,9 +659,10 @@ class UserPluginTest extends TestCase {
|
||||||
public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) {
|
public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) {
|
||||||
$this->mockConfig(false, true, true);
|
$this->mockConfig(false, true, true);
|
||||||
|
|
||||||
$userResults = array_map(function ($user) {
|
$userResults = [];
|
||||||
return $this->getUserMock($user['uid'], $user['uid']);
|
foreach ($matchingUsers as $user) {
|
||||||
}, $matchingUsers);
|
$userResults[$user['uid']] = $user['uid'];
|
||||||
|
}
|
||||||
|
|
||||||
$mappedResultExact = array_map(function ($user) {
|
$mappedResultExact = array_map(function ($user) {
|
||||||
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
||||||
|
@ -670,9 +671,19 @@ class UserPluginTest extends TestCase {
|
||||||
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
||||||
}, $result['wide']);
|
}, $result['wide']);
|
||||||
|
|
||||||
$this->userManager->expects($this->once())
|
$this->userManager
|
||||||
->method('searchDisplayName')
|
->method('get')
|
||||||
|
->willReturnCallback(function ($userId) use ($userResults) {
|
||||||
|
if (isset($userResults[$userId])) {
|
||||||
|
return $this->getUserMock($userId, $userId);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->groupManager->method('displayNamesInGroup')
|
||||||
->willReturn($userResults);
|
->willReturn($userResults);
|
||||||
|
|
||||||
|
|
||||||
$this->session->expects($this->any())
|
$this->session->expects($this->any())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->willReturn($this->getUserMock('test', 'foo'));
|
->willReturn($this->getUserMock('test', 'foo'));
|
||||||
|
|
Loading…
Reference in New Issue