Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more personal information fields to the settings page for enhanced federated sharing #1946

Merged
merged 53 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c42d977
Add more personal information fields to the settings page for enhance…
ChristophWurst Apr 20, 2016
20739c9
Persist settings on the server
ChristophWurst Apr 20, 2016
78f6e29
Add federation scope to the user avatar
ChristophWurst Apr 21, 2016
d1233b4
use PUT to update user settings
ChristophWurst Apr 21, 2016
40b9973
introduce accounts table and keep it up-to-date with the data added t…
Apr 25, 2016
445a254
display stored user data
Apr 25, 2016
1700e3d
allow multiple values for phone, website, address and email
Apr 25, 2016
de1f3f0
allow to change display names in the user settings again
Apr 26, 2016
51b5f27
increase version to trigger db migration
ChristophWurst Oct 31, 2016
9c7533f
fix profile picture fed sharing scope menu
ChristophWurst Oct 31, 2016
77c034f
remove double import
ChristophWurst Nov 7, 2016
9177420
Fix popover layout
skjnldsv Nov 7, 2016
b75ef0f
Fix popover layout fix for files and global
skjnldsv Nov 7, 2016
987995a
Fix popup arrow positioning
skjnldsv Nov 7, 2016
8f33d9d
update system address book if the user change the personal settings
schiessle Nov 11, 2016
f7a4db5
fix avatar cropper
icewind1991 Nov 15, 2016
3f8bfbd
change order of email and phone number
schiessle Nov 16, 2016
f489fd9
change scope to 'local' for display name and avatar
schiessle Nov 16, 2016
a15809c
Fix location of menu
rullzer Nov 16, 2016
845f0bd
Fix position of menu
rullzer Nov 16, 2016
08e6541
fix unit tests
schiessle Nov 16, 2016
3a88087
update unit tests
schiessle Nov 17, 2016
c5e6194
remove old test class
schiessle Nov 17, 2016
fa87b2f
limit max-width to have never more than two input fields next to each…
schiessle Nov 17, 2016
061ef0c
rearrange input fields
schiessle Nov 17, 2016
b23a4ca
push public user data to the lookup server
schiessle Nov 17, 2016
0690234
lookup server connector
schiessle Nov 17, 2016
056ce51
Fix password display issue
rullzer Nov 17, 2016
53c8391
Add private
LukasReschke Nov 17, 2016
6f4cb12
Add identity proof
LukasReschke Nov 17, 2016
a32d6e4
fix unit tests
schiessle Nov 17, 2016
fb91bf6
Add a signer class for signing
LukasReschke Nov 18, 2016
662dff0
Adjust permission checks
LukasReschke Nov 18, 2016
8bf4111
Fix changing display names for subadmins
LukasReschke Nov 18, 2016
f7f7002
Search on lookup server
rullzer Nov 18, 2016
c20c7f3
Push json to the lookupserver
rullzer Nov 18, 2016
e53e585
put explanatory text directly in popup
jancborchardt Nov 18, 2016
15c075e
Fix lookup url
rullzer Nov 18, 2016
f062c6d
fix menu positioning hack
jancborchardt Nov 18, 2016
6e783f8
make icons a bit smaller
jancborchardt Nov 18, 2016
dac9801
Add retry job
LukasReschke Nov 18, 2016
c49b0d3
Remove unused variable
LukasReschke Nov 18, 2016
7b3855a
Add config switch
LukasReschke Nov 18, 2016
ccf3e42
Remove debug code
LukasReschke Nov 18, 2016
a0c6404
Make JS aware of password verification
LukasReschke Nov 18, 2016
5acc3d3
Highlight current entry
LukasReschke Nov 18, 2016
e87933b
Fix mail scope
LukasReschke Nov 18, 2016
16181c5
Ask for password when scope is changed
LukasReschke Nov 18, 2016
d04ec92
Adjust integration test
LukasReschke Nov 18, 2016
d001dbd
Adjust unit tests
LukasReschke Nov 19, 2016
5aed91c
small fixes
schiessle Nov 21, 2016
4a05aa8
don't try to verify email address if no email address is set
schiessle Nov 21, 2016
a1ca54a
center checkmark to indicate that the setting was stored
schiessle Nov 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
!/apps/files_sharing
!/apps/files_trashbin
!/apps/files_versions
!/apps/lookup_server_connector
!/apps/user_ldap
!/apps/provisioning_api
!/apps/systemtags
Expand Down
6 changes: 6 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public function registerHooks() {
}
});

$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
$user = $event->getSubject();
$syncService = $this->getContainer()->query(SyncService::class);
$syncService->updateUser($user);
});

$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
/** @var Backend $backend */
$backend = $this->getContainer()->query(Backend::class);
Expand Down
144 changes: 56 additions & 88 deletions apps/dav/lib/CardDAV/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,116 +22,84 @@

namespace OCA\DAV\CardDAV;

use OC\Accounts\AccountManager;
use OCP\IImage;
use OCP\IUser;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;

class Converter {

/** @var AccountManager */
private $accountManager;

/**
* @param IUser $user
* @return VCard
* Converter constructor.
*
* @param AccountManager $accountManager
*/
public function createCardFromUser(IUser $user) {

$uid = $user->getUID();
$displayName = $user->getDisplayName();
$displayName = empty($displayName ) ? $uid : $displayName;
$emailAddress = $user->getEMailAddress();
$cloudId = $user->getCloudId();
$image = $this->getAvatarImage($user);

$vCard = new VCard();
$vCard->VERSION = '3.0';
$vCard->UID = $uid;
if (!empty($displayName)) {
$vCard->FN = $displayName;
$vCard->N = $this->splitFullName($displayName);
}
if (!empty($emailAddress)) {
$vCard->add(new Text($vCard, 'EMAIL', $emailAddress, ['TYPE' => 'OTHER']));
}
if (!empty($cloudId)) {
$vCard->CLOUD = $cloudId;
}
if ($image) {
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
}
$vCard->validate();

return $vCard;
public function __construct(AccountManager $accountManager) {
$this->accountManager = $accountManager;
}

/**
* @param VCard $vCard
* @param IUser $user
* @return bool
* @return VCard|null
*/
public function updateCard(VCard $vCard, IUser $user) {
public function createCardFromUser(IUser $user) {

$userData = $this->accountManager->getUser($user);

$uid = $user->getUID();
$displayName = $user->getDisplayName();
$displayName = empty($displayName ) ? $uid : $displayName;
$emailAddress = $user->getEMailAddress();
$cloudId = $user->getCloudId();
$image = $this->getAvatarImage($user);

$updated = false;
if($this->propertyNeedsUpdate($vCard, 'FN', $displayName)) {
$vCard->FN = new Text($vCard, 'FN', $displayName);
unset($vCard->N);
$vCard->add(new Text($vCard, 'N', $this->splitFullName($displayName)));
$updated = true;
}
if($this->propertyNeedsUpdate($vCard, 'EMAIL', $emailAddress)) {
$vCard->EMAIL = new Text($vCard, 'EMAIL', $emailAddress);
$updated = true;
}
if($this->propertyNeedsUpdate($vCard, 'CLOUD', $cloudId)) {
$vCard->CLOUD = new Text($vCard, 'CLOUD', $cloudId);
$updated = true;
}

if($this->propertyNeedsUpdate($vCard, 'PHOTO', $image)) {
unset($vCard->PHOTO);
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
$updated = true;
}

if (empty($emailAddress) && !is_null($vCard->EMAIL)) {
unset($vCard->EMAIL);
$updated = true;
}
if (empty($cloudId) && !is_null($vCard->CLOUD)) {
unset($vCard->CLOUD);
$updated = true;
}
if (empty($image) && !is_null($vCard->PHOTO)) {
unset($vCard->PHOTO);
$updated = true;
$vCard = new VCard();
$vCard->add(new Text($vCard, 'UID', $uid));

$publish = false;

foreach ($userData as $property => $value) {
if ($value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
$value['scope'] === AccountManager::VISIBILITY_PUBLIC
) {
$publish = true;
switch ($property) {
case AccountManager::PROPERTY_DISPLAYNAME:
$vCard->add(new Text($vCard, 'FN', $value['value']));
$vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
break;
case AccountManager::PROPERTY_AVATAR:
if ($image !== null) {
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
}
break;
case AccountManager::PROPERTY_EMAIL:
$vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
break;
case AccountManager::PROPERTY_WEBSITE:
$vCard->add(new Text($vCard, 'URL', $value['value']));
break;
case AccountManager::PROPERTY_PHONE:
$vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
break;
case AccountManager::PROPERTY_ADDRESS:
$vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
break;
case AccountManager::PROPERTY_TWITTER:
$vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
break;
}
}
}

return $updated;
}

/**
* @param VCard $vCard
* @param string $name
* @param string|IImage $newValue
* @return bool
*/
private function propertyNeedsUpdate(VCard $vCard, $name, $newValue) {
if (is_null($newValue)) {
return false;
if ($publish && !empty($cloudId)) {
$vCard->add(new Text($vCard, 'CLOUD', $cloudId));
$vCard->validate();
return $vCard;
}
$value = $vCard->__get($name);
if (!is_null($value)) {
$value = $value->getValue();
$newValue = $newValue instanceof IImage ? $newValue->data() : $newValue;

return $value !== $newValue;
}
return true;
return null;
}

/**
Expand Down
27 changes: 22 additions & 5 deletions apps/dav/lib/CardDAV/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\DAV\CardDAV;

use OC\Accounts\AccountManager;
use OCP\AppFramework\Http;
use OCP\ILogger;
use OCP\IUser;
Expand All @@ -48,10 +49,22 @@ class SyncService {
/** @var array */
private $localSystemAddressBook;

public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger) {
/** @var AccountManager */
private $accountManager;

/**
* SyncService constructor.
*
* @param CardDavBackend $backend
* @param IUserManager $userManager
* @param ILogger $logger
* @param AccountManager $accountManager
*/
public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) {
$this->backend = $backend;
$this->userManager = $userManager;
$this->logger = $logger;
$this->accountManager = $accountManager;
}

/**
Expand Down Expand Up @@ -215,18 +228,22 @@ private function parseMultiStatus($body) {
public function updateUser($user) {
$systemAddressBook = $this->getLocalSystemAddressBook();
$addressBookId = $systemAddressBook['id'];
$converter = new Converter();
$converter = new Converter($this->accountManager);
$name = $user->getBackendClassName();
$userId = $user->getUID();

$cardId = "$name:$userId.vcf";
$card = $this->backend->getCard($addressBookId, $cardId);
if ($card === false) {
$vCard = $converter->createCardFromUser($user);
$this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
if ($vCard !== null) {
$this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
}
} else {
$vCard = Reader::read($card['carddata']);
if ($converter->updateCard($vCard, $user)) {
$vCard = $converter->createCardFromUser($user);
if (is_null($vCard)) {
$this->backend->deleteCard($addressBookId, $cardId);
} else {
$this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
}
}
Expand Down
9 changes: 8 additions & 1 deletion apps/dav/lib/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;

class HookManager {

Expand All @@ -51,14 +53,19 @@ class HookManager {
/** @var array */
private $addressBooksToDelete;

/** @var EventDispatcher */
private $eventDispatcher;

public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
CardDavBackend $cardDav) {
CardDavBackend $cardDav,
EventDispatcher $eventDispatcher) {
$this->userManager = $userManager;
$this->syncService = $syncService;
$this->calDav = $calDav;
$this->cardDav = $cardDav;
$this->eventDispatcher = $eventDispatcher;
}

public function setup() {
Expand Down
Loading