diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-04-18 11:23:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 11:23:30 +0200 |
commit | 7af6507f68e8076c4fb7f8832d92c93456c4cece (patch) | |
tree | 94edf586666852ef3fb8044db496f121589289f0 | |
parent | a27b61a0c7d800c617d3f1bae087deeb0d54e95a (diff) | |
parent | ef7064256f0d8fa6cd09872f93d12efac8827e14 (diff) | |
download | nextcloud-server-7af6507f68e8076c4fb7f8832d92c93456c4cece.tar.gz nextcloud-server-7af6507f68e8076c4fb7f8832d92c93456c4cece.zip |
Merge pull request #20532 from nextcloud/backport/20529/stable17
[stable17] Update list of multiple properties
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 29 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/AddressBookImplTest.php | 87 |
2 files changed, 95 insertions, 21 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 21455fc3863..3c6138e029e 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -2,9 +2,14 @@ /** * @copyright Copyright (c) 2016, ownCloud, Inc. * + * @author Arne Hamann <kontakt+github@arne.email> * @author Björn Schießle <bjoern@schiessle.org> + * @author Daniel Kesselberg <mail@danielkesselberg.de> * @author Georg Ehrke <oc.list@georgehrke.com> * @author Joas Schilling <coding@schilljs.com> + * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * @author Julius Härtl <jus@bitgrid.net> + * @author labor4 <schreibtisch@labor4.ch> * @author Thomas Müller <thomas.mueller@tmit.eu> * * @license AGPL-3.0 @@ -19,7 +24,7 @@ * 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/> + * along with this program. If not, see <http://www.gnu.org/licenses/> * */ @@ -162,7 +167,7 @@ class AddressBookImpl implements IAddressBook { $permissions = $this->addressBook->getACL(); $result = 0; foreach ($permissions as $permission) { - switch($permission['privilege']) { + switch ($permission['privilege']) { case '{DAV:}read': $result |= Constants::PERMISSION_READ; break; @@ -237,6 +242,7 @@ class AddressBookImpl implements IAddressBook { * * @param string $uri * @param VCard $vCard + * @param boolean $withTypes (optional) return the values as arrays of value/type pairs * @return array */ protected function vCard2Array($uri, VCard $vCard, $withTypes = false) { @@ -256,20 +262,7 @@ class AddressBookImpl implements IAddressBook { ]) . '?photo'; $result['PHOTO'] = 'VALUE=uri:' . $url; - - } else if ($property->name === 'X-SOCIALPROFILE') { - $type = $this->getTypeFromProperty($property); - - // Type is the social network, when it's empty we don't need this. - if ($type !== null) { - if (!isset($result[$property->name])) { - $result[$property->name] = []; - } - $result[$property->name][$type] = $property->getValue(); - } - - // The following properties can be set multiple times - } else if (in_array($property->name, ['CLOUD', 'EMAIL', 'IMPP', 'TEL', 'URL', 'X-ADDRESSBOOKSERVER-MEMBER'])) { + } elseif (in_array($property->name, ['URL', 'GEO', 'CLOUD', 'ADR', 'EMAIL', 'IMPP', 'TEL', 'X-SOCIALPROFILE', 'RELATED', 'LANG', 'X-ADDRESSBOOKSERVER-MEMBER'])) { if (!isset($result[$property->name])) { $result[$property->name] = []; } @@ -279,12 +272,10 @@ class AddressBookImpl implements IAddressBook { $result[$property->name][] = [ 'type' => $type, 'value' => $property->getValue() - ]; + ]; } else { $result[$property->name][] = $property->getValue(); } - - } else { $result[$property->name] = $property->getValue(); } diff --git a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php index 89253ce9dc9..30066b3cfe8 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php @@ -326,6 +326,9 @@ class AddressBookImplTest extends TestCase { $property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example'); $property->add('TYPE', 'twitter'); $vCard->add($property); + $property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example-2'); + $property->add('TYPE', 'twitter'); + $vCard->add($property); $property = $vCard->createProperty('X-SOCIALPROFILE', 'fb-example'); $property->add('TYPE', 'facebook'); $vCard->add($property); @@ -360,8 +363,88 @@ class AddressBookImplTest extends TestCase { ], 'X-SOCIALPROFILE' => [ - 'twitter'=> 'tw-example', - 'facebook'=> 'fb-example', + 'tw-example', + 'tw-example-2', + 'fb-example', + ], + + 'isLocalSystemBook' => true, + ], $array); + } + + public function testVCard2ArrayWithTypes() { + $vCard = new VCard(); + + $vCard->add($vCard->createProperty('FN', 'Full Name')); + + // Multi-value properties + $vCard->add($vCard->createProperty('CLOUD', 'cloud-user1@localhost')); + $vCard->add($vCard->createProperty('CLOUD', 'cloud-user2@example.tld')); + + $property = $vCard->createProperty('EMAIL', 'email-user1@localhost'); + $property->add('TYPE', 'HOME'); + $vCard->add($property); + $property = $vCard->createProperty('EMAIL', 'email-user2@example.tld'); + $property->add('TYPE', 'WORK'); + $vCard->add($property); + + $vCard->add($vCard->createProperty('IMPP', 'impp-user1@localhost')); + $vCard->add($vCard->createProperty('IMPP', 'impp-user2@example.tld')); + + $property = $vCard->createProperty('TEL', '+49 123456789'); + $property->add('TYPE', 'HOME,VOICE'); + $vCard->add($property); + $property = $vCard->createProperty('TEL', '+1 555 123456789'); + $property->add('TYPE', 'WORK'); + $vCard->add($property); + + $vCard->add($vCard->createProperty('URL', 'https://localhost')); + $vCard->add($vCard->createProperty('URL', 'https://example.tld')); + + // Type depending properties + $property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example'); + $property->add('TYPE', 'twitter'); + $vCard->add($property); + $property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example-2'); + $property->add('TYPE', 'twitter'); + $vCard->add($property); + $property = $vCard->createProperty('X-SOCIALPROFILE', 'fb-example'); + $property->add('TYPE', 'facebook'); + $vCard->add($property); + + $array = $this->invokePrivate($this->addressBookImpl, 'vCard2Array', ['uri', $vCard, true]); + unset($array['PRODID']); + unset($array['UID']); + + $this->assertEquals([ + 'URI' => 'uri', + 'VERSION' => '4.0', + 'FN' => 'Full Name', + 'CLOUD' => [ + ['type' => '', 'value' => 'cloud-user1@localhost'], + ['type' => '', 'value' => 'cloud-user2@example.tld'], + ], + 'EMAIL' => [ + ['type' => 'HOME', 'value' => 'email-user1@localhost'], + ['type' => 'WORK', 'value' => 'email-user2@example.tld'], + ], + 'IMPP' => [ + ['type' => '', 'value' => 'impp-user1@localhost'], + ['type' => '', 'value' => 'impp-user2@example.tld'], + ], + 'TEL' => [ + ['type' => 'HOME,VOICE', 'value' => '+49 123456789'], + ['type' => 'WORK', 'value' => '+1 555 123456789'], + ], + 'URL' => [ + ['type' => '', 'value' => 'https://localhost'], + ['type' => '', 'value' => 'https://example.tld'], + ], + + 'X-SOCIALPROFILE' => [ + ['type' => 'twitter', 'value' => 'tw-example'], + ['type' => 'twitter', 'value' => 'tw-example-2'], + ['type' => 'facebook', 'value' => 'fb-example'], ], 'isLocalSystemBook' => true, |