Skip to content

Commit 4fd3cba

Browse files
committed
Extract cs:allowed-sharing-modes into it's own plugin
So that it's still there when we disable the PublishPlugin Signed-off-by: Thomas Citharel <[email protected]>
1 parent b9f276e commit 4fd3cba

9 files changed

Lines changed: 137 additions & 53 deletions

File tree

apps/dav/composer/autoload.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33
// autoload.php @generated by Composer
44

55
if (PHP_VERSION_ID < 50600) {
6-
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
7-
exit(1);
6+
if (!headers_sent()) {
7+
header('HTTP/1.1 500 Internal Server Error');
8+
}
9+
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
10+
if (!ini_get('display_errors')) {
11+
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12+
fwrite(STDERR, $err);
13+
} elseif (!headers_sent()) {
14+
echo $err;
15+
}
16+
}
17+
trigger_error(
18+
$err,
19+
E_USER_ERROR
20+
);
821
}
922

1023
require_once __DIR__ . '/composer/autoload_real.php';

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter' => $baseDir . '/../lib/CalDAV/Search/Xml/Filter/PropFilter.php',
9393
'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter' => $baseDir . '/../lib/CalDAV/Search/Xml/Filter/SearchTermFilter.php',
9494
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport' => $baseDir . '/../lib/CalDAV/Search/Xml/Request/CalendarSearchReport.php',
95+
'OCA\\DAV\\CalDAV\\SharingPlugin' => $baseDir . '/../lib/CalDAV/SharingPlugin.php',
9596
'OCA\\DAV\\CalDAV\\Trashbin\\DeletedCalendarObject' => $baseDir . '/../lib/CalDAV/Trashbin/DeletedCalendarObject.php',
9697
'OCA\\DAV\\CalDAV\\Trashbin\\DeletedCalendarObjectsCollection' => $baseDir . '/../lib/CalDAV/Trashbin/DeletedCalendarObjectsCollection.php',
9798
'OCA\\DAV\\CalDAV\\Trashbin\\Plugin' => $baseDir . '/../lib/CalDAV/Trashbin/Plugin.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ComposerStaticInitDAV
107107
'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter' => __DIR__ . '/..' . '/../lib/CalDAV/Search/Xml/Filter/PropFilter.php',
108108
'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter' => __DIR__ . '/..' . '/../lib/CalDAV/Search/Xml/Filter/SearchTermFilter.php',
109109
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport' => __DIR__ . '/..' . '/../lib/CalDAV/Search/Xml/Request/CalendarSearchReport.php',
110+
'OCA\\DAV\\CalDAV\\SharingPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/SharingPlugin.php',
110111
'OCA\\DAV\\CalDAV\\Trashbin\\DeletedCalendarObject' => __DIR__ . '/..' . '/../lib/CalDAV/Trashbin/DeletedCalendarObject.php',
111112
'OCA\\DAV\\CalDAV\\Trashbin\\DeletedCalendarObjectsCollection' => __DIR__ . '/..' . '/../lib/CalDAV/Trashbin/DeletedCalendarObjectsCollection.php',
112113
'OCA\\DAV\\CalDAV\\Trashbin\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Trashbin/Plugin.php',

apps/dav/composer/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => '144514e49e25b7b123fd535902fee97fa39fb446',
6+
'reference' => 'b9f276eca620fef1b52bd2ba0c53b11fe859cdcf',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => '144514e49e25b7b123fd535902fee97fa39fb446',
16+
'reference' => 'b9f276eca620fef1b52bd2ba0c53b11fe859cdcf',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../',
1919
'aliases' => array(),

apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCA\DAV\Events\SabrePluginAuthInitEvent;
3636
use OCA\DAV\RootCollection;
3737
use OCP\EventDispatcher\IEventDispatcher;
38+
use OCP\IConfig;
3839
use Psr\Log\LoggerInterface;
3940
use Sabre\VObject\ITip\Message;
4041

@@ -94,6 +95,7 @@ public function __construct(bool $public = true) {
9495
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
9596
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
9697
//$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
98+
$this->server->addPlugin(new \OCA\DAV\CalDAV\SharingPlugin(\OC::$server->get(IConfig::class)));
9799
$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
98100
\OC::$server->getConfig(),
99101
\OC::$server->getURLGenerator()

apps/dav/lib/CalDAV/Publishing/PublishPlugin.php

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
3232
use OCP\IConfig;
3333
use OCP\IURLGenerator;
34-
use Sabre\CalDAV\Xml\Property\AllowedSharingModes;
3534
use Sabre\DAV\Exception\NotFound;
3635
use Sabre\DAV\INode;
3736
use Sabre\DAV\PropFind;
@@ -43,33 +42,10 @@
4342
class PublishPlugin extends ServerPlugin {
4443
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
4544

46-
/**
47-
* Reference to SabreDAV server object.
48-
*
49-
* @var \Sabre\DAV\Server
50-
*/
51-
protected $server;
52-
53-
/**
54-
* Config instance to get instance secret.
55-
*
56-
* @var IConfig
57-
*/
58-
protected $config;
45+
protected Server $server;
46+
protected IConfig $config;
47+
protected IURLGenerator $urlGenerator;
5948

60-
/**
61-
* URL Generator for absolute URLs.
62-
*
63-
* @var IURLGenerator
64-
*/
65-
protected $urlGenerator;
66-
67-
/**
68-
* PublishPlugin constructor.
69-
*
70-
* @param IConfig $config
71-
* @param IURLGenerator $urlGenerator
72-
*/
7349
public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
7450
$this->config = $config;
7551
$this->urlGenerator = $urlGenerator;
@@ -83,9 +59,9 @@ public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
8359
*
8460
* @return string[]
8561
*/
86-
public function getFeatures() {
62+
public function getFeatures(): array {
8763
// May have to be changed to be detected
88-
return ['oc-calendar-publishing', 'calendarserver-sharing'];
64+
return ['oc-calendar-publishing'];
8965
}
9066

9167
/**
@@ -96,7 +72,7 @@ public function getFeatures() {
9672
*
9773
* @return string
9874
*/
99-
public function getPluginName() {
75+
public function getPluginName(): string {
10076
return 'oc-calendar-publishing';
10177
}
10278

@@ -128,18 +104,6 @@ public function propFind(PropFind $propFind, INode $node) {
128104
return new Publisher($publishUrl, true);
129105
}
130106
});
131-
132-
$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) {
133-
$canShare = (!$node->isSubscription() && $node->canWrite());
134-
$canPublish = (!$node->isSubscription() && $node->canWrite());
135-
136-
if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') {
137-
$canShare = $canShare && ($node->getOwner() === $node->getPrincipalURI());
138-
$canPublish = $canPublish && ($node->getOwner() === $node->getPrincipalURI());
139-
}
140-
141-
return new AllowedSharingModes($canShare, $canPublish);
142-
});
143107
}
144108
}
145109

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2022 Thomas Citharel <[email protected]>
4+
*
5+
* @author Thomas Citharel <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace OCA\DAV\CalDAV;
24+
25+
use OCP\IConfig;
26+
use Sabre\CalDAV\Xml\Property\AllowedSharingModes;
27+
use Sabre\DAV\INode;
28+
use Sabre\DAV\PropFind;
29+
use Sabre\DAV\Server;
30+
use Sabre\DAV\ServerPlugin;
31+
32+
class SharingPlugin extends ServerPlugin {
33+
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
34+
35+
protected Server $server;
36+
protected IConfig $config;
37+
38+
public function __construct(IConfig $config) {
39+
$this->config = $config;
40+
}
41+
42+
/**
43+
* This method should return a list of server-features.
44+
*
45+
* This is for example 'versioning' and is added to the DAV: header
46+
* in an OPTIONS response.
47+
*
48+
* @return string[]
49+
*/
50+
public function getFeatures(): array {
51+
// May have to be changed to be detected
52+
return ['calendarserver-sharing'];
53+
}
54+
55+
/**
56+
* Returns a plugin name.
57+
*
58+
* Using this name other plugins will be able to access other plugins
59+
* using Sabre\DAV\Server::getPlugin
60+
*
61+
* @return string
62+
*/
63+
public function getPluginName(): string {
64+
return 'oc-calendar-sharing';
65+
}
66+
67+
/**
68+
* This initializes the plugin.
69+
*
70+
* This function is called by Sabre\DAV\Server, after
71+
* addPlugin is called.
72+
*
73+
* This method should set up the required event subscriptions.
74+
*
75+
* @param Server $server
76+
*/
77+
public function initialize(Server $server) {
78+
$this->server = $server;
79+
80+
$this->server->on('propFind', [$this, 'propFind']);
81+
}
82+
83+
public function propFind(PropFind $propFind, INode $node) {
84+
if ($node instanceof Calendar) {
85+
$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) {
86+
$canShare = (!$node->isSubscription() && $node->canWrite());
87+
$canPublish = (!$node->isSubscription() && $node->canWrite());
88+
89+
if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') {
90+
$canShare = $canShare && ($node->getOwner() === $node->getPrincipalURI());
91+
$canPublish = $canPublish && ($node->getOwner() === $node->getPrincipalURI());
92+
}
93+
94+
if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
95+
$canPublish = false;
96+
}
97+
98+
return new AllowedSharingModes($canShare, $canPublish);
99+
});
100+
}
101+
}
102+
}

apps/dav/lib/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
use OCP\AppFramework\Http\Response;
7575
use OCP\Diagnostics\IEventLogger;
7676
use OCP\EventDispatcher\IEventDispatcher;
77+
use OCP\IConfig;
7778
use OCP\IRequest;
7879
use OCP\Profiler\IProfiler;
7980
use OCP\SabrePluginEvent;
@@ -182,6 +183,7 @@ public function __construct(IRequest $request, string $baseUri) {
182183

183184
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
184185
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
186+
$this->server->addPlugin(new \OCA\DAV\CalDAV\SharingPlugin(\OC::$server->get(IConfig::class)));
185187
if (\OC::$server->getConfig()->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
186188
$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
187189
\OC::$server->getConfig(),

apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\IConfig;
3131
use OCP\IRequest;
3232
use OCP\IURLGenerator;
33+
use PHPUnit\Framework\MockObject\MockObject;
3334
use Sabre\DAV\Server;
3435
use Sabre\DAV\SimpleCollection;
3536
use Sabre\HTTP\Request;
@@ -38,15 +39,13 @@
3839

3940
class PublishingTest extends TestCase {
4041

41-
/** @var PublishPlugin */
42-
private $plugin;
43-
/** @var Server */
44-
private $server;
45-
/** @var Calendar | \PHPUnit\Framework\MockObject\MockObject */
42+
private PublishPlugin $plugin;
43+
private Server $server;
44+
/** @var Calendar | MockObject */
4645
private $book;
47-
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
46+
/** @var IConfig | MockObject */
4847
private $config;
49-
/** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
48+
/** @var IURLGenerator | MockObject */
5049
private $urlGenerator;
5150

5251
protected function setUp(): void {

0 commit comments

Comments
 (0)