diff options
author | Joas Schilling <coding@schilljs.com> | 2016-08-18 15:10:18 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-24 08:50:25 +0200 |
commit | 53182fb780dbec9ac98f1e6f137201c6348a99cc (patch) | |
tree | d62bb38050771d701c3ee7150efa3b09961d56a4 /apps/dav | |
parent | 2f1b17d44a854221a4b3c461df80d0522ac3c8b5 (diff) | |
download | nextcloud-server-53182fb780dbec9ac98f1e6f137201c6348a99cc.tar.gz nextcloud-server-53182fb780dbec9ac98f1e6f137201c6348a99cc.zip |
Better displaynames for shared calendars
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/appinfo/v1/caldav.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/AppInfo/Application.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 30 | ||||
-rw-r--r-- | apps/dav/lib/Command/CreateCalendar.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/RootCollection.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/Migration/ClassificationTest.php | 11 |
7 files changed, 39 insertions, 18 deletions
diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 490f4477a7b..13b4d3119ca 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -46,7 +46,7 @@ $principalBackend = new Principal( 'principals/' ); $db = \OC::$server->getDatabaseConnection(); -$calDavBackend = new CalDavBackend($db, $principalBackend); +$calDavBackend = new CalDavBackend($db, $principalBackend, \OC::$server->getUserManager()); $debugging = \OC::$server->getConfig()->getSystemValue('debug', false); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index fa9d6e29fde..e1a01f12361 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -97,7 +97,7 @@ class Application extends App { $c->getServer()->getUserManager(), $c->getServer()->getGroupManager() ); - return new CalDavBackend($db, $principal); + return new CalDavBackend($db, $principal, $c->getServer()->getUserManager()); }); $container->registerService('BirthdayService', function($c) { diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 1f337ab0143..ea5c09939a6 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -30,6 +30,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\Sharing\Backend; use OCP\IDBConnection; +use OCP\IUser; +use OCP\IUserManager; use Sabre\CalDAV\Backend\AbstractBackend; use Sabre\CalDAV\Backend\SchedulingSupport; use Sabre\CalDAV\Backend\SubscriptionSupport; @@ -99,6 +101,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', ]; + /** + * @var string[] Map of uid => display name + */ + protected $userDisplayNames; + /** @var IDBConnection */ private $db; @@ -108,15 +115,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription /** @var Principal */ private $principalBackend; + /** @var IUserManager */ + private $userManager; + /** * CalDavBackend constructor. * * @param IDBConnection $db * @param Principal $principalBackend + * @param IUserManager $userManager */ - public function __construct(IDBConnection $db, Principal $principalBackend) { + public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager) { $this->db = $db; $this->principalBackend = $principalBackend; + $this->userManager = $userManager; $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); } @@ -217,7 +229,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription while($row = $result->fetch()) { list(, $name) = URLUtil::splitPath($row['principaluri']); $uri = $row['uri'] . '_shared_by_' . $name; - $row['displayname'] = $row['displayname'] . "($name)"; + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; $components = []; if ($row['components']) { $components = explode(',',$row['components']); @@ -247,6 +259,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return array_values($calendars); } + 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 string $principal * @param string $uri diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php index 7d07ad03279..0bc6398250e 100644 --- a/apps/dav/lib/Command/CreateCalendar.php +++ b/apps/dav/lib/Command/CreateCalendar.php @@ -76,7 +76,7 @@ class CreateCalendar extends Command { ); $name = $input->getArgument('name'); - $caldav = new CalDavBackend($this->dbConnection, $principalBackend); + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager); $caldav->createCalendar("principals/users/$user", $name, []); } } diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index 16df85d8146..de3f7e2a857 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -59,7 +59,7 @@ class RootCollection extends SimpleCollection { $systemPrincipals->disableListing = $disableListing; $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend); + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager()); $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); $calendarRoot->disableListing = $disableListing; diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php index 2b7424272e2..0e2e1b0ee51 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php @@ -49,6 +49,9 @@ abstract class AbstractCalDavBackendTest extends TestCase { /** @var Principal | \PHPUnit_Framework_MockObject_MockObject */ protected $principal; + /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $userManager; + const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; @@ -56,6 +59,9 @@ abstract class AbstractCalDavBackendTest extends TestCase { 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']) @@ -69,7 +75,7 @@ abstract class AbstractCalDavBackendTest extends TestCase { ->willReturn([self::UNIT_TEST_GROUP]); $db = \OC::$server->getDatabaseConnection(); - $this->backend = new CalDavBackend($db, $this->principal); + $this->backend = new CalDavBackend($db, $this->principal, $this->userManager); $this->tearDown(); } diff --git a/apps/dav/tests/unit/Migration/ClassificationTest.php b/apps/dav/tests/unit/Migration/ClassificationTest.php index f19702e9cb2..1960fa031e1 100644 --- a/apps/dav/tests/unit/Migration/ClassificationTest.php +++ b/apps/dav/tests/unit/Migration/ClassificationTest.php @@ -35,17 +35,6 @@ use OCP\IUser; * @package OCA\DAV\Tests\unit\DAV */ class ClassificationTest extends AbstractCalDavBackendTest { - - /** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\IUserManager */ - private $userManager; - - public function setUp() { - parent::setUp(); - - $this->userManager = $this->getMockBuilder('OCP\IUserManager') - ->disableOriginalConstructor()->getMock(); - } - public function test() { // setup data $calendarId = $this->createTestCalendar(); |