]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add ability to limit sharing to owner 22236/head
authorGeorg Ehrke <developer@georgehrke.com>
Tue, 11 Aug 2020 07:24:08 +0000 (09:24 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Tue, 18 Aug 2020 11:18:00 +0000 (13:18 +0200)
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php
apps/dav/lib/DAV/Sharing/Plugin.php
apps/dav/lib/Server.php
apps/dav/tests/unit/CardDAV/Sharing/PluginTest.php
apps/dav/tests/unit/DAV/Sharing/PluginTest.php

index eee651647cb498bf0ad62a245eb0628fac377d59..f34baffd784f761b707b2fa6c261c0ea304f93c0 100644 (file)
@@ -133,7 +133,12 @@ class PublishPlugin extends ServerPlugin {
                                $canShare = (!$node->isSubscription() && $node->canWrite());
                                $canPublish = (!$node->isSubscription() && $node->canWrite());
 
-                               return new AllowedSharingModes($canShare, $canPublish);
+                               if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') {
+                                       $canShare &= ($node->getOwner() === $node->getPrincipalURI());
+                                       $canPublish &= ($node->getOwner() === $node->getPrincipalURI());
+                               }
+
+                               return new AllowedSharingModes((bool)$canShare, (bool)$canPublish);
                        });
                }
        }
@@ -190,7 +195,14 @@ class PublishPlugin extends ServerPlugin {
 
                        // If there's no ACL support, we allow everything
                        if ($acl) {
+                               /** @var \Sabre\DAVACL\Plugin $acl */
                                $acl->checkPrivileges($path, '{DAV:}write');
+
+                               $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes';
+                               $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner();
+                               if ($limitSharingToOwner && !$isOwner) {
+                                       return;
+                               }
                        }
 
                        $node->setPublishStatus(true);
@@ -218,7 +230,14 @@ class PublishPlugin extends ServerPlugin {
 
                        // If there's no ACL support, we allow everything
                        if ($acl) {
+                               /** @var \Sabre\DAVACL\Plugin $acl */
                                $acl->checkPrivileges($path, '{DAV:}write');
+
+                               $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes';
+                               $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner();
+                               if ($limitSharingToOwner && !$isOwner) {
+                                       return;
+                               }
                        }
 
                        $node->setPublishStatus(false);
index f8967a788b979a63003bf81bde43d66c9edb9d51..06bc5b2157fa98d4e41d123a827c055e1284eeef 100644 (file)
@@ -27,6 +27,7 @@ namespace OCA\DAV\DAV\Sharing;
 use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\DAV\Sharing\Xml\Invite;
 use OCA\DAV\DAV\Sharing\Xml\ShareRequest;
+use OCP\IConfig;
 use OCP\IRequest;
 use Sabre\DAV\Exception\NotFound;
 use Sabre\DAV\INode;
@@ -46,15 +47,20 @@ class Plugin extends ServerPlugin {
        /** @var IRequest */
        private $request;
 
+       /** @var IConfig */
+       private $config;
+
        /**
         * Plugin constructor.
         *
         * @param Auth $authBackEnd
         * @param IRequest $request
+        * @param IConfig $config
         */
-       public function __construct(Auth $authBackEnd, IRequest $request) {
+       public function __construct(Auth $authBackEnd, IRequest $request, IConfig $config) {
                $this->auth = $authBackEnd;
                $this->request = $request;
+               $this->config = $config;
        }
 
        /**
@@ -164,6 +170,12 @@ class Plugin extends ServerPlugin {
                                if ($acl) {
                                        /** @var \Sabre\DAVACL\Plugin $acl */
                                        $acl->checkPrivileges($path, '{DAV:}write');
+
+                                       $limitSharingToOwner = $this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes';
+                                       $isOwner = $acl->getCurrentUserPrincipal() === $node->getOwner();
+                                       if ($limitSharingToOwner && !$isOwner) {
+                                               return;
+                                       }
                                }
 
                                $node->updateShares($message->set, $message->remove);
index e64abf43f75419d8395dfb032d72fa928a8cb816..44ba036de8720149c7c903021b7191e122115c64 100644 (file)
@@ -162,7 +162,7 @@ class Server {
                        $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
 
                        $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
-                       $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
+                       $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
                        $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
                                \OC::$server->getConfig(),
                                \OC::$server->getURLGenerator()
@@ -171,7 +171,7 @@ class Server {
 
                // addressbook plugins
                if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
-                       $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
+                       $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig()));
                        $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
                        $this->server->addPlugin(new VCFExportPlugin());
                        $this->server->addPlugin(new MultiGetExportPlugin());
index 146ead4ed3fc208a8dce0c8d536b35d036eb5480..472826ac2f772c4301b7f6b5a15ae5bc0de61276 100644 (file)
@@ -30,6 +30,7 @@ namespace OCA\DAV\Tests\unit\CardDAV\Sharing;
 use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\DAV\Sharing\IShareable;
 use OCA\DAV\DAV\Sharing\Plugin;
+use OCP\IConfig;
 use OCP\IRequest;
 use Sabre\DAV\Server;
 use Sabre\DAV\SimpleCollection;
@@ -55,7 +56,8 @@ class PluginTest extends TestCase {
 
                /** @var IRequest $request */
                $request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock();
-               $this->plugin = new Plugin($authBackend, $request);
+               $config = $this->createMock(IConfig::class);
+               $this->plugin = new Plugin($authBackend, $request, $config);
 
                $root = new SimpleCollection('root');
                $this->server = new \Sabre\DAV\Server($root);
index 038e0f9e7bf324e81f8b5afb0b0aa577ec520ce2..0b01f46ffec2b764ff63ebb687433cddb94d55f3 100644 (file)
@@ -30,6 +30,7 @@ namespace OCA\DAV\Tests\unit\DAV\Sharing;
 use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\DAV\Sharing\IShareable;
 use OCA\DAV\DAV\Sharing\Plugin;
+use OCP\IConfig;
 use OCP\IRequest;
 use Sabre\DAV\Server;
 use Sabre\DAV\SimpleCollection;
@@ -55,7 +56,8 @@ class PluginTest extends TestCase {
 
                /** @var IRequest $request */
                $request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock();
-               $this->plugin = new Plugin($authBackend, $request);
+               $config = $this->createMock(IConfig::class);
+               $this->plugin = new Plugin($authBackend, $request, $config);
 
                $root = new SimpleCollection('root');
                $this->server = new \Sabre\DAV\Server($root);