Merge pull request #22244 from owncloud/dont-update-shared-resource-properties
For 9.0 we don't have the possibility to store calendar and addressbo…
This commit is contained in:
commit
296a46cc38
|
@ -23,6 +23,7 @@ namespace OCA\DAV\CalDAV;
|
||||||
|
|
||||||
use OCA\DAV\DAV\Sharing\IShareable;
|
use OCA\DAV\DAV\Sharing\IShareable;
|
||||||
use Sabre\DAV\Exception\Forbidden;
|
use Sabre\DAV\Exception\Forbidden;
|
||||||
|
use Sabre\DAV\PropPatch;
|
||||||
|
|
||||||
class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
|
|
||||||
|
@ -122,4 +123,13 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
}
|
}
|
||||||
parent::delete();
|
parent::delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function propPatch(PropPatch $propPatch) {
|
||||||
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace OCA\DAV\CardDAV;
|
||||||
use OCA\DAV\DAV\Sharing\IShareable;
|
use OCA\DAV\DAV\Sharing\IShareable;
|
||||||
use Sabre\DAV\Exception\Forbidden;
|
use Sabre\DAV\Exception\Forbidden;
|
||||||
use Sabre\DAV\Exception\NotFound;
|
use Sabre\DAV\Exception\NotFound;
|
||||||
|
use Sabre\DAV\PropPatch;
|
||||||
|
|
||||||
class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
|
class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
|
||||||
|
|
||||||
|
@ -83,14 +84,14 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the current user
|
// add the current user
|
||||||
if (isset($this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) {
|
if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
|
||||||
$owner = $this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'];
|
$owner = $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'];
|
||||||
$acl[] = [
|
$acl[] = [
|
||||||
'privilege' => '{DAV:}read',
|
'privilege' => '{DAV:}read',
|
||||||
'principal' => $owner,
|
'principal' => $owner,
|
||||||
'protected' => true,
|
'protected' => true,
|
||||||
];
|
];
|
||||||
if ($this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only']) {
|
if ($this->addressBookInfo['{http://owncloud.org/ns}read-only']) {
|
||||||
$acl[] = [
|
$acl[] = [
|
||||||
'privilege' => '{DAV:}write',
|
'privilege' => '{DAV:}write',
|
||||||
'principal' => $owner,
|
'principal' => $owner,
|
||||||
|
@ -162,6 +163,13 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
|
||||||
parent::delete();
|
parent::delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function propPatch(PropPatch $propPatch) {
|
||||||
|
if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) {
|
||||||
|
throw new Forbidden();
|
||||||
|
}
|
||||||
|
parent::propPatch($propPatch);
|
||||||
|
}
|
||||||
|
|
||||||
public function getContactsGroups() {
|
public function getContactsGroups() {
|
||||||
/** @var CardDavBackend $cardDavBackend */
|
/** @var CardDavBackend $cardDavBackend */
|
||||||
$cardDavBackend = $this->carddavBackend;
|
$cardDavBackend = $this->carddavBackend;
|
||||||
|
|
|
@ -190,6 +190,14 @@ class Backend {
|
||||||
'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
|
'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
|
||||||
'protected' => true,
|
'protected' => true,
|
||||||
];
|
];
|
||||||
|
} else if ($this->resourceType === 'calendar') {
|
||||||
|
// Allow changing the properties of read only calendars,
|
||||||
|
// so users can change the visibility.
|
||||||
|
$acl[] = [
|
||||||
|
'privilege' => '{DAV:}write-properties',
|
||||||
|
'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
|
||||||
|
'protected' => true,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $acl;
|
return $acl;
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace OCA\DAV\Tests\Unit\CalDAV;
|
||||||
|
|
||||||
use OCA\DAV\CalDAV\CalDavBackend;
|
use OCA\DAV\CalDAV\CalDavBackend;
|
||||||
use OCA\DAV\CalDAV\Calendar;
|
use OCA\DAV\CalDAV\Calendar;
|
||||||
|
use Sabre\DAV\PropPatch;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class CalendarTest extends TestCase {
|
class CalendarTest extends TestCase {
|
||||||
|
@ -63,4 +64,42 @@ class CalendarTest extends TestCase {
|
||||||
$c = new Calendar($backend, $calendarInfo);
|
$c = new Calendar($backend, $calendarInfo);
|
||||||
$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],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataPropPatch
|
||||||
|
*/
|
||||||
|
public function testPropPatch($mutations, $throws) {
|
||||||
|
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
|
||||||
|
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
|
||||||
|
$calendarInfo = [
|
||||||
|
'{http://owncloud.org/ns}owner-principal' => 'user1',
|
||||||
|
'principaluri' => 'user2',
|
||||||
|
'id' => 666
|
||||||
|
];
|
||||||
|
$c = new Calendar($backend, $calendarInfo);
|
||||||
|
|
||||||
|
if ($throws) {
|
||||||
|
$this->setExpectedException('\Sabre\DAV\Exception\Forbidden');
|
||||||
|
}
|
||||||
|
$c->propPatch(new PropPatch($mutations));
|
||||||
|
if (!$throws) {
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace OCA\DAV\Tests\Unit\CardDAV;
|
||||||
|
|
||||||
use OCA\DAV\CardDAV\AddressBook;
|
use OCA\DAV\CardDAV\AddressBook;
|
||||||
use OCA\DAV\CardDAV\CardDavBackend;
|
use OCA\DAV\CardDAV\CardDavBackend;
|
||||||
|
use Sabre\DAV\PropPatch;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class AddressBookTest extends TestCase {
|
class AddressBookTest extends TestCase {
|
||||||
|
@ -61,4 +62,19 @@ class AddressBookTest extends TestCase {
|
||||||
$c = new AddressBook($backend, $calendarInfo);
|
$c = new AddressBook($backend, $calendarInfo);
|
||||||
$c->delete();
|
$c->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||||
|
*/
|
||||||
|
public function testPropPatch() {
|
||||||
|
/** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */
|
||||||
|
$backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock();
|
||||||
|
$calendarInfo = [
|
||||||
|
'{http://owncloud.org/ns}owner-principal' => 'user1',
|
||||||
|
'principaluri' => 'user2',
|
||||||
|
'id' => 666
|
||||||
|
];
|
||||||
|
$c = new AddressBook($backend, $calendarInfo);
|
||||||
|
$c->propPatch(new PropPatch([]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue