Skip to content

Commit e08c77b

Browse files
committed
fix: Include email when searching share suggestions
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 2687ac5 commit e08c77b

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/private/Collaboration/Collaborators/RemotePlugin.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
4242
$resultType = new SearchResultType('remotes');
4343

4444
// Search in contacts
45-
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
45+
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN', 'EMAIL'], [
4646
'limit' => $limit,
4747
'offset' => $offset,
4848
'enumeration' => false,
@@ -84,7 +84,17 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8484
];
8585
}
8686

87-
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
87+
$emailMatch = false;
88+
if (isset($contact['EMAIL'])) {
89+
$emails = is_array($contact['EMAIL']) ? $contact['EMAIL'] : [$contact['EMAIL']];
90+
foreach ($emails as $email) {
91+
if (is_string($email) && strtolower($email) === $lowerSearch) {
92+
$emailMatch = true;
93+
break;
94+
}
95+
}
96+
}
97+
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch || $emailMatch) {
8898
if (strtolower($cloudId) === $lowerSearch) {
8999
$searchResult->markExactIdMatch($resultType);
90100
}

tests/lib/Collaboration/Collaborators/RemotePluginTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,46 @@ function ($appName, $key, $default) {
182182
$this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']);
183183
}
184184

185+
public function testEmailSearchInContacts(): void {
186+
$this->config->expects($this->any())
187+
->method('getAppValue')
188+
->willReturnCallback(
189+
function ($appName, $key, $default) {
190+
if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
191+
return 'yes';
192+
}
193+
return $default;
194+
}
195+
);
196+
197+
$this->trustedServers->expects($this->any())
198+
->method('isTrustedServer')
199+
->willReturnCallback(function ($serverUrl) {
200+
return $serverUrl === 'trustedserver.com';
201+
});
202+
203+
$this->instantiatePlugin();
204+
205+
$this->contactsManager->expects($this->once())
206+
->method('search')
207+
->with('john@gmail.com', ['CLOUD', 'FN', 'EMAIL'])
208+
->willReturn([
209+
[
210+
'FN' => 'John Doe',
211+
'EMAIL' => 'john@gmail.com',
212+
'CLOUD' => 'john@trustedserver.com',
213+
'UID' => 'john-contact-id'
214+
]
215+
]);
216+
217+
$this->plugin->search('john@gmail.com', 2, 0, $this->searchResult);
218+
$result = $this->searchResult->asArray();
219+
220+
$this->assertNotEmpty($result['exact']['remotes']);
221+
$this->assertEquals('john@trustedserver.com', $result['exact']['remotes'][0]['value']['shareWith']);
222+
$this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']);
223+
}
224+
185225
public static function dataGetRemote() {
186226
return [
187227
['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true],

0 commit comments

Comments
 (0)