Skip to content

Commit 17e23d1

Browse files
authored
Merge pull request #59972 from nextcloud/backport/59693/stable25
2 parents 19f83e3 + 4023baa commit 17e23d1

8 files changed

Lines changed: 293 additions & 15 deletions

File tree

.drone.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,31 @@ trigger:
962962
- pull_request
963963
- push
964964

965+
---
966+
kind: pipeline
967+
name: integration-caldav-delegation
968+
969+
steps:
970+
- name: submodules
971+
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
972+
commands:
973+
- git submodule update --init
974+
- name: integration-caldav-delegation
975+
image: ghcr.io/nextcloud/continuous-integration-integration-php7.4:latest
976+
commands:
977+
- bash tests/drone-run-integration-tests.sh || exit 0
978+
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
979+
- cd build/integration
980+
- ./run.sh features/caldav-delegation.feature
981+
982+
trigger:
983+
branch:
984+
- master
985+
- stable*
986+
event:
987+
- pull_request
988+
- push
989+
965990
---
966991
kind: pipeline
967992
name: integration-comments
@@ -2033,4 +2058,6 @@ trigger:
20332058
- push
20342059
---
20352060
kind: signature
2036-
hmac: fd19490e3939e1da07aae543ff0bc5bb920df2cdc7bc81d224faf9cc5b6c444a
2061+
hmac: 3b856c3a173b1df862572509f7cb1465b216faedfb6f14889778ca471702ba58
2062+
2063+
...

apps/dav/composer/composer/autoload_classmap.php

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

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 145 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,39 @@ public function setUpScenario() {
6161

6262
/** @AfterScenario */
6363
public function afterScenario() {
64-
$davUrl = $this->baseUrl. '/remote.php/dav/calendars/admin/MyCalendar';
65-
try {
66-
$this->client->delete(
67-
$davUrl,
68-
[
69-
'auth' => [
70-
'admin',
71-
'admin',
72-
],
73-
'headers' => [
74-
'X-NC-CalDAV-No-Trashbin' => '1',
64+
foreach (['MyCalendar', 'MyCalendar2'] as $calendarName) {
65+
try {
66+
$this->client->delete(
67+
$this->baseUrl . '/remote.php/dav/calendars/admin/' . $calendarName,
68+
[
69+
'auth' => ['admin', 'admin'],
70+
'headers' => ['X-NC-CalDAV-No-Trashbin' => '1'],
7571
]
76-
]
77-
);
78-
} catch (\GuzzleHttp\Exception\ClientException $e) {
72+
);
73+
} catch (\GuzzleHttp\Exception\ClientException $e) {
74+
}
75+
}
76+
}
77+
78+
/** @AfterScenario @caldav-delegation */
79+
public function afterDelegationScenario() {
80+
foreach (['calendar-proxy-read', 'calendar-proxy-write'] as $proxyType) {
81+
try {
82+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
83+
$propPatch->properties = ['{DAV:}group-member-set' => new \Sabre\DAV\Xml\Property\Href([])];
84+
$xml = new \Sabre\Xml\Service();
85+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
86+
$this->client->request(
87+
'PROPPATCH',
88+
$this->baseUrl . '/remote.php/dav/principals/users/admin/' . $proxyType,
89+
[
90+
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'],
91+
'body' => $body,
92+
'auth' => ['admin', 'admin'],
93+
]
94+
);
95+
} catch (\GuzzleHttp\Exception\ClientException $e) {
96+
}
7997
}
8098
}
8199

@@ -105,6 +123,80 @@ public function requestsCalendar($user, $calendar, $endpoint) {
105123
}
106124
}
107125

126+
/**
127+
* @Then The CalDAV response should contain a property :key
128+
* @throws \Exception
129+
*/
130+
public function theCaldavResponseShouldContainAProperty(string $key) {
131+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
132+
$multiStatus = $this->responseXml['value'];
133+
$responses = $multiStatus->getResponses()[0]->getResponseProperties();
134+
if (!isset($responses[200])) {
135+
throw new \Exception(
136+
sprintf(
137+
'Expected code 200 got [%s]',
138+
implode(',', array_keys($responses)),
139+
)
140+
);
141+
}
142+
143+
$props = $responses[200];
144+
if (!array_key_exists($key, $props)) {
145+
throw new \Exception(
146+
sprintf(
147+
'Expected property %s in %s',
148+
$key,
149+
json_encode($props, JSON_PRETTY_PRINT),
150+
)
151+
);
152+
}
153+
}
154+
155+
/**
156+
* @Then The CalDAV response should contain an href :href
157+
* @throws \Exception
158+
*/
159+
public function theCaldavResponseShouldContainAnHref(string $href) {
160+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
161+
$multiStatus = $this->responseXml['value'];
162+
foreach ($multiStatus->getResponses() as $response) {
163+
if ($response->getHref() === $href) {
164+
return;
165+
}
166+
}
167+
throw new \Exception(
168+
sprintf(
169+
'Expected href %s not found in response',
170+
$href,
171+
)
172+
);
173+
}
174+
175+
/**
176+
* @Then The CalDAV response should be multi status
177+
* @throws \Exception
178+
*/
179+
public function theCaldavResponseShouldBeMultiStatus() {
180+
if ($this->response->getStatusCode() !== 207) {
181+
throw new \Exception(
182+
sprintf(
183+
'Expected code 207 got %s',
184+
$this->response->getStatusCode()
185+
)
186+
);
187+
}
188+
189+
$body = $this->response->getBody()->getContents();
190+
if ($body && substr($body, 0, 1) === '<') {
191+
$reader = new Sabre\Xml\Reader();
192+
$reader->xml($body);
193+
$reader->elementMap['{DAV:}multistatus'] = \Sabre\DAV\Xml\Response\MultiStatus::class;
194+
$reader->elementMap['{DAV:}response'] = \Sabre\DAV\Xml\Element\Response::class;
195+
$reader->elementMap['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'] = \Sabre\DAV\Xml\Property\Href::class;
196+
$this->responseXml = $reader->parse();
197+
}
198+
}
199+
108200
/**
109201
* @Then The CalDAV HTTP status code should be :code
110202
* @param int $code
@@ -258,4 +350,43 @@ public function sendsCreateCalendarRequest(string $user, string $calendar, strin
258350
$this->response = $e->getResponse();
259351
}
260352
}
353+
354+
/**
355+
* @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
356+
*/
357+
public function updatesHrefPropertyOfPrincipal(
358+
string $user,
359+
string $key,
360+
string $value,
361+
string $principal,
362+
string $endpoint
363+
) {
364+
$davUrl = $this->baseUrl . $endpoint . $principal;
365+
$password = ($user === 'admin') ? 'admin' : '123456';
366+
367+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
368+
$propPatch->properties = [$key => new \Sabre\DAV\Xml\Property\Href($value)];
369+
370+
$xml = new \Sabre\Xml\Service();
371+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
372+
373+
try {
374+
$this->response = $this->client->request(
375+
'PROPPATCH',
376+
$davUrl,
377+
[
378+
'headers' => [
379+
'Content-Type' => 'application/xml; charset=UTF-8',
380+
],
381+
'body' => $body,
382+
'auth' => [
383+
$user,
384+
$password,
385+
],
386+
]
387+
);
388+
} catch (\GuzzleHttp\Exception\ClientException $e) {
389+
$this->response = $e->getResponse();
390+
}
391+
}
261392
}
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)