aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/ContactsManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/ContactsManager.php')
-rw-r--r--lib/private/ContactsManager.php102
1 files changed, 35 insertions, 67 deletions
diff --git a/lib/private/ContactsManager.php b/lib/private/ContactsManager.php
index 937fb94a09a..87b341ac36b 100644
--- a/lib/private/ContactsManager.php
+++ b/lib/private/ContactsManager.php
@@ -1,37 +1,18 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Tobia De Koninck <tobia@ledfan.be>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC;
use OCP\Constants;
use OCP\Contacts\IManager;
use OCP\IAddressBook;
+use OCP\IAddressBookEnabled;
class ContactsManager implements IManager {
-
/**
* This function is used to search and find contacts within the users address books.
* In case $pattern is empty all contacts will be returned.
@@ -39,32 +20,40 @@ class ContactsManager implements IManager {
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
* @param array $options = array() to define the search behavior
- * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
- * - 'limit' - Set a numeric limit for the search results
- * - 'offset' - Set the offset for the limited search results
- * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
- * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed
- * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
- * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
+ * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
+ * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
+ * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
+ * - 'limit' - Set a numeric limit for the search results
+ * - 'offset' - Set the offset for the limited search results
+ * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
+ * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed
+ * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
+ * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
* @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($pattern, $searchProperties = [], $options = []) {
$this->loadAddressBooks();
$result = [];
foreach ($this->addressBooks as $addressBook) {
+ if ($addressBook instanceof IAddressBookEnabled && !$addressBook->isEnabled()) {
+ continue;
+ }
$searchOptions = $options;
$strictSearch = array_key_exists('strict_search', $options) && $options['strict_search'] === true;
if ($addressBook->isSystemAddressBook()) {
+ $enumeration = !\array_key_exists('enumeration', $options) || $options['enumeration'] !== false;
$fullMatch = !\array_key_exists('fullmatch', $options) || $options['fullmatch'] !== false;
- if (!$fullMatch) {
- // Neither full match is allowed, so skip the system address book
+
+ if (!$enumeration && !$fullMatch) {
+ // No access to system address book AND no full match allowed
continue;
}
+
if ($strictSearch) {
$searchOptions['wildcard'] = false;
} else {
- $searchOptions['wildcard'] = !\array_key_exists('enumeration', $options) || $options['enumeration'] !== false;
+ $searchOptions['wildcard'] = $enumeration;
}
} else {
$searchOptions['wildcard'] = !$strictSearch;
@@ -85,21 +74,21 @@ class ContactsManager implements IManager {
/**
* This function can be used to delete the contact identified by the given id
*
- * @param object $id the unique identifier to a contact
- * @param string $address_book_key identifier of the address book in which the contact shall be deleted
+ * @param int $id the unique identifier to a contact
+ * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
* @return bool successful or not
*/
- public function delete($id, $address_book_key) {
- $addressBook = $this->getAddressBook($address_book_key);
+ public function delete($id, $addressBookKey) {
+ $addressBook = $this->getAddressBook($addressBookKey);
if (!$addressBook) {
- return null;
+ return false;
}
if ($addressBook->getPermissions() & Constants::PERMISSION_DELETE) {
return $addressBook->delete($id);
}
- return null;
+ return false;
}
/**
@@ -107,11 +96,11 @@ class ContactsManager implements IManager {
* Otherwise the contact will be updated by replacing the entire data set.
*
* @param array $properties this array if key-value-pairs defines a contact
- * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
- * @return array representing the contact just created or updated
+ * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
+ * @return ?array representing the contact just created or updated
*/
- public function createOrUpdate($properties, $address_book_key) {
- $addressBook = $this->getAddressBook($address_book_key);
+ public function createOrUpdate($properties, $addressBookKey) {
+ $addressBook = $this->getAddressBook($addressBookKey);
if (!$addressBook) {
return null;
}
@@ -128,7 +117,7 @@ class ContactsManager implements IManager {
*
* @return bool true if enabled, false if not
*/
- public function isEnabled() {
+ public function isEnabled(): bool {
return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
}
@@ -147,24 +136,6 @@ class ContactsManager implements IManager {
}
/**
- * Return a list of the user's addressbooks display names
- * ! The addressBook displayName are not unique, please use getUserAddressBooks
- *
- * @return IAddressBook[]
- * @since 6.0.0
- * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead
- */
- public function getAddressBooks() {
- $this->loadAddressBooks();
- $result = [];
- foreach ($this->addressBooks as $addressBook) {
- $result[$addressBook->getKey()] = $addressBook->getDisplayName();
- }
-
- return $result;
- }
-
- /**
* Return a list of the user's addressbooks
*
* @return IAddressBook[]
@@ -205,11 +176,8 @@ class ContactsManager implements IManager {
/**
* Get (and load when needed) the address book for $key
- *
- * @param string $addressBookKey
- * @return IAddressBook
*/
- protected function getAddressBook($addressBookKey) {
+ protected function getAddressBook(string $addressBookKey): ?IAddressBook {
$this->loadAddressBooks();
if (!array_key_exists($addressBookKey, $this->addressBooks)) {
return null;