From 62a36ee884ed689da0590b30bb96332c9fe6f0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 10 Mar 2016 12:32:46 +0100 Subject: [PATCH] The birthday_calendar is read-only --- apps/dav/lib/caldav/calendar.php | 13 +++++++++---- apps/dav/tests/unit/caldav/calendartest.php | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/dav/lib/caldav/calendar.php b/apps/dav/lib/caldav/calendar.php index 55f1acec39..1e87f9b433 100644 --- a/apps/dav/lib/caldav/calendar.php +++ b/apps/dav/lib/caldav/calendar.php @@ -22,11 +22,20 @@ namespace OCA\DAV\CalDAV; use OCA\DAV\DAV\Sharing\IShareable; +use Sabre\CalDAV\Backend\BackendInterface; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\PropPatch; class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { + public function __construct(BackendInterface $caldavBackend, $calendarInfo) { + parent::__construct($caldavBackend, $calendarInfo); + + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { + $this->calendarInfo['{http://sabredav.org/ns}read-only'] = true; + } + } + /** * Updates the list of shares. * @@ -100,10 +109,6 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { } function delete() { - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { - throw new Forbidden(); - } - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { $principal = 'principal:' . parent::getOwner(); $shares = $this->getShares(); diff --git a/apps/dav/tests/unit/caldav/calendartest.php b/apps/dav/tests/unit/caldav/calendartest.php index c41070ea43..e7f4d57067 100644 --- a/apps/dav/tests/unit/caldav/calendartest.php +++ b/apps/dav/tests/unit/caldav/calendartest.php @@ -32,7 +32,7 @@ class CalendarTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend->expects($this->once())->method('updateShares'); - $backend->method('getShares')->willReturn([ + $backend->expects($this->any())->method('getShares')->willReturn([ ['href' => 'principal:user2'] ]); $calendarInfo = [ @@ -52,7 +52,7 @@ class CalendarTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend->expects($this->never())->method('updateShares'); - $backend->method('getShares')->willReturn([ + $backend->expects($this->any())->method('getShares')->willReturn([ ['href' => 'principal:group2'] ]); $calendarInfo = [ @@ -90,7 +90,8 @@ class CalendarTest extends TestCase { $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', - 'id' => 666 + 'id' => 666, + 'uri' => 'default' ]; $c = new Calendar($backend, $calendarInfo);