Allow to hide a shared calendar
This commit is contained in:
parent
b1a1a46193
commit
27f3dcc682
|
@ -125,7 +125,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
}
|
}
|
||||||
|
|
||||||
function propPatch(PropPatch $propPatch) {
|
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();
|
throw new Forbidden();
|
||||||
}
|
}
|
||||||
parent::propPatch($propPatch);
|
parent::propPatch($propPatch);
|
||||||
|
|
|
@ -65,10 +65,26 @@ class CalendarTest extends TestCase {
|
||||||
$c->delete();
|
$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 */
|
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
|
||||||
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
|
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
|
||||||
$calendarInfo = [
|
$calendarInfo = [
|
||||||
|
@ -77,6 +93,13 @@ class CalendarTest extends TestCase {
|
||||||
'id' => 666
|
'id' => 666
|
||||||
];
|
];
|
||||||
$c = new Calendar($backend, $calendarInfo);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue