Skip to content

Commit 64cb8ac

Browse files
authored
Merge pull request #59760 from nextcloud/backport/59693/stable30
2 parents 2f2cb04 + 6439130 commit 64cb8ac

7 files changed

Lines changed: 190 additions & 28 deletions

File tree

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
'OCA\\DAV\\CalDAV\\Outbox' => $baseDir . '/../lib/CalDAV/Outbox.php',
7474
'OCA\\DAV\\CalDAV\\Plugin' => $baseDir . '/../lib/CalDAV/Plugin.php',
7575
'OCA\\DAV\\CalDAV\\Principal\\Collection' => $baseDir . '/../lib/CalDAV/Principal/Collection.php',
76+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => $baseDir . '/../lib/CalDAV/Principal/ProxyRead.php',
77+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => $baseDir . '/../lib/CalDAV/Principal/ProxyWrite.php',
7678
'OCA\\DAV\\CalDAV\\Principal\\User' => $baseDir . '/../lib/CalDAV/Principal/User.php',
7779
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => $baseDir . '/../lib/CalDAV/Proxy/Proxy.php',
7880
'OCA\\DAV\\CalDAV\\Proxy\\ProxyMapper' => $baseDir . '/../lib/CalDAV/Proxy/ProxyMapper.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class ComposerStaticInitDAV
8888
'OCA\\DAV\\CalDAV\\Outbox' => __DIR__ . '/..' . '/../lib/CalDAV/Outbox.php',
8989
'OCA\\DAV\\CalDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Plugin.php',
9090
'OCA\\DAV\\CalDAV\\Principal\\Collection' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/Collection.php',
91+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyRead.php',
92+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyWrite.php',
9193
'OCA\\DAV\\CalDAV\\Principal\\User' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/User.php',
9294
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => __DIR__ . '/..' . '/../lib/CalDAV/Proxy/Proxy.php',
9395
'OCA\\DAV\\CalDAV\\Proxy\\ProxyMapper' => __DIR__ . '/..' . '/../lib/CalDAV/Proxy/ProxyMapper.php',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\CalDAV\Principal;
11+
12+
use Sabre\DAVACL;
13+
14+
class ProxyRead extends \Sabre\CalDAV\Principal\ProxyRead implements DAVACL\IACL {
15+
use DAVACL\ACLTrait;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function getOwner() {
21+
return $this->principalInfo['uri'];
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\CalDAV\Principal;
11+
12+
use Sabre\DAVACL;
13+
14+
class ProxyWrite extends \Sabre\CalDAV\Principal\ProxyWrite implements DAVACL\IACL {
15+
use DAVACL\ACLTrait;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function getOwner() {
21+
return $this->principalInfo['uri'];
22+
}
23+
}

apps/dav/lib/CalDAV/Principal/User.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,44 @@ public function getACL() {
3434
];
3535
return $acl;
3636
}
37+
38+
/**
39+
* Returns a specific child node, referenced by its name.
40+
*
41+
* @param string $name
42+
*
43+
* @return \Sabre\DAV\INode
44+
*/
45+
public function getChild($name) {
46+
$principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name);
47+
if (!$principal) {
48+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
49+
}
50+
if ($name === 'calendar-proxy-read') {
51+
return new ProxyRead($this->principalBackend, $this->principalProperties);
52+
}
53+
54+
if ($name === 'calendar-proxy-write') {
55+
return new ProxyWrite($this->principalBackend, $this->principalProperties);
56+
}
57+
58+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
59+
}
60+
61+
/**
62+
* Returns an array with all the child nodes.
63+
*
64+
* @return \Sabre\DAV\INode[]
65+
*/
66+
public function getChildren() {
67+
$r = [];
68+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) {
69+
$r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
70+
}
71+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) {
72+
$r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
73+
}
74+
75+
return $r;
76+
}
3777
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
Feature: calendar delegation
4+
Calendar delegation grants another user/principal control of a calendar account,
5+
including all calendars the delegator can access.
6+
7+
@caldav-delegation
8+
Scenario: admin grants user0 read access to her calendar account
9+
Given user "admin" exists
10+
And user "user0" exists
11+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user0" of principal "users/admin/calendar-proxy-read" on the endpoint "/remote.php/dav/principals/"
12+
Then The CalDAV response should be multi status
13+
And The CalDAV response should contain an href "/remote.php/dav/principals/users/admin/calendar-proxy-read"
14+
And The CalDAV response should contain a property "{DAV:}group-member-set"
15+
16+
@caldav-delegation
17+
Scenario: admin grants write access to her calendar account
18+
Given user "admin" exists
19+
And user "user0" exists
20+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user0" of principal "users/admin/calendar-proxy-write" on the endpoint "/remote.php/dav/principals/"
21+
Then The CalDAV response should be multi status
22+
And The CalDAV response should contain an href "/remote.php/dav/principals/users/admin/calendar-proxy-write"
23+
And The CalDAV response should contain a property "{DAV:}group-member-set"
24+
25+
Scenario: Admin cannot grant User1 access to User0's calendar account
26+
Given user "admin" exists
27+
And user "user0" exists
28+
And user "user1" exists
29+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user1" of principal "users/user0/calendar-proxy-write" on the endpoint "/remote.php/dav/principals/"
30+
Then The CalDAV HTTP status code should be "404"

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,39 @@ public function setUpScenario() {
4242

4343
/** @AfterScenario */
4444
public function afterScenario() {
45-
$davUrl = $this->baseUrl. '/remote.php/dav/calendars/admin/MyCalendar';
46-
try {
47-
$this->client->delete(
48-
$davUrl,
49-
[
50-
'auth' => [
51-
'admin',
52-
'admin',
53-
],
54-
'headers' => [
55-
'X-NC-CalDAV-No-Trashbin' => '1',
45+
foreach (['MyCalendar', 'MyCalendar2'] as $calendarName) {
46+
try {
47+
$this->client->delete(
48+
$this->baseUrl . '/remote.php/dav/calendars/admin/' . $calendarName,
49+
[
50+
'auth' => ['admin', 'admin'],
51+
'headers' => ['X-NC-CalDAV-No-Trashbin' => '1'],
5652
]
57-
]
58-
);
59-
} catch (\GuzzleHttp\Exception\ClientException $e) {
53+
);
54+
} catch (\GuzzleHttp\Exception\ClientException $e) {
55+
}
56+
}
57+
}
58+
59+
/** @AfterScenario @caldav-delegation */
60+
public function afterDelegationScenario() {
61+
foreach (['calendar-proxy-read', 'calendar-proxy-write'] as $proxyType) {
62+
try {
63+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
64+
$propPatch->properties = ['{DAV:}group-member-set' => new \Sabre\DAV\Xml\Property\Href([])];
65+
$xml = new \Sabre\Xml\Service();
66+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
67+
$this->client->request(
68+
'PROPPATCH',
69+
$this->baseUrl . '/remote.php/dav/principals/users/admin/' . $proxyType,
70+
[
71+
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'],
72+
'body' => $body,
73+
'auth' => ['admin', 'admin'],
74+
]
75+
);
76+
} catch (\GuzzleHttp\Exception\ClientException $e) {
77+
}
6078
}
6179
}
6280

@@ -174,6 +192,26 @@ public function theCaldavResponseShouldContainAPropertyWithHrefValue(
174192
}
175193
}
176194

195+
/**
196+
* @Then The CalDAV response should contain an href :href
197+
* @throws \Exception
198+
*/
199+
public function theCaldavResponseShouldContainAnHref(string $href): void {
200+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
201+
$multiStatus = $this->responseXml['value'];
202+
foreach ($multiStatus->getResponses() as $response) {
203+
if ($response->getHref() === $href) {
204+
return;
205+
}
206+
}
207+
throw new \Exception(
208+
sprintf(
209+
'Expected href %s not found in response',
210+
$href,
211+
)
212+
);
213+
}
214+
177215
/**
178216
* @Then The CalDAV response should be multi status
179217
* @throws \Exception
@@ -372,19 +410,23 @@ public function updatesHrefPropertyOfPrincipal(
372410
$xml = new \Sabre\Xml\Service();
373411
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
374412

375-
$this->response = $this->client->request(
376-
'PROPPATCH',
377-
$davUrl,
378-
[
379-
'headers' => [
380-
'Content-Type' => 'application/xml; charset=UTF-8',
381-
],
382-
'body' => $body,
383-
'auth' => [
384-
$user,
385-
$password,
386-
],
387-
]
388-
);
413+
try {
414+
$this->response = $this->client->request(
415+
'PROPPATCH',
416+
$davUrl,
417+
[
418+
'headers' => [
419+
'Content-Type' => 'application/xml; charset=UTF-8',
420+
],
421+
'body' => $body,
422+
'auth' => [
423+
$user,
424+
$password,
425+
],
426+
]
427+
);
428+
} catch (\GuzzleHttp\Exception\ClientException $e) {
429+
$this->response = $e->getResponse();
430+
}
389431
}
390432
}

0 commit comments

Comments
 (0)