From b30e035e25923101345dc02b7e82936cbef9b811 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 Feb 2018 18:11:44 +0100 Subject: [PATCH] Better result handling of email search 1. Local users should not be returned when searching for empty string 2. The limit of the response should be respected Signed-off-by: Joas Schilling --- lib/private/Collaboration/Collaborators/MailPlugin.php | 2 ++ lib/private/Collaboration/Collaborators/RemotePlugin.php | 2 ++ tests/lib/Collaboration/Collaborators/MailPluginTest.php | 4 ++-- tests/lib/Collaboration/Collaborators/RemotePluginTest.php | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index 2e946c4a87..99629f213e 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -173,6 +173,8 @@ class MailPlugin implements ISearchPlugin { if (!$this->shareeEnumeration) { $result['wide'] = []; + } else { + $result['wide'] = array_slice($result['wide'], $offset, $limit); } if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index b17a64e4ff..e0f5298f83 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -102,6 +102,8 @@ class RemotePlugin implements ISearchPlugin { if (!$this->shareeEnumeration) { $result['wide'] = []; + } else { + $result['wide'] = array_slice($result['wide'], $offset, $limit); } if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index b728ae521e..9c4836c2eb 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -103,7 +103,7 @@ class MailPluginTest extends TestCase { ->with($searchTerm, ['EMAIL', 'FN']) ->willReturn($contacts); - $moreResults = $this->plugin->search($searchTerm, 0, 0, $this->searchResult); + $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult); $result = $this->searchResult->asArray(); $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails'))); @@ -398,7 +398,7 @@ class MailPluginTest extends TestCase { return in_array($group, $userToGroupMapping[$userId]); }); - $moreResults = $this->plugin->search($searchTerm, 0, 0, $this->searchResult); + $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult); $result = $this->searchResult->asArray(); $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails'))); diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index 5c4b3af5e7..aa009a7134 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -94,7 +94,7 @@ class RemotePluginTest extends TestCase { ->with($searchTerm, ['CLOUD', 'FN']) ->willReturn($contacts); - $moreResults = $this->plugin->search($searchTerm, 0, 0, $this->searchResult); + $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult); $result = $this->searchResult->asArray(); $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('remotes')));