diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php index 28ba9228cd43..9bc387d22cb1 100644 --- a/apps/dav/lib/CalDAV/Calendar.php +++ b/apps/dav/lib/CalDAV/Calendar.php @@ -103,7 +103,13 @@ function getACL() { 'principal' => $this->getOwner(), 'protected' => true, ]]; - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { + $acl[] = [ + 'privilege' => '{DAV:}write-properties', + 'principal' => $this->getOwner(), + 'protected' => true, + ]; + } else { $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), diff --git a/apps/dav/lib/CalDAV/Plugin.php b/apps/dav/lib/CalDAV/Plugin.php index a5d1d214afef..25b3f2ecab2d 100644 --- a/apps/dav/lib/CalDAV/Plugin.php +++ b/apps/dav/lib/CalDAV/Plugin.php @@ -21,9 +21,24 @@ namespace OCA\DAV\CalDAV; +use Sabre\DAV; +use Sabre\DAV\Xml\Property\ShareAccess; use Sabre\HTTP\URLUtil; class Plugin extends \Sabre\CalDAV\Plugin { + public function initialize(DAV\Server $server) { + parent::initialize($server); + } + + public function propFind(DAV\PropFind $propFind, DAV\INode $node) { + parent::propFind($propFind, $node); + + if ($node instanceof Calendar && $node->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { + $propFind->handle('{DAV:}share-access', function () use ($node) { + return new ShareAccess(DAV\Sharing\Plugin::ACCESS_NOACCESS); + }); + } + } /** * @inheritdoc diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index 1fa606fead5e..5b2591c30ab3 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -29,6 +29,7 @@ use Sabre\DAV\PropPatch; use Sabre\VObject\Reader; use Test\TestCase; +use Sabre\DAV\Exception\Forbidden; class CalendarTest extends TestCase { @@ -37,7 +38,7 @@ class CalendarTest extends TestCase { public function setUp() { parent::setUp(); - $this->l10n = $this->getMockBuilder('\OCP\IL10N') + $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); $this->l10n ->expects($this->any()) @@ -115,7 +116,7 @@ public function testPropPatch($mutations, $throws) { $c = new Calendar($backend, $calendarInfo, $this->l10n); if ($throws) { - $this->setExpectedException('\Sabre\DAV\Exception\Forbidden'); + $this->expectException(Forbidden::class); } $c->propPatch(new PropPatch($mutations)); if (!$throws) { @@ -159,6 +160,10 @@ public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'def 'privilege' => '{DAV:}read', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true + ], [ + 'privilege' => '{DAV:}write-properties', + 'principal' => $hasOwnerSet ? 'user1' : 'user2', + 'protected' => true ]]; } if ($hasOwnerSet) { diff --git a/apps/dav/tests/unit/CalDAV/PluginTest.php b/apps/dav/tests/unit/CalDAV/PluginTest.php new file mode 100644 index 000000000000..8e09e34bff28 --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/PluginTest.php @@ -0,0 +1,40 @@ +plugin = new Plugin(); + } + + public function testPropFind() { + $propFind = new PropFind('/calendar/user/birthday_calendar', [ + '{DAV:}share-access' + ]); + $node = $this->createMock(Calendar::class); + $node->method('getName')->willReturn(BirthdayService::BIRTHDAY_CALENDAR_URI); + $this->plugin->propFind($propFind, $node); + + $this->assertEquals(200, $propFind->getStatus('{DAV:}share-access')); + $this->assertInstanceOf(ShareAccess::class, $propFind->get('{DAV:}share-access')); + $this->assertEquals(\Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS, $propFind->get('{DAV:}share-access')->getValue()); + } + + public function testGetCalendarHomeForPrincipal() { + $calendarHome = $this->plugin->getCalendarHomeForPrincipal('principals/users/alice'); + $this->assertEquals('calendars/alice', $calendarHome); + } +}