-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathSharingPlugin.php
More file actions
64 lines (50 loc) · 1.7 KB
/
Copy pathSharingPlugin.php
File metadata and controls
64 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\DAV\CalDAV;
use OCP\IAppConfig;
use OCP\IConfig;
use Override;
use Sabre\CalDAV\Xml\Property\AllowedSharingModes;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
class SharingPlugin extends ServerPlugin {
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
protected Server $server;
public function __construct(
private readonly IAppConfig $config,
) {
}
#[Override]
public function getFeatures(): array {
// May have to be changed to be detected
return ['calendarserver-sharing'];
}
#[Override]
public function getPluginName(): string {
return 'oc-calendar-sharing';
}
#[Override]
public function initialize(Server $server): void {
$this->server = $server;
$this->server->on('propFind', $this->propFind(...));
}
public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof Calendar) {
$propFind->handle('{' . self::NS_CALENDARSERVER . '}allowed-sharing-modes', function () use ($node) {
$canShare = (!$node->isSubscription() && $node->canWrite());
$canPublish = (!$node->isSubscription() && $node->canWrite());
if ($this->config->getValueBool('dav', 'limitAddressBookAndCalendarSharingToOwner')) {
$canShare = $canShare && ($node->getOwner() === $node->getPrincipalURI());
$canPublish = $canPublish && ($node->getOwner() === $node->getPrincipalURI());
}
if (!$this->config->getValueBool('core', 'shareapi_allow_links', true)) {
$canPublish = false;
}
return new AllowedSharingModes($canShare, $canPublish);
});
}
}
}