'principals/'
);
$db = \OC::$server->getDatabaseConnection();
-$cardDavBackend = new CardDavBackend($db, $principalBackend);
+$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager());
$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
$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) {
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;
'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;
*
* @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');
}
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'],
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
*/
\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;
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
private $principal;
+ /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
+
/** @var IDBConnection */
private $db;
public function setUp() {
parent::setUp();
+ $this->userManager = $this->getMockBuilder('OCP\IUserManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
$this->db = \OC::$server->getDatabaseConnection();
- $this->backend = new CardDavBackend($this->db, $this->principal, null);
+ $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, null);
// start every test with a empty cards_properties and cards table
$query = $this->db->getQueryBuilder();
/** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
$backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
- ->setConstructorArgs([$this->db, $this->principal, null])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null])
->setMethods(['updateProperties', 'purgeProperties'])->getMock();
// create a new address book
public function testMultiCard() {
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
- ->setConstructorArgs([$this->db, $this->principal, null])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null])
->setMethods(['updateProperties'])->getMock();
// create a new address book
public function testDeleteWithoutCard() {
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
- ->setConstructorArgs([$this->db, $this->principal, null])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null])
->setMethods([
'getCardId',
'addChange',
public function testSyncSupport() {
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
- ->setConstructorArgs([$this->db, $this->principal, null])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null])
->setMethods(['updateProperties'])->getMock();
// create a new address book
$cardId = 2;
$backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
- ->setConstructorArgs([$this->db, $this->principal, null])
+ ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null])
->setMethods(['getCardId'])->getMock();
$backend->expects($this->any())->method('getCardId')->willReturn($cardId);