Skip to content

Commit 0a21e47

Browse files
committed
move disableFreeBusy check from User principal backend to Scheduling Outbox collection. This allows to keep local delivery of scheduling messages while prohibiting FreeBusy requests
Signed-off-by: Georg Ehrke <[email protected]>
1 parent e3a2b9e commit 0a21e47

File tree

8 files changed

+305
-108
lines changed

8 files changed

+305
-108
lines changed

apps/dav/composer/composer/ClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private function findFileWithExtension($class, $ext)
377377
$subPath = $class;
378378
while (false !== $lastPos = strrpos($subPath, '\\')) {
379379
$subPath = substr($subPath, 0, $lastPos);
380-
$search = $subPath.'\\';
380+
$search = $subPath . '\\';
381381
if (isset($this->prefixDirsPsr4[$search])) {
382382
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383383
foreach ($this->prefixDirsPsr4[$search] as $dir) {

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'OCA\\DAV\\CalDAV\\CalendarManager' => $baseDir . '/../lib/CalDAV/CalendarManager.php',
3232
'OCA\\DAV\\CalDAV\\CalendarObject' => $baseDir . '/../lib/CalDAV/CalendarObject.php',
3333
'OCA\\DAV\\CalDAV\\CalendarRoot' => $baseDir . '/../lib/CalDAV/CalendarRoot.php',
34+
'OCA\\DAV\\CalDAV\\Outbox' => $baseDir . '/../lib/CalDAV/Outbox.php',
3435
'OCA\\DAV\\CalDAV\\Plugin' => $baseDir . '/../lib/CalDAV/Plugin.php',
3536
'OCA\\DAV\\CalDAV\\Principal\\Collection' => $baseDir . '/../lib/CalDAV/Principal/Collection.php',
3637
'OCA\\DAV\\CalDAV\\Principal\\User' => $baseDir . '/../lib/CalDAV/Principal/User.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ComposerStaticInitDAV
4646
'OCA\\DAV\\CalDAV\\CalendarManager' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarManager.php',
4747
'OCA\\DAV\\CalDAV\\CalendarObject' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarObject.php',
4848
'OCA\\DAV\\CalDAV\\CalendarRoot' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarRoot.php',
49+
'OCA\\DAV\\CalDAV\\Outbox' => __DIR__ . '/..' . '/../lib/CalDAV/Outbox.php',
4950
'OCA\\DAV\\CalDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Plugin.php',
5051
'OCA\\DAV\\CalDAV\\Principal\\Collection' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/Collection.php',
5152
'OCA\\DAV\\CalDAV\\Principal\\User' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/User.php',

apps/dav/lib/CalDAV/CalendarHome.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Sabre\CalDAV\Backend\SchedulingSupport;
3030
use Sabre\CalDAV\Backend\SubscriptionSupport;
3131
use Sabre\CalDAV\Schedule\Inbox;
32-
use Sabre\CalDAV\Schedule\Outbox;
3332
use Sabre\CalDAV\Subscriptions\Subscription;
3433
use Sabre\DAV\Exception\NotFound;
3534
use Sabre\DAV\Exception\MethodNotAllowed;
@@ -81,7 +80,7 @@ function getChildren() {
8180

8281
if ($this->caldavBackend instanceof SchedulingSupport) {
8382
$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
84-
$objects[] = new Outbox($this->principalInfo['uri']);
83+
$objects[] = new Outbox($this->config, $this->principalInfo['uri']);
8584
}
8685

8786
// We're adding a notifications node, if it's supported by the backend.
@@ -108,7 +107,7 @@ function getChild($name) {
108107
return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
109108
}
110109
if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
111-
return new Outbox($this->principalInfo['uri']);
110+
return new Outbox($this->config, $this->principalInfo['uri']);
112111
}
113112
if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
114113
return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);

apps/dav/lib/CalDAV/Outbox.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2018, Georg Ehrke
4+
*
5+
* @author Georg Ehrke <[email protected]>
6+
*
7+
* @license AGPL-3.0
8+
*
9+
* This code is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License, version 3,
11+
* as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License, version 3,
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>
20+
*
21+
*/
22+
namespace OCA\DAV\CalDAV;
23+
24+
use OCP\IConfig;
25+
use Sabre\CalDAV\Plugin as CalDAVPlugin;
26+
27+
/**
28+
* Class Outbox
29+
*
30+
* @package OCA\DAV\CalDAV
31+
*/
32+
class Outbox extends \Sabre\CalDAV\Schedule\Outbox {
33+
34+
/** @var IConfig */
35+
private $config;
36+
37+
/** @var null|bool */
38+
private $disableFreeBusy = null;
39+
40+
/**
41+
* Outbox constructor.
42+
*
43+
* @param IConfig $config
44+
* @param string $principalUri
45+
*/
46+
public function __construct(IConfig $config, string $principalUri) {
47+
parent::__construct($principalUri);
48+
$this->config = $config;
49+
}
50+
51+
/**
52+
* Returns a list of ACE's for this node.
53+
*
54+
* Each ACE has the following properties:
55+
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
56+
* currently the only supported privileges
57+
* * 'principal', a url to the principal who owns the node
58+
* * 'protected' (optional), indicating that this ACE is not allowed to
59+
* be updated.
60+
*
61+
* @return array
62+
*/
63+
function getACL() {
64+
// getACL is called so frequently that we cache the config result
65+
if ($this->disableFreeBusy === null) {
66+
$this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes');
67+
}
68+
69+
$commonAcl = [
70+
[
71+
'privilege' => '{DAV:}read',
72+
'principal' => $this->getOwner(),
73+
'protected' => true,
74+
],
75+
[
76+
'privilege' => '{DAV:}read',
77+
'principal' => $this->getOwner() . '/calendar-proxy-read',
78+
'protected' => true,
79+
],
80+
[
81+
'privilege' => '{DAV:}read',
82+
'principal' => $this->getOwner() . '/calendar-proxy-write',
83+
'protected' => true,
84+
],
85+
];
86+
87+
// schedule-send is an aggregate privilege for:
88+
// - schedule-send-invite
89+
// - schedule-send-reply
90+
// - schedule-send-freebusy
91+
//
92+
// If FreeBusy is disabled, we have to remove the latter privilege
93+
94+
if ($this->disableFreeBusy) {
95+
return array_merge($commonAcl, [
96+
[
97+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
98+
'principal' => $this->getOwner(),
99+
'protected' => true,
100+
],
101+
[
102+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite',
103+
'principal' => $this->getOwner() . '/calendar-proxy-write',
104+
'protected' => true,
105+
],
106+
[
107+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
108+
'principal' => $this->getOwner(),
109+
'protected' => true,
110+
],
111+
[
112+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply',
113+
'principal' => $this->getOwner() . '/calendar-proxy-write',
114+
'protected' => true,
115+
],
116+
]);
117+
}
118+
119+
return array_merge($commonAcl, [
120+
[
121+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
122+
'principal' => $this->getOwner(),
123+
'protected' => true,
124+
],
125+
[
126+
'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send',
127+
'principal' => $this->getOwner() . '/calendar-proxy-write',
128+
'protected' => true,
129+
],
130+
]);
131+
}
132+
}

apps/dav/lib/Connector/Sabre/Principal.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,9 @@ function updatePrincipal($path, PropPatch $propPatch) {
213213
protected function searchUserPrincipals(array $searchProperties, $test = 'allof') {
214214
$results = [];
215215

216-
// If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
216+
// If sharing is disabled, return the empty array
217217
$shareAPIEnabled = $this->shareManager->shareApiEnabled();
218-
$disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
219-
if ($disableFreeBusy === 'yes') {
218+
if (!$shareAPIEnabled) {
220219
return [];
221220
}
222221

@@ -299,10 +298,9 @@ function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
299298
* @return string
300299
*/
301300
function findByUri($uri, $principalPrefix) {
302-
// If sharing is disabled (or FreeBusy was disabled on purpose), return the empty array
301+
// If sharing is disabled, return the empty array
303302
$shareAPIEnabled = $this->shareManager->shareApiEnabled();
304-
$disableFreeBusy = $this->config->getAppValue('dav', 'disableFreeBusy', $shareAPIEnabled ? 'no' : 'yes');
305-
if ($disableFreeBusy === 'yes') {
303+
if (!$shareAPIEnabled) {
306304
return null;
307305
}
308306

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2018, Georg Ehrke
4+
*
5+
* @author Georg Ehrke <[email protected]>
6+
*
7+
* @license AGPL-3.0
8+
*
9+
* This code is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License, version 3,
11+
* as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License, version 3,
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>
20+
*
21+
*/
22+
23+
namespace OCA\DAV\Tests\unit\CalDAV;
24+
25+
use OCA\DAV\CalDAV\Outbox;
26+
use OCP\IConfig;
27+
use Test\TestCase;
28+
29+
class OutboxTest extends TestCase {
30+
31+
/** @var IConfig */
32+
private $config;
33+
34+
/** @var Outbox */
35+
private $outbox;
36+
37+
protected function setUp() {
38+
parent::setUp();
39+
40+
$this->config = $this->createMock(IConfig::class);
41+
$this->outbox = new Outbox($this->config, 'user-principal-123');
42+
}
43+
44+
public function testGetACLFreeBusyEnabled() {
45+
$this->config->expects($this->once())
46+
->method('getAppValue')
47+
->with('dav', 'disableFreeBusy', 'no')
48+
->will($this->returnValue('no'));
49+
50+
$this->assertEquals([
51+
[
52+
'privilege' => '{DAV:}read',
53+
'principal' => 'user-principal-123',
54+
'protected' => true,
55+
],
56+
[
57+
'privilege' => '{DAV:}read',
58+
'principal' => 'user-principal-123/calendar-proxy-read',
59+
'protected' => true,
60+
],
61+
[
62+
'privilege' => '{DAV:}read',
63+
'principal' => 'user-principal-123/calendar-proxy-write',
64+
'protected' => true,
65+
],
66+
[
67+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send',
68+
'principal' => 'user-principal-123',
69+
'protected' => true,
70+
],
71+
[
72+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send',
73+
'principal' => 'user-principal-123/calendar-proxy-write',
74+
'protected' => true,
75+
],
76+
], $this->outbox->getACL());
77+
}
78+
79+
public function testGetACLFreeBusyDisabled() {
80+
$this->config->expects($this->once())
81+
->method('getAppValue')
82+
->with('dav', 'disableFreeBusy', 'no')
83+
->will($this->returnValue('yes'));
84+
85+
$this->assertEquals([
86+
[
87+
'privilege' => '{DAV:}read',
88+
'principal' => 'user-principal-123',
89+
'protected' => true,
90+
],
91+
[
92+
'privilege' => '{DAV:}read',
93+
'principal' => 'user-principal-123/calendar-proxy-read',
94+
'protected' => true,
95+
],
96+
[
97+
'privilege' => '{DAV:}read',
98+
'principal' => 'user-principal-123/calendar-proxy-write',
99+
'protected' => true,
100+
],
101+
[
102+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send-invite',
103+
'principal' => 'user-principal-123',
104+
'protected' => true,
105+
],
106+
[
107+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send-invite',
108+
'principal' => 'user-principal-123/calendar-proxy-write',
109+
'protected' => true,
110+
],
111+
[
112+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send-reply',
113+
'principal' => 'user-principal-123',
114+
'protected' => true,
115+
],
116+
[
117+
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-send-reply',
118+
'principal' => 'user-principal-123/calendar-proxy-write',
119+
'protected' => true,
120+
],
121+
], $this->outbox->getACL());
122+
}
123+
}

0 commit comments

Comments
 (0)