diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-03-13 14:58:37 +0100 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-03-24 11:06:44 +0100 |
commit | e6371134523b6c263b37dd70878e7256cef53ecc (patch) | |
tree | a2d02506454a0d01943162043ad523f4e1565ace /apps/dav | |
parent | 4531b4a81da81c8f1b6eb49b2669fa93088e33d9 (diff) | |
download | nextcloud-server-e6371134523b6c263b37dd70878e7256cef53ecc.tar.gz nextcloud-server-e6371134523b6c263b37dd70878e7256cef53ecc.zip |
don't add empty values to the vcard
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CardDAV/Converter.php | 12 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/ConverterTest.php | 10 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/SyncServiceTest.php | 74 |
3 files changed, 56 insertions, 40 deletions
diff --git a/apps/dav/lib/CardDAV/Converter.php b/apps/dav/lib/CardDAV/Converter.php index 0f8ea799f1e..eb43fe7d671 100644 --- a/apps/dav/lib/CardDAV/Converter.php +++ b/apps/dav/lib/CardDAV/Converter.php @@ -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: diff --git a/apps/dav/tests/unit/CardDAV/ConverterTest.php b/apps/dav/tests/unit/CardDAV/ConverterTest.php index 528b3aa9ef4..ff218bfc78c 100644 --- a/apps/dav/tests/unit/CardDAV/ConverterTest.php +++ b/apps/dav/tests/unit/CardDAV/ConverterTest.php @@ -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' + ], ]; } diff --git a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php index 68345def66b..de4e8ead4c0 100644 --- a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php +++ b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php @@ -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); |