Skip to content

Commit

Permalink
fix(CardDAV): set owner-principal, displayname properties for SAB
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <anna@nextcloud.com>
  • Loading branch information
miaulalala committed Aug 16, 2023
1 parent 5af9b6c commit 3c3b2f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
20 changes: 11 additions & 9 deletions apps/dav/lib/CardDAV/AddressBook.php
Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/Connector/Sabre/Principal.php
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion apps/dav/tests/unit/CardDAV/AddressBookTest.php
Expand Up @@ -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,
Expand Down

0 comments on commit 3c3b2f8

Please sign in to comment.