fix: Include email when searching share suggestions

Signed-off-by: nfebe <fenn25.fn@gmail.com>

[skip ci]
pull/55642/head
nfebe 2025-09-17 13:20:25 +07:00 committed by F. E Noel Nfebe
parent f94d30cbc6
commit da82f6f79f
2 changed files with 52 additions and 2 deletions

@ -42,7 +42,7 @@ class RemotePlugin implements ISearchPlugin {
$resultType = new SearchResultType('remotes');
// Search in contacts
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN', 'EMAIL'], [
'limit' => $limit,
'offset' => $offset,
'enumeration' => false,
@ -84,7 +84,17 @@ class RemotePlugin implements ISearchPlugin {
];
}
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
$emailMatch = false;
if (isset($contact['EMAIL'])) {
$emails = is_array($contact['EMAIL']) ? $contact['EMAIL'] : [$contact['EMAIL']];
foreach ($emails as $email) {
if (is_string($email) && strtolower($email) === $lowerSearch) {
$emailMatch = true;
break;
}
}
}
if ($emailMatch || strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
if (strtolower($cloudId) === $lowerSearch) {
$searchResult->markExactIdMatch($resultType);
}

@ -180,6 +180,46 @@ class RemotePluginTest extends TestCase {
$this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']);
}
public function testEmailSearchInContacts(): void {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(
function ($appName, $key, $default) {
if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
return 'yes';
}
return $default;
}
);
$this->trustedServers->expects($this->any())
->method('isTrustedServer')
->willReturnCallback(function ($serverUrl) {
return $serverUrl === 'trustedserver.com';
});
$this->instantiatePlugin();
$this->contactsManager->expects($this->once())
->method('search')
->with('john@gmail.com', ['CLOUD', 'FN', 'EMAIL'])
->willReturn([
[
'FN' => 'John Doe',
'EMAIL' => 'john@gmail.com',
'CLOUD' => 'john@trustedserver.com',
'UID' => 'john-contact-id'
]
]);
$this->plugin->search('john@gmail.com', 2, 0, $this->searchResult);
$result = $this->searchResult->asArray();
$this->assertNotEmpty($result['exact']['remotes']);
$this->assertEquals('john@trustedserver.com', $result['exact']['remotes'][0]['value']['shareWith']);
$this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']);
}
public static function dataGetRemote() {
return [
['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true],