]> source.dussan.org Git - nextcloud-server.git/commitdiff
Limit more contact searches
authorJoas Schilling <coding@schilljs.com>
Wed, 8 Dec 2021 16:26:30 +0000 (17:26 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 13 Dec 2021 14:26:22 +0000 (14:26 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/federatedfilesharing/lib/Notifier.php
apps/files/lib/Activity/Provider.php
apps/files_sharing/lib/Activity/Providers/Base.php
apps/files_sharing/lib/Controller/ShareAPIController.php
apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
apps/sharebymail/lib/Activity.php
lib/private/Collaboration/Collaborators/RemotePlugin.php
lib/private/Contacts/ContactsMenu/ContactsStore.php
lib/private/Federation/CloudIdManager.php
lib/private/Share/Share.php

index f365a14a13ca3fff8268d5b9ba4450d4babadf9c..3f6d22d03aaf07c98c5e7d0c9d872d7b694203b2 100644 (file)
@@ -255,7 +255,12 @@ class Notifier implements INotifier {
                        }
                }
 
-               $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']);
+               $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD'], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+                       'strict_search' => true,
+               ]);
                foreach ($addressBookEntries as $entry) {
                        if (isset($entry['CLOUD'])) {
                                foreach ($entry['CLOUD'] as $cloudID) {
index f50d9d6a42a6bb5db0a2a4f26d167938ded742aa..6d5618c4128cee66b4e862bd8a5e200f951cf617 100644 (file)
@@ -560,7 +560,12 @@ class Provider implements IProvider {
                        return $this->displayNames[$search];
                }
 
-               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']);
+               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+                       'strict_search' => true,
+               ]);
                foreach ($addressBookContacts as $contact) {
                        if (isset($contact['isLocalSystemBook'])) {
                                continue;
index 843a0c447f16102af1d02d54f04e2c75958a4bf3..b8fee9f66f67b7f0cdc7a4dbe691dab8b42b05fe 100644 (file)
@@ -204,7 +204,12 @@ abstract class Base implements IProvider {
                        return $this->displayNames[$search];
                }
 
-               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']);
+               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+                       'strict_search' => true,
+               ]);
                foreach ($addressBookContacts as $contact) {
                        if (isset($contact['isLocalSystemBook'])) {
                                continue;
index 8a3a8ab038f22cfe01f4ad3a4cb5af22257d30c2..108014923d5a5a35f4654ddeb31060955191f9c3 100644 (file)
@@ -333,8 +333,12 @@ class ShareAPIController extends OCSController {
         * @return string
         */
        private function getDisplayNameFromAddressBook(string $query, string $property): string {
-               // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
-               $result = \OC::$server->getContactsManager()->search($query, [$property]);
+               // FIXME: If we inject the contacts manager it gets initialized before any address books are registered
+               $result = \OC::$server->getContactsManager()->search($query, [$property], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'strict_search' => true,
+               ]);
                foreach ($result as $r) {
                        foreach ($r[$property] as $value) {
                                if ($value === $query && $r['FN']) {
index 804a98f6d3fdfae847eb9de3ae877fde24a5c14a..5b45adc0a4c1e27ab59e79647a723f459d043df5 100644 (file)
@@ -4227,7 +4227,11 @@ class ShareAPIControllerTest extends TestCase {
 
                $cm->method('search')
                        ->willReturnMap([
-                               ['user@server.com', ['CLOUD'], [],
+                               ['user@server.com', ['CLOUD'], [
+                                       'limit' => 1,
+                                       'enumeration' => false,
+                                       'strict_search' => true,
+                               ],
                                        [
                                                [
                                                        'CLOUD' => [
@@ -4237,7 +4241,11 @@ class ShareAPIControllerTest extends TestCase {
                                                ],
                                        ],
                                ],
-                               ['user@server.com', ['EMAIL'], [],
+                               ['user@server.com', ['EMAIL'], [
+                                       'limit' => 1,
+                                       'enumeration' => false,
+                                       'strict_search' => true,
+                               ],
                                        [
                                                [
                                                        'EMAIL' => [
index 23f036c470003eeb43aed26f3804e6e75e372143..861969fca8ac693aeb562795ce9a5069313554a6 100644 (file)
@@ -363,7 +363,12 @@ class Activity implements IProvider {
         * @return string
         */
        protected function getContactName($email) {
-               $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']);
+               $addressBookContacts = $this->contactsManager->search($email, ['EMAIL'], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+                       'strict_search' => true,
+               ]);
 
                foreach ($addressBookContacts as $contact) {
                        if (isset($contact['isLocalSystemBook'])) {
index 3d9b1f9847ac88bbf92623773a0db11abc10d146..e053465e83dfcfaf12338d96c452bd07f6a9c935 100644 (file)
@@ -68,7 +68,12 @@ class RemotePlugin implements ISearchPlugin {
                $resultType = new SearchResultType('remotes');
 
                // Search in contacts
-               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], ['limit' => $limit, 'offset' => $offset]);
+               $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
+                       'limit' => $limit,
+                       'offset' => $offset,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+               ]);
                foreach ($addressBookContacts as $contact) {
                        if (isset($contact['isLocalSystemBook'])) {
                                continue;
index 69f26c7969fb854997322071ad86c2697c1d2ea0..5aa2c5ab1aaca1d5a35bc16ec76b547b7f666791 100644 (file)
@@ -75,7 +75,10 @@ class ContactsStore implements IContactsStore {
         * @return IEntry[]
         */
        public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
-               $options = [];
+               $options = [
+                       'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
+                       'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
+               ];
                if ($limit !== null) {
                        $options['limit'] = $limit;
                }
index 0671a0bfa02298d66f4ffabd543e9e16a689728a..012be25b77f5f10966aecc675f64208f273e01b8 100644 (file)
@@ -83,7 +83,12 @@ class CloudIdManager implements ICloudIdManager {
        }
 
        protected function getDisplayNameFromContact(string $cloudId): ?string {
-               $addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD']);
+               $addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD'], [
+                       'limit' => 1,
+                       'enumeration' => false,
+                       'fullmatch' => false,
+                       'strict_search' => true,
+               ]);
                foreach ($addressBookEntries as $entry) {
                        if (isset($entry['CLOUD'])) {
                                foreach ($entry['CLOUD'] as $cloudID) {
index 2d0d4f1cf87e13e2d3ac7a4cd668e532f1ac6093..5b310ac05c92c82c34a1940842509f765e62513d 100644 (file)
@@ -594,7 +594,12 @@ class Share extends Constants {
                                $row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName();
                        } elseif (isset($row['share_with']) && $row['share_with'] != '' &&
                                $row['share_type'] === IShare::TYPE_REMOTE) {
-                               $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']);
+                               $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD'], [
+                                       'limit' => 1,
+                                       'enumeration' => false,
+                                       'fullmatch' => false,
+                                       'strict_search' => true,
+                               ]);
                                foreach ($addressBookEntries as $entry) {
                                        foreach ($entry['CLOUD'] as $cloudID) {
                                                if ($cloudID === $row['share_with']) {