summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/CardDAV/AddressBookImpl.php13
-rw-r--r--lib/private/Collaboration/Collaborators/MailPlugin.php11
-rw-r--r--lib/private/Collaboration/Collaborators/RemotePlugin.php19
-rw-r--r--lib/public/IAddressBook.php14
-rw-r--r--tests/lib/Collaboration/Collaborators/RemotePluginTest.php36
5 files changed, 69 insertions, 24 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php
index e9946e65aba..4f2491e1895 100644
--- a/apps/dav/lib/CardDAV/AddressBookImpl.php
+++ b/apps/dav/lib/CardDAV/AddressBookImpl.php
@@ -95,9 +95,11 @@ class AddressBookImpl implements IAddressBook {
public function search($pattern, $searchProperties, $options) {
$results = $this->backend->search($this->getKey(), $pattern, $searchProperties);
+ $withTypes = \array_key_exists('types', $options) && $options['types'] === true;
+
$vCards = [];
foreach ($results as $result) {
- $vCards[] = $this->vCard2Array($result['uri'], $this->readCard($result['carddata']));
+ $vCards[] = $this->vCard2Array($result['uri'], $this->readCard($result['carddata']), $withTypes);
}
return $vCards;
@@ -220,7 +222,7 @@ class AddressBookImpl implements IAddressBook {
* @param VCard $vCard
* @return array
*/
- protected function vCard2Array($uri, VCard $vCard) {
+ protected function vCard2Array($uri, VCard $vCard, $withTypes = false) {
$result = [
'URI' => $uri,
];
@@ -256,8 +258,11 @@ class AddressBookImpl implements IAddressBook {
}
$type = $this->getTypeFromProperty($property);
- if ($type !== null) {
- $result[$property->name][$type] = $property->getValue();
+ if ($withTypes) {
+ $result[$property->name][] = [
+ 'type' => $type,
+ 'value' => $property->getValue()
+ ];
} else {
$result[$property->name][] = $property->getValue();
}
diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php
index e89e22d012e..1d0738677bb 100644
--- a/lib/private/Collaboration/Collaborators/MailPlugin.php
+++ b/lib/private/Collaboration/Collaborators/MailPlugin.php
@@ -84,11 +84,16 @@ class MailPlugin implements ISearchPlugin {
foreach ($addressBookContacts as $contact) {
if (isset($contact['EMAIL'])) {
$emailAddresses = $contact['EMAIL'];
- if (!is_array($emailAddresses)) {
+ if (\is_string($emailAddresses)) {
$emailAddresses = [$emailAddresses];
}
foreach ($emailAddresses as $type => $emailAddress) {
$displayName = $emailAddress;
+ if (\is_array($emailAddress)) {
+ $emailAddressData = $emailAddress;
+ $emailAddress = $emailAddressData['value'];
+ $emailAddressType = $emailAddressData['type'];
+ }
if (isset($contact['FN'])) {
$displayName = $contact['FN'] . ' (' . $emailAddress . ')';
}
@@ -163,7 +168,7 @@ class MailPlugin implements ISearchPlugin {
$result['exact'][] = [
'label' => $displayName,
'uuid' => $contact['UID'],
- 'type' => $type,
+ 'type' => $emailAddressType,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $emailAddress,
@@ -173,7 +178,7 @@ class MailPlugin implements ISearchPlugin {
$result['wide'][] = [
'label' => $displayName,
'uuid' => $contact['UID'],
- 'type' => $type,
+ 'type' => $emailAddressType,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $emailAddress,
diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php
index bde6d15b7b6..3da6bdeb637 100644
--- a/lib/private/Collaboration/Collaborators/RemotePlugin.php
+++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php
@@ -44,12 +44,15 @@ class RemotePlugin implements ISearchPlugin {
private $config;
/** @var IUserManager */
private $userManager;
+ /** @var string */
+ private $userId;
- public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager) {
+ public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager, $userId) {
$this->contactsManager = $contactsManager;
$this->cloudIdManager = $cloudIdManager;
$this->config = $config;
$this->userManager = $userManager;
+ $this->userId = $userId;
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
}
@@ -67,11 +70,17 @@ class RemotePlugin implements ISearchPlugin {
}
if (isset($contact['CLOUD'])) {
$cloudIds = $contact['CLOUD'];
- if (!is_array($cloudIds)) {
+ if (is_string($cloudIds)) {
$cloudIds = [$cloudIds];
}
$lowerSearch = strtolower($search);
- foreach ($cloudIds as $type => $cloudId) {
+ foreach ($cloudIds as $cloudId) {
+ $cloudIdType = '';
+ if (\is_array($cloudId)) {
+ $cloudIdData = $cloudId;
+ $cloudId = $cloudIdData['value'];
+ $cloudIdType = $cloudIdData['type'];
+ }
try {
list($remoteUser, $serverUrl) = $this->splitUserRemote($cloudId);
} catch (\InvalidArgumentException $e) {
@@ -90,7 +99,7 @@ class RemotePlugin implements ISearchPlugin {
$result['exact'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'uuid' => $contact['UID'],
- 'type' => $type,
+ 'type' => $cloudIdType,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
'shareWith' => $cloudId,
@@ -101,7 +110,7 @@ class RemotePlugin implements ISearchPlugin {
$result['wide'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'uuid' => $contact['UID'],
- 'type' => $type,
+ 'type' => $cloudIdType,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
'shareWith' => $cloudId,
diff --git a/lib/public/IAddressBook.php b/lib/public/IAddressBook.php
index 67c34c9e8c9..4739e6f0c5b 100644
--- a/lib/public/IAddressBook.php
+++ b/lib/public/IAddressBook.php
@@ -55,16 +55,18 @@ namespace OCP {
/**
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
- * @param array $options - for future use. One should always have options!
+ * @param array $options Options to define the output format
+ * - 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']]
* @return array an array of contacts which are arrays of key-value-pairs
+ * example result:
+ * [
+ * ['id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'],
+ * ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['d@e.f', 'g@h.i']]
+ * ]
* @since 5.0.0
*/
public function search($pattern, $searchProperties, $options);
- // // dummy results
- // return array(
- // array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'),
- // array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('d@e.f', 'g@h.i')),
- // );
/**
* @param array $properties this array if key-value-pairs defines a contact
diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
index ac050e23562..e253f2dfc9f 100644
--- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
@@ -66,7 +66,7 @@ class RemotePluginTest extends TestCase {
}
public function instantiatePlugin() {
- $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager);
+ $this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager, 'admin');
}
/**
@@ -158,14 +158,17 @@ class RemotePluginTest extends TestCase {
'test',
[
[
+ 'UID' => 'uid',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid1',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -173,7 +176,7 @@ class RemotePluginTest extends TestCase {
],
],
true,
- ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => []]],
+ ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => []]],
false,
true,
],
@@ -181,14 +184,17 @@ class RemotePluginTest extends TestCase {
'test',
[
[
+ 'UID' => 'uid',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -204,14 +210,17 @@ class RemotePluginTest extends TestCase {
'test@remote',
[
[
+ 'UID' => 'uid',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -219,7 +228,7 @@ class RemotePluginTest extends TestCase {
],
],
true,
- ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]],
+ ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]],
false,
true,
],
@@ -227,14 +236,17 @@ class RemotePluginTest extends TestCase {
'test@remote',
[
[
+ 'UID' => 'uid',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -250,14 +262,17 @@ class RemotePluginTest extends TestCase {
'username@localhost',
[
[
+ 'UID' => 'uid3',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => '2',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid1',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -265,7 +280,7 @@ class RemotePluginTest extends TestCase {
],
],
true,
- ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]],
+ ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]],
true,
true,
],
@@ -273,14 +288,17 @@ class RemotePluginTest extends TestCase {
'username@localhost',
[
[
+ 'UID' => 'uid3',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid2',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid1',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',
@@ -288,7 +306,7 @@ class RemotePluginTest extends TestCase {
],
],
false,
- ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]],
+ ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid1', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]]]],
true,
true,
],
@@ -297,14 +315,17 @@ class RemotePluginTest extends TestCase {
'user name@localhost',
[
[
+ 'UID' => 'uid1',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid2',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid3',
'FN' => 'User Name @ Localhost',
'CLOUD' => [
'user name@localhost',
@@ -312,7 +333,7 @@ class RemotePluginTest extends TestCase {
],
],
false,
- ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user name@localhost', 'server' => 'localhost']]]]],
+ ['remotes' => [], 'exact' => ['remotes' => [['label' => 'User Name @ Localhost (user name@localhost)', 'uuid' => 'uid3', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user name@localhost', 'server' => 'localhost']]]]],
true,
true,
],
@@ -321,14 +342,17 @@ class RemotePluginTest extends TestCase {
'user space@remote',
[
[
+ 'UID' => 'uid3',
'FN' => 'User3 @ Localhost',
],
[
+ 'UID' => 'uid2',
'FN' => 'User2 @ Localhost',
'CLOUD' => [
],
],
[
+ 'UID' => 'uid1',
'FN' => 'User @ Localhost',
'CLOUD' => [
'username@localhost',