diff options
author | Joas Schilling <coding@schilljs.com> | 2016-08-18 15:14:04 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-24 08:50:25 +0200 |
commit | 3fbb5de74fcdc5cefc88b05a11a8efc66ea2f565 (patch) | |
tree | 7cac5241f71944dfeb434c2eb7e4169575982d1d /apps/dav/lib | |
parent | 53182fb780dbec9ac98f1e6f137201c6348a99cc (diff) | |
download | nextcloud-server-3fbb5de74fcdc5cefc88b05a11a8efc66ea2f565.tar.gz nextcloud-server-3fbb5de74fcdc5cefc88b05a11a8efc66ea2f565.zip |
Better displaynames for shared address books
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/AppInfo/Application.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 29 | ||||
-rw-r--r-- | apps/dav/lib/RootCollection.php | 4 |
3 files changed, 31 insertions, 4 deletions
diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index e1a01f12361..17145847fa1 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -87,7 +87,7 @@ class Application extends App { $c->getServer()->getUserManager(), $c->getServer()->getGroupManager() ); - return new CardDavBackend($db, $principal, $dispatcher); + return new CardDavBackend($db, $principal, $c->getServer()->getUserManager(), $dispatcher); }); $container->registerService('CalDavBackend', function($c) { diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index f8552f1323e..f6d80dfe701 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -33,6 +33,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\DAV\Sharing\Backend; use OCA\DAV\DAV\Sharing\IShareable; use OCP\IDBConnection; +use OCP\IUser; +use OCP\IUserManager; use PDO; use Sabre\CardDAV\Backend\BackendInterface; use Sabre\CardDAV\Backend\SyncSupport; @@ -66,6 +68,14 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME', 'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO', 'CLOUD'); + /** + * @var string[] Map of uid => display name + */ + protected $userDisplayNames; + + /** @var IUserManager */ + private $userManager; + /** @var EventDispatcherInterface */ private $dispatcher; @@ -74,13 +84,16 @@ class CardDavBackend implements BackendInterface, SyncSupport { * * @param IDBConnection $db * @param Principal $principalBackend + * @param IUserManager $userManager * @param EventDispatcherInterface $dispatcher */ public function __construct(IDBConnection $db, Principal $principalBackend, + IUserManager $userManager, EventDispatcherInterface $dispatcher = null) { $this->db = $db; $this->principalBackend = $principalBackend; + $this->userManager = $userManager; $this->dispatcher = $dispatcher; $this->sharingBackend = new Backend($this->db, $principalBackend, 'addressbook'); } @@ -143,7 +156,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { while($row = $result->fetch()) { list(, $name) = URLUtil::splitPath($row['principaluri']); $uri = $row['uri'] . '_shared_by_' . $name; - $displayName = $row['displayname'] . "($name)"; + $displayName = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; if (!isset($addressBooks[$row['id']])) { $addressBooks[$row['id']] = [ 'id' => $row['id'], @@ -163,6 +176,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { return array_values($addressBooks); } + private function getUserDisplayName($uid) { + if (!isset($this->userDisplayNames[$uid])) { + $user = $this->userManager->get($uid); + + if ($user instanceof IUser) { + $this->userDisplayNames[$uid] = $user->getDisplayName(); + } else { + $this->userDisplayNames[$uid] = $uid; + } + } + + return $this->userDisplayNames[$uid]; + } + /** * @param int $addressBookId */ diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index de3f7e2a857..974d08bc34f 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -83,11 +83,11 @@ class RootCollection extends SimpleCollection { \OC::$server->getLogger() ); - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); $usersAddressBookRoot->disableListing = $disableListing; - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); $systemAddressBookRoot->disableListing = $disableListing; |