Skip to content

Commit 744ecd0

Browse files
authored
Merge pull request #59976 from nextcloud/backport/59693/stable21
2 parents 131ede8 + eb685dc commit 744ecd0

7 files changed

Lines changed: 257 additions & 0 deletions

File tree

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
'OCA\\DAV\\CalDAV\\Outbox' => $baseDir . '/../lib/CalDAV/Outbox.php',
5151
'OCA\\DAV\\CalDAV\\Plugin' => $baseDir . '/../lib/CalDAV/Plugin.php',
5252
'OCA\\DAV\\CalDAV\\Principal\\Collection' => $baseDir . '/../lib/CalDAV/Principal/Collection.php',
53+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => $baseDir . '/../lib/CalDAV/Principal/ProxyRead.php',
54+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => $baseDir . '/../lib/CalDAV/Principal/ProxyWrite.php',
5355
'OCA\\DAV\\CalDAV\\Principal\\User' => $baseDir . '/../lib/CalDAV/Principal/User.php',
5456
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => $baseDir . '/../lib/CalDAV/Proxy/Proxy.php',
5557
'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
@@ -65,6 +65,8 @@ class ComposerStaticInitDAV
6565
'OCA\\DAV\\CalDAV\\Outbox' => __DIR__ . '/..' . '/../lib/CalDAV/Outbox.php',
6666
'OCA\\DAV\\CalDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Plugin.php',
6767
'OCA\\DAV\\CalDAV\\Principal\\Collection' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/Collection.php',
68+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyRead.php',
69+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyWrite.php',
6870
'OCA\\DAV\\CalDAV\\Principal\\User' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/User.php',
6971
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => __DIR__ . '/..' . '/../lib/CalDAV/Proxy/Proxy.php',
7072
'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
@@ -52,4 +52,44 @@ public function getACL() {
5252
];
5353
return $acl;
5454
}
55+
56+
/**
57+
* Returns a specific child node, referenced by its name.
58+
*
59+
* @param string $name
60+
*
61+
* @return \Sabre\DAV\INode
62+
*/
63+
public function getChild($name) {
64+
$principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name);
65+
if (!$principal) {
66+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
67+
}
68+
if ($name === 'calendar-proxy-read') {
69+
return new ProxyRead($this->principalBackend, $this->principalProperties);
70+
}
71+
72+
if ($name === 'calendar-proxy-write') {
73+
return new ProxyWrite($this->principalBackend, $this->principalProperties);
74+
}
75+
76+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
77+
}
78+
79+
/**
80+
* Returns an array with all the child nodes.
81+
*
82+
* @return \Sabre\DAV\INode[]
83+
*/
84+
public function getChildren() {
85+
$r = [];
86+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) {
87+
$r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
88+
}
89+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) {
90+
$r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
91+
}
92+
93+
return $r;
94+
}
5595
}

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,37 @@ public function afterScenario() {
7070
'admin',
7171
'admin',
7272
],
73+
'headers' => [
74+
'X-NC-CalDAV-No-Trashbin' => '1',
75+
]
7376
]
7477
);
7578
} catch (\GuzzleHttp\Exception\ClientException $e) {
7679
}
7780
}
7881

82+
/** @AfterScenario @caldav-delegation */
83+
public function afterDelegationScenario() {
84+
foreach (['calendar-proxy-read', 'calendar-proxy-write'] as $proxyType) {
85+
try {
86+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
87+
$propPatch->properties = ['{DAV:}group-member-set' => new \Sabre\DAV\Xml\Property\Href([])];
88+
$xml = new \Sabre\Xml\Service();
89+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
90+
$this->client->request(
91+
'PROPPATCH',
92+
$this->baseUrl . '/remote.php/dav/principals/users/admin/' . $proxyType,
93+
[
94+
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'],
95+
'body' => $body,
96+
'auth' => ['admin', 'admin'],
97+
]
98+
);
99+
} catch (\GuzzleHttp\Exception\ClientException $e) {
100+
}
101+
}
102+
}
103+
79104
/**
80105
* @When :user requests calendar :calendar on the endpoint :endpoint
81106
* @param string $user
@@ -102,6 +127,80 @@ public function requestsCalendar($user, $calendar, $endpoint) {
102127
}
103128
}
104129

130+
/**
131+
* @Then The CalDAV response should contain a property :key
132+
* @throws \Exception
133+
*/
134+
public function theCaldavResponseShouldContainAProperty(string $key) {
135+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
136+
$multiStatus = $this->responseXml['value'];
137+
$responses = $multiStatus->getResponses()[0]->getResponseProperties();
138+
if (!isset($responses[200])) {
139+
throw new \Exception(
140+
sprintf(
141+
'Expected code 200 got [%s]',
142+
implode(',', array_keys($responses)),
143+
)
144+
);
145+
}
146+
147+
$props = $responses[200];
148+
if (!array_key_exists($key, $props)) {
149+
throw new \Exception(
150+
sprintf(
151+
'Expected property %s in %s',
152+
$key,
153+
json_encode($props, JSON_PRETTY_PRINT),
154+
)
155+
);
156+
}
157+
}
158+
159+
/**
160+
* @Then The CalDAV response should contain an href :href
161+
* @throws \Exception
162+
*/
163+
public function theCaldavResponseShouldContainAnHref(string $href) {
164+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
165+
$multiStatus = $this->responseXml['value'];
166+
foreach ($multiStatus->getResponses() as $response) {
167+
if ($response->getHref() === $href) {
168+
return;
169+
}
170+
}
171+
throw new \Exception(
172+
sprintf(
173+
'Expected href %s not found in response',
174+
$href,
175+
)
176+
);
177+
}
178+
179+
/**
180+
* @Then The CalDAV response should be multi status
181+
* @throws \Exception
182+
*/
183+
public function theCaldavResponseShouldBeMultiStatus() {
184+
if ($this->response->getStatusCode() !== 207) {
185+
throw new \Exception(
186+
sprintf(
187+
'Expected code 207 got %s',
188+
$this->response->getStatusCode()
189+
)
190+
);
191+
}
192+
193+
$body = $this->response->getBody()->getContents();
194+
if ($body && substr($body, 0, 1) === '<') {
195+
$reader = new Sabre\Xml\Reader();
196+
$reader->xml($body);
197+
$reader->elementMap['{DAV:}multistatus'] = \Sabre\DAV\Xml\Response\MultiStatus::class;
198+
$reader->elementMap['{DAV:}response'] = \Sabre\DAV\Xml\Element\Response::class;
199+
$reader->elementMap['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'] = \Sabre\DAV\Xml\Property\Href::class;
200+
$this->responseXml = $reader->parse();
201+
}
202+
}
203+
105204
/**
106205
* @Then The CalDAV HTTP status code should be :code
107206
* @param int $code
@@ -231,4 +330,42 @@ public function t($amount) {
231330
);
232331
}
233332
}
333+
/**
334+
* @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
335+
*/
336+
public function updatesHrefPropertyOfPrincipal(
337+
string $user,
338+
string $key,
339+
string $value,
340+
string $principal,
341+
string $endpoint
342+
) {
343+
$davUrl = $this->baseUrl . $endpoint . $principal;
344+
$password = ($user === 'admin') ? 'admin' : '123456';
345+
346+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
347+
$propPatch->properties = [$key => new \Sabre\DAV\Xml\Property\Href($value)];
348+
349+
$xml = new \Sabre\Xml\Service();
350+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
351+
352+
try {
353+
$this->response = $this->client->request(
354+
'PROPPATCH',
355+
$davUrl,
356+
[
357+
'headers' => [
358+
'Content-Type' => 'application/xml; charset=UTF-8',
359+
],
360+
'body' => $body,
361+
'auth' => [
362+
$user,
363+
$password,
364+
],
365+
]
366+
);
367+
} catch (\GuzzleHttp\Exception\ClientException $e) {
368+
$this->response = $e->getResponse();
369+
}
370+
}
234371
}
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"

0 commit comments

Comments
 (0)