From 3c3b2f807bd01d282f9057ebea4fe5e544f6d2ac Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Fri, 21 Jul 2023 12:33:00 +0200 Subject: [PATCH] fix(CardDAV): set owner-principal, displayname properties for SAB Signed-off-by: Anna Larch --- apps/dav/lib/CardDAV/AddressBook.php | 20 ++++++++++--------- apps/dav/lib/CardDAV/CardDavBackend.php | 2 ++ apps/dav/lib/Connector/Sabre/Principal.php | 5 +++++ .../tests/unit/CardDAV/AddressBookTest.php | 1 - 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/dav/lib/CardDAV/AddressBook.php b/apps/dav/lib/CardDAV/AddressBook.php index e9eec4161cb81..0d636e55cb375 100644 --- a/apps/dav/lib/CardDAV/AddressBook.php +++ b/apps/dav/lib/CardDAV/AddressBook.php @@ -116,7 +116,12 @@ public function getACL() { 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), 'protected' => true, - ] + ], + [ + 'privilege' => '{DAV:}write-properties', + 'principal' => '{DAV:}authenticated', + 'protected' => true, + ], ]; if ($this->getOwner() === 'principals/system/system') { @@ -147,7 +152,7 @@ public function getACL() { } $acl = $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system']; + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system', '{DAV:}authenticated']; return array_filter($acl, function ($rule) use ($allowedPrincipals) { return \in_array($rule['principal'], $allowedPrincipals, true); }); @@ -166,8 +171,7 @@ public function getChild($name) { return new Card($this->carddavBackend, $this->addressBookInfo, $obj); } - public function getChildren() - { + public function getChildren() { $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); $children = []; foreach ($objs as $obj) { @@ -178,8 +182,7 @@ public function getChildren() return $children; } - public function getMultipleChildren(array $paths) - { + public function getMultipleChildren(array $paths) { $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths); $children = []; foreach ($objs as $obj) { @@ -221,10 +224,9 @@ public function delete() { } public function propPatch(PropPatch $propPatch) { - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { - throw new Forbidden(); + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { + parent::propPatch($propPatch); } - parent::propPatch($propPatch); } public function getContactsGroups() { diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 045ad4d1385ba..d7bad8d74cadf 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -311,10 +311,12 @@ public function getAddressBooksByUri(string $principal, string $addressBookUri): '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0', + ]; // system address books are always read only if ($principal === 'principals/system/system') { + $addressBook['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'] = $row['principaluri']; $addressBook['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'] = true; } diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php index 0a88228831421..b1f1da6f63df4 100644 --- a/apps/dav/lib/Connector/Sabre/Principal.php +++ b/apps/dav/lib/Connector/Sabre/Principal.php @@ -208,6 +208,11 @@ public function getPrincipalByPath($path) { '{DAV:}displayname' => $group->getDisplayName(), ]; } + } elseif ($prefix === 'principals/system') { + return [ + 'uri' => 'principals/system/' . $name, + '{DAV:}displayname' => $this->languageFactory->get('dav')->t("Accounts"), + ]; } return null; } diff --git a/apps/dav/tests/unit/CardDAV/AddressBookTest.php b/apps/dav/tests/unit/CardDAV/AddressBookTest.php index 81361d02068ee..6bbe5b6b77e1a 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookTest.php @@ -107,7 +107,6 @@ public function testPropPatch(): void { /** @var MockObject | CardDavBackend $backend */ $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock(); $addressBookInfo = [ - '{http://owncloud.org/ns}owner-principal' => 'user1', '{DAV:}displayname' => 'Test address book', 'principaluri' => 'user2', 'id' => 666,