Skip to content

Commit

Permalink
Make enhancing entries with type property optional
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Oct 23, 2018
1 parent 84e9e58 commit 4786e00
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
13 changes: 9 additions & 4 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public function getDisplayName() {
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;
Expand Down Expand Up @@ -220,7 +222,7 @@ protected function createEmptyVCard($uid) {
* @param VCard $vCard
* @return array
*/
protected function vCard2Array($uri, VCard $vCard) {
protected function vCard2Array($uri, VCard $vCard, $withTypes = false) {
$result = [
'URI' => $uri,
];
Expand Down Expand Up @@ -256,8 +258,11 @@ protected function vCard2Array($uri, VCard $vCard) {
}

$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();
}
Expand Down
11 changes: 8 additions & 3 deletions lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
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 . ')';
}
Expand Down Expand Up @@ -163,7 +168,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result['exact'][] = [
'label' => $displayName,
'uuid' => $contact['UID'],
'type' => $type,
'type' => $emailAddressType,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $emailAddress,
Expand All @@ -173,7 +178,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result['wide'][] = [
'label' => $displayName,
'uuid' => $contact['UID'],
'type' => $type,
'type' => $emailAddressType,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $emailAddress,
Expand Down
17 changes: 13 additions & 4 deletions lib/private/Collaboration/Collaborators/RemotePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ class RemotePlugin implements ISearchPlugin {
private $cloudIdManager;
/** @var IConfig */
private $config;
/** @var string */
private $userId;

public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
$this->contactsManager = $contactsManager;
$this->cloudIdManager = $cloudIdManager;
$this->config = $config;
$this->userId = \OC::$server->getUserSession()->getUser()->getUID();

$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
}
Expand All @@ -63,11 +66,17 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
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) {
Expand All @@ -87,7 +96,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result['exact'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'uuid' => $contact['UID'],
'type' => $type,
'type' => $cloudIdType,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
'shareWith' => $cloudId,
Expand All @@ -98,7 +107,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
$result['wide'][] = [
'label' => $contact['FN'] . " ($cloudId)",
'uuid' => $contact['UID'],
'type' => $type,
'type' => $cloudIdType,
'value' => [
'shareType' => Share::SHARE_TYPE_REMOTE,
'shareWith' => $cloudId,
Expand Down
14 changes: 8 additions & 6 deletions lib/public/IAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ public function getDisplayName();
/**
* @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' => '[email protected]']]
* @return array an array of contacts which are arrays of key-value-pairs
* example result:
* [
* ['id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => '[email protected]', 'GEO' => '37.386013;-122.082932'],
* ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['[email protected]', '[email protected]']]
* ]
* @since 5.0.0
*/
public function search($pattern, $searchProperties, $options);
// // dummy results
// return array(
// array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => '[email protected]', 'GEO' => '37.386013;-122.082932'),
// array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('[email protected]', '[email protected]')),
// );

/**
* @param array $properties this array if key-value-pairs defines a contact
Expand Down

0 comments on commit 4786e00

Please sign in to comment.