]> source.dussan.org Git - nextcloud-server.git/commitdiff
don't add empty values to the vcard
authorBjoern Schiessle <bjoern@schiessle.org>
Mon, 13 Mar 2017 13:58:37 +0000 (14:58 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Fri, 24 Mar 2017 10:06:44 +0000 (11:06 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/dav/lib/CardDAV/Converter.php
apps/dav/tests/unit/CardDAV/ConverterTest.php
apps/dav/tests/unit/CardDAV/SyncServiceTest.php

index 0f8ea799f1e599fe371d70865ba2c0dfc2b93b49..eb43fe7d671596ace3e3b6908e5999af7b605ffd 100644 (file)
@@ -61,9 +61,15 @@ class Converter {
                $publish = false;
 
                foreach ($userData as $property => $value) {
-                       if ($value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
-                               $value['scope'] === AccountManager::VISIBILITY_PUBLIC
-                       ) {
+
+                       $shareWithTrustedServers =
+                               $value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
+                               $value['scope'] === AccountManager::VISIBILITY_PUBLIC;
+
+                       $emptyValue = !isset($value['value']) || $value['value'] === '';
+                       $noImage = $image === null;
+
+                       if ($shareWithTrustedServers && (!$emptyValue || !$noImage)) {
                                $publish = true;
                                switch ($property) {
                                        case AccountManager::PROPERTY_DISPLAYNAME:
index 528b3aa9ef4ed09f669f361a62b1bb6160dc9fe7..ff218bfc78c048e7b2a8bfde18b74a29d45005d8 100644 (file)
@@ -173,6 +173,16 @@ class ConverterTest extends  TestCase {
                                null,
                                "foo@cloud.net"
                        ],
+                       [
+                               [
+                                       'cloud' => 'foo@cloud.net',
+                                       'fn' => 'Dr. Foo Bar',
+                                       'photo' => 'data:image/jpeg;base64,MTIzNDU2Nzg5',
+                               ],
+                               'Dr. Foo Bar',
+                               '',
+                               'foo@cloud.net'
+                       ],
                ];
        }
 
index 68345def66b85fa5783581c220004a52180bb344..de4e8ead4c0b6a0f25c81e6bcbb2caf94419843d 100644 (file)
@@ -103,50 +103,50 @@ class SyncServiceTest extends TestCase {
                $user->method('getBackendClassName')->willReturn('unittest');
                $user->method('getUID')->willReturn('test-user');
                $user->method('getCloudId')->willReturn('cloudId');
+               $user->method('getDisplayName')->willReturn('test-user');
                $accountManager = $this->getMockBuilder('OC\Accounts\AccountManager')->disableOriginalConstructor()->getMock();
                $accountManager->expects($this->any())->method('getUser')
                        ->willReturn([
-                               AccountManager::PROPERTY_DISPLAYNAME =>
-                                       [
-                                               'value' => $user->getDisplayName(),
-                                               'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
-                                       ],
-                               AccountManager::PROPERTY_ADDRESS =>
-                                       [
-                                               'value' => '',
-                                               'scope' => AccountManager::VISIBILITY_PRIVATE,
-                                       ],
-                               AccountManager::PROPERTY_WEBSITE =>
-                                       [
-                                               'value' => '',
-                                               'scope' => AccountManager::VISIBILITY_PRIVATE,
-                                       ],
-                               AccountManager::PROPERTY_EMAIL =>
-                                       [
-                                               'value' => $user->getEMailAddress(),
-                                               'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
-                                       ],
-                               AccountManager::PROPERTY_AVATAR =>
-                                       [
-                                               'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
-                                       ],
-                               AccountManager::PROPERTY_PHONE =>
-                                       [
-                                               'value' => '',
-                                               'scope' => AccountManager::VISIBILITY_PRIVATE,
-                                       ],
-                               AccountManager::PROPERTY_TWITTER =>
-                                       [
-                                               'value' => '',
-                                               'scope' => AccountManager::VISIBILITY_PRIVATE,
-                                       ],
-                       ]);
+                                       AccountManager::PROPERTY_DISPLAYNAME =>
+                                               [
+                                                       'value' => $user->getDisplayName(),
+                                                       'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
+                                               ],
+                                       AccountManager::PROPERTY_ADDRESS =>
+                                               [
+                                                       'value' => '',
+                                                       'scope' => AccountManager::VISIBILITY_PRIVATE,
+                                               ],
+                                       AccountManager::PROPERTY_WEBSITE =>
+                                               [
+                                                       'value' => '',
+                                                       'scope' => AccountManager::VISIBILITY_PRIVATE,
+                                               ],
+                                       AccountManager::PROPERTY_EMAIL =>
+                                               [
+                                                       'value' => $user->getEMailAddress(),
+                                                       'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
+                                               ],
+                                       AccountManager::PROPERTY_AVATAR =>
+                                               [
+                                                       'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
+                                               ],
+                                       AccountManager::PROPERTY_PHONE =>
+                                               [
+                                                       'value' => '',
+                                                       'scope' => AccountManager::VISIBILITY_PRIVATE,
+                                               ],
+                                       AccountManager::PROPERTY_TWITTER =>
+                                               [
+                                                       'value' => '',
+                                                       'scope' => AccountManager::VISIBILITY_PRIVATE,
+                                               ],
+                               ]
+                       );
 
                $ss = new SyncService($backend, $userManager, $logger, $accountManager);
                $ss->updateUser($user);
 
-               $user->method('getDisplayName')->willReturn('A test user for unit testing');
-
                $ss->updateUser($user);
 
                $ss->deleteUser($user);