]> 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)
committerJoas Schilling <coding@schilljs.com>
Mon, 13 Dec 2021 12:48:55 +0000 (13:48 +0100)
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 fa0119010cf91c7fe2b68d4200c26fecff619d9c..5e57b77b64a431ab23ea0bee86848b20a200eb12 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 8f3a5a4f417c4c0578543f4aa77747155c3bedcd..a7db85a0de1ecb543aefb0cbc521f4fa645c6c7b 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 948d629c8fc99dda6f41a0eb2a854af7a3c1ffc2..e61bdffadcd520d494799254787e62704a1e572c 100644 (file)
@@ -203,7 +203,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 c9853f1e12c17c74a4f3068889d978a1f41c274b..4d60a78ce954c43be6f3b0763044b00608bea623 100644 (file)
@@ -334,8 +334,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 86a7d479899202d6522e28421661cc3ea878b254..0a837400725856c978d09b68add7a708cc4a6876 100644 (file)
@@ -4417,7 +4417,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' => [
@@ -4427,7 +4431,11 @@ class ShareAPIControllerTest extends TestCase {
                                                ],
                                        ],
                                ],
-                               ['user@server.com', ['EMAIL'], [],
+                               ['user@server.com', ['EMAIL'], [
+                                       'limit' => 1,
+                                       'enumeration' => false,
+                                       'strict_search' => true,
+                               ],
                                        [
                                                [
                                                        'EMAIL' => [
index ff012654834d42b020d1d26bbf7db8a4bcf322a1..3992f0f942b51a4f11afd14153ec8ee3af89ba00 100644 (file)
@@ -362,7 +362,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 4fe62523b66013e5c53b0ba30827f6ca42d45376..7d7a013a38c84523f78e28d9fff0d50e8066d1e2 100644 (file)
@@ -67,7 +67,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 cd1cc9b6169a934fe19035426c2cf8e413608fbb..a27c2ae455a0e6ea39a5f9dc0ec74c56cd7f88ec 100644 (file)
@@ -96,7 +96,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;
                }
@@ -270,7 +273,9 @@ class ContactsStore implements IContactsStore {
                                return null;
                }
 
-               $contacts = $this->contactsManager->search($shareWith, $filter);
+               $contacts = $this->contactsManager->search($shareWith, $filter, [
+                       'strict_search' => true,
+               ]);
                $match = null;
 
                foreach ($contacts as $contact) {
index 24437456fd028124cd4eb1a9304bef8f87635a46..77bb9437ba290426c3cabede418716736a5e85b6 100644 (file)
@@ -90,7 +90,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 a857a850f9b7bff1a960280c5b4437ab769e71ae..548c8a2c4517f3f70e9acbea676b604bcd841980 100644 (file)
@@ -593,7 +593,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']) {