Merge pull request #21419 from nextcloud/backport/21408/stable19
[stable19] Avoid duplicate matches in wide and exact results
This commit is contained in:
commit
5c467fccd4
|
@ -71,7 +71,6 @@ class UserPlugin implements ISearchPlugin {
|
||||||
public function search($search, $limit, $offset, ISearchResult $searchResult) {
|
public function search($search, $limit, $offset, ISearchResult $searchResult) {
|
||||||
$result = ['wide' => [], 'exact' => []];
|
$result = ['wide' => [], 'exact' => []];
|
||||||
$users = [];
|
$users = [];
|
||||||
$autoCompleteUsers = [];
|
|
||||||
$hasMoreResults = false;
|
$hasMoreResults = false;
|
||||||
|
|
||||||
$userGroups = [];
|
$userGroups = [];
|
||||||
|
@ -91,28 +90,6 @@ class UserPlugin implements ISearchPlugin {
|
||||||
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;
|
||||||
|
|
||||||
$addToWideResults = false;
|
|
||||||
if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
|
|
||||||
$addToWideResults = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->shareeEnumerationInGroupOnly) {
|
|
||||||
$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
|
|
||||||
if (!empty($commonGroups)) {
|
|
||||||
$addToWideResults = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($addToWideResults) {
|
|
||||||
$autoCompleteUsers[] = [
|
|
||||||
'label' => $user->getDisplayName(),
|
|
||||||
'value' => [
|
|
||||||
'shareType' => IShare::TYPE_USER,
|
|
||||||
'shareWith' => (string)$user->getUID(),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,13 +122,27 @@ class UserPlugin implements ISearchPlugin {
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$result['wide'][] = [
|
$addToWideResults = false;
|
||||||
'label' => $userDisplayName,
|
if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
|
||||||
'value' => [
|
$addToWideResults = true;
|
||||||
'shareType' => Share::SHARE_TYPE_USER,
|
}
|
||||||
'shareWith' => $uid,
|
|
||||||
],
|
if ($this->shareeEnumerationInGroupOnly) {
|
||||||
];
|
$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
|
||||||
|
if (!empty($commonGroups)) {
|
||||||
|
$addToWideResults = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($addToWideResults) {
|
||||||
|
$result['wide'][] = [
|
||||||
|
'label' => $userDisplayName,
|
||||||
|
'value' => [
|
||||||
|
'shareType' => IShare::TYPE_USER,
|
||||||
|
'shareWith' => $uid,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,10 +174,7 @@ class UserPlugin implements ISearchPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// overwrite wide matches if they are limited
|
|
||||||
if (!$this->shareeEnumeration || $this->shareeEnumerationInGroupOnly) {
|
|
||||||
$result['wide'] = $autoCompleteUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = new SearchResultType('users');
|
$type = new SearchResultType('users');
|
||||||
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
|
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
|
||||||
|
|
|
@ -522,7 +522,16 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => ['groupA']],
|
['uid' => 'test1', 'groups' => ['groupA']],
|
||||||
['uid' => 'test2', 'groups' => ['groupB']],
|
['uid' => 'test2', 'groups' => ['groupB']],
|
||||||
],
|
],
|
||||||
['test1'],
|
['exact' => [], 'wide' => ['test1']],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'test1',
|
||||||
|
['groupA'],
|
||||||
|
[
|
||||||
|
['uid' => 'test1', 'groups' => ['groupA']],
|
||||||
|
['uid' => 'test2', 'groups' => ['groupB']],
|
||||||
|
],
|
||||||
|
['exact' => ['test1'], 'wide' => []],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
|
@ -531,7 +540,7 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => ['groupA']],
|
['uid' => 'test1', 'groups' => ['groupA']],
|
||||||
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
||||||
],
|
],
|
||||||
['test1', 'test2'],
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
|
@ -540,7 +549,7 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
||||||
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
||||||
],
|
],
|
||||||
['test1', 'test2'],
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
|
@ -549,7 +558,7 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
||||||
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
||||||
],
|
],
|
||||||
['test1', 'test2'],
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
|
@ -558,7 +567,7 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => ['groupA']],
|
['uid' => 'test1', 'groups' => ['groupA']],
|
||||||
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
||||||
],
|
],
|
||||||
[],
|
['exact' => [], 'wide' => []],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
|
@ -567,7 +576,16 @@ class UserPluginTest extends TestCase {
|
||||||
['uid' => 'test1', 'groups' => []],
|
['uid' => 'test1', 'groups' => []],
|
||||||
['uid' => 'test2', 'groups' => []],
|
['uid' => 'test2', 'groups' => []],
|
||||||
],
|
],
|
||||||
[],
|
['exact' => [], 'wide' => []],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'test',
|
||||||
|
['groupC', 'groupB'],
|
||||||
|
[
|
||||||
|
['uid' => 'test1', 'groups' => []],
|
||||||
|
['uid' => 'test2', 'groups' => []],
|
||||||
|
],
|
||||||
|
['exact' => [], 'wide' => []],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -582,9 +600,12 @@ class UserPluginTest extends TestCase {
|
||||||
return $this->getUserMock($user['uid'], $user['uid']);
|
return $this->getUserMock($user['uid'], $user['uid']);
|
||||||
}, $matchingUsers);
|
}, $matchingUsers);
|
||||||
|
|
||||||
$mappedResult = array_map(function ($user) {
|
$mappedResultExact = array_map(function ($user) {
|
||||||
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
|
||||||
}, $result);
|
}, $result['exact']);
|
||||||
|
$mappedResultWide = array_map(function ($user) {
|
||||||
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
|
||||||
|
}, $result['wide']);
|
||||||
|
|
||||||
$this->userManager->expects($this->once())
|
$this->userManager->expects($this->once())
|
||||||
->method('searchDisplayName')
|
->method('searchDisplayName')
|
||||||
|
@ -615,7 +636,7 @@ class UserPluginTest extends TestCase {
|
||||||
$this->plugin->search($search, $this->limit, $this->offset, $this->searchResult);
|
$this->plugin->search($search, $this->limit, $this->offset, $this->searchResult);
|
||||||
$result = $this->searchResult->asArray();
|
$result = $this->searchResult->asArray();
|
||||||
|
|
||||||
$this->assertEquals([], $result['exact']['users']);
|
$this->assertEquals($mappedResultExact, $result['exact']['users']);
|
||||||
$this->assertEquals($mappedResult, $result['users']);
|
$this->assertEquals($mappedResultWide, $result['users']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue