don't add empty values to the vcard

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-03-13 14:58:37 +01:00
parent 4531b4a81d
commit e637113452
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
3 changed files with 56 additions and 40 deletions

View File

@ -61,9 +61,15 @@ class Converter {
$publish = false; $publish = false;
foreach ($userData as $property => $value) { 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; $publish = true;
switch ($property) { switch ($property) {
case AccountManager::PROPERTY_DISPLAYNAME: case AccountManager::PROPERTY_DISPLAYNAME:

View File

@ -173,6 +173,16 @@ class ConverterTest extends TestCase {
null, null,
"foo@cloud.net" "foo@cloud.net"
], ],
[
[
'cloud' => 'foo@cloud.net',
'fn' => 'Dr. Foo Bar',
'photo' => 'data:image/jpeg;base64,MTIzNDU2Nzg5',
],
'Dr. Foo Bar',
'',
'foo@cloud.net'
],
]; ];
} }

View File

@ -103,50 +103,50 @@ class SyncServiceTest extends TestCase {
$user->method('getBackendClassName')->willReturn('unittest'); $user->method('getBackendClassName')->willReturn('unittest');
$user->method('getUID')->willReturn('test-user'); $user->method('getUID')->willReturn('test-user');
$user->method('getCloudId')->willReturn('cloudId'); $user->method('getCloudId')->willReturn('cloudId');
$user->method('getDisplayName')->willReturn('test-user');
$accountManager = $this->getMockBuilder('OC\Accounts\AccountManager')->disableOriginalConstructor()->getMock(); $accountManager = $this->getMockBuilder('OC\Accounts\AccountManager')->disableOriginalConstructor()->getMock();
$accountManager->expects($this->any())->method('getUser') $accountManager->expects($this->any())->method('getUser')
->willReturn([ ->willReturn([
AccountManager::PROPERTY_DISPLAYNAME => AccountManager::PROPERTY_DISPLAYNAME =>
[ [
'value' => $user->getDisplayName(), 'value' => $user->getDisplayName(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY, 'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
], ],
AccountManager::PROPERTY_ADDRESS => AccountManager::PROPERTY_ADDRESS =>
[ [
'value' => '', 'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE, 'scope' => AccountManager::VISIBILITY_PRIVATE,
], ],
AccountManager::PROPERTY_WEBSITE => AccountManager::PROPERTY_WEBSITE =>
[ [
'value' => '', 'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE, 'scope' => AccountManager::VISIBILITY_PRIVATE,
], ],
AccountManager::PROPERTY_EMAIL => AccountManager::PROPERTY_EMAIL =>
[ [
'value' => $user->getEMailAddress(), 'value' => $user->getEMailAddress(),
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY, 'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
], ],
AccountManager::PROPERTY_AVATAR => AccountManager::PROPERTY_AVATAR =>
[ [
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY 'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
], ],
AccountManager::PROPERTY_PHONE => AccountManager::PROPERTY_PHONE =>
[ [
'value' => '', 'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE, 'scope' => AccountManager::VISIBILITY_PRIVATE,
], ],
AccountManager::PROPERTY_TWITTER => AccountManager::PROPERTY_TWITTER =>
[ [
'value' => '', 'value' => '',
'scope' => AccountManager::VISIBILITY_PRIVATE, 'scope' => AccountManager::VISIBILITY_PRIVATE,
], ],
]); ]
);
$ss = new SyncService($backend, $userManager, $logger, $accountManager); $ss = new SyncService($backend, $userManager, $logger, $accountManager);
$ss->updateUser($user); $ss->updateUser($user);
$user->method('getDisplayName')->willReturn('A test user for unit testing');
$ss->updateUser($user); $ss->updateUser($user);
$ss->deleteUser($user); $ss->deleteUser($user);