Skip to content

Commit 38b69a3

Browse files
committed
Add ability to limit sharing to owner
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
1 parent ccb1675 commit 38b69a3

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ public function propFind(PropFind $propFind, INode $node) {
130130
});
131131

132132
$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) {
133-
$canShare = (!$node->isSubscription() && $node->canWrite());
134-
$canPublish = (!$node->isSubscription() && $node->canWrite());
133+
if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') {
134+
$canShare = (!$node->isSubscription() && $node->getOwner() === $node->getPrincipalURI());
135+
$canPublish = (!$node->isSubscription() && $node->getOwner() === $node->getPrincipalURI());
136+
} else {
137+
$canShare = (!$node->isSubscription() && $node->canWrite());
138+
$canPublish = (!$node->isSubscription() && $node->canWrite());
139+
}
135140

136141
return new AllowedSharingModes($canShare, $canPublish);
137142
});
@@ -190,7 +195,14 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
190195

191196
// If there's no ACL support, we allow everything
192197
if ($acl) {
198+
/** @var \Sabre\DAVACL\Plugin $acl */
193199
$acl->checkPrivileges($path, '{DAV:}write');
200+
201+
$limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes';
202+
$isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner();
203+
if ($limitSharingToOwner && !$isOwner) {
204+
return;
205+
}
194206
}
195207

196208
$node->setPublishStatus(true);
@@ -218,7 +230,13 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
218230

219231
// If there's no ACL support, we allow everything
220232
if ($acl) {
233+
/** @var \Sabre\DAVACL\Plugin $acl */
221234
$acl->checkPrivileges($path, '{DAV:}write');
235+
236+
if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', false)
237+
&& $acl->getCurrentUserPrincipal() !== $node->getOwner()) {
238+
return;
239+
}
222240
}
223241

224242
$node->setPublishStatus(false);

apps/dav/lib/DAV/Sharing/Plugin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCA\DAV\Connector\Sabre\Auth;
2828
use OCA\DAV\DAV\Sharing\Xml\Invite;
2929
use OCA\DAV\DAV\Sharing\Xml\ShareRequest;
30+
use OCP\IConfig;
3031
use OCP\IRequest;
3132
use Sabre\DAV\Exception\NotFound;
3233
use Sabre\DAV\INode;
@@ -46,15 +47,20 @@ class Plugin extends ServerPlugin {
4647
/** @var IRequest */
4748
private $request;
4849

50+
/** @var IConfig */
51+
private $config;
52+
4953
/**
5054
* Plugin constructor.
5155
*
5256
* @param Auth $authBackEnd
5357
* @param IRequest $request
58+
* @param IConfig $config
5459
*/
55-
public function __construct(Auth $authBackEnd, IRequest $request) {
60+
public function __construct(Auth $authBackEnd, IRequest $request, IConfig $config) {
5661
$this->auth = $authBackEnd;
5762
$this->request = $request;
63+
$this->config = $config;
5864
}
5965

6066
/**
@@ -164,6 +170,12 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
164170
if ($acl) {
165171
/** @var \Sabre\DAVACL\Plugin $acl */
166172
$acl->checkPrivileges($path, '{DAV:}write');
173+
174+
$limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes';
175+
$isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner();
176+
if ($limitSharingToOwner && !$isOwner) {
177+
return;
178+
}
167179
}
168180

169181
$node->updateShares($message->set, $message->remove);

0 commit comments

Comments
 (0)