Skip to content

Commit 65dfd15

Browse files
committed
fix: Include email when searching share suggestions
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 177d73c commit 65dfd15

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 ($emailMatch || strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
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
@@ -180,6 +180,46 @@ function ($appName, $key, $default) {
180180
$this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']);
181181
}
182182

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

0 commit comments

Comments
 (0)