Allow to hide a shared calendar

This commit is contained in:
Joas Schilling 2016-02-18 12:12:14 +01:00
parent 95e218b00c
commit 6f22784d3d
2 changed files with 29 additions and 4 deletions

View File

@ -106,7 +106,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
}
function propPatch(PropPatch $propPatch) {
if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
$mutations = $propPatch->getMutations();
// If this is a shared calendar, the user can only change the enabled property, to hide it.
if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && (sizeof($mutations) !== 1 || !isset($mutations['{http://owncloud.org/ns}calendar-enabled']))) {
throw new Forbidden();
}
parent::propPatch($propPatch);

View File

@ -65,10 +65,26 @@ class CalendarTest extends TestCase {
$c->delete();
}
public function dataPropPatch() {
return [
[[], true],
[[
'{http://owncloud.org/ns}calendar-enabled' => true,
], false],
[[
'{DAV:}displayname' => true,
], true],
[[
'{DAV:}displayname' => true,
'{http://owncloud.org/ns}calendar-enabled' => true,
], true],
];
}
/**
* @expectedException \Sabre\DAV\Exception\Forbidden
* @dataProvider dataPropPatch
*/
public function testPropPatch() {
public function testPropPatch($mutations, $throws) {
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
$calendarInfo = [
@ -77,6 +93,13 @@ class CalendarTest extends TestCase {
'id' => 666
];
$c = new Calendar($backend, $calendarInfo);
$c->propPatch(new PropPatch([]));
if ($throws) {
$this->setExpectedException('\Sabre\DAV\Exception\Forbidden');
}
$c->propPatch(new PropPatch($mutations));
if (!$throws) {
$this->assertTrue(true);
}
}
}