Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] fixes #26746 - birthday calendar exposes no access share s… #31882

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/dav/lib/CalDAV/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 15 additions & 0 deletions apps/dav/lib/CalDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions apps/dav/tests/unit/CalDAV/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Sabre\DAV\PropPatch;
use Sabre\VObject\Reader;
use Test\TestCase;
use Sabre\DAV\Exception\Forbidden;

class CalendarTest extends TestCase {

Expand All @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions apps/dav/tests/unit/CalDAV/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace OCA\DAV\Tests\unit\CalDAV;

use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\Plugin;
use Sabre\DAV\PropFind;
use Sabre\DAV\Xml\Property\ShareAccess;
use Test\TestCase;

class PluginTest extends TestCase {

/** @var Plugin */
private $plugin;

protected function setUp() {
parent::setUp();

$this->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);
}
}