From bbaf2af41617deca82c99fddd3151b847f00fa9a Mon Sep 17 00:00:00 2001 From: Pawel Boguslawski Date: Fri, 14 Oct 2022 13:18:04 +0200 Subject: [PATCH] Disable sharing calendars via link adjusted Fixes: 45eefc221d4439c99fd2c8badfe93dc3af40f028 Related: https://github.com/nextcloud/server/pull/34372 Author-Change-Id: IB#1126264 Signed-off-by: Pawel Boguslawski --- apps/dav/lib/CalDAV/CalDavBackend.php | 9 --------- apps/dav/lib/CalDAV/PublicCalendarRoot.php | 6 ++++++ apps/dav/lib/CalDAV/Publishing/PublishPlugin.php | 6 ------ apps/dav/lib/Server.php | 10 ++++++---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 9bd776b293174..a894b65d75604 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -3,7 +3,6 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2018 Georg Ehrke * @copyright Copyright (c) 2020, leith abdulla () - * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Chih-Hsuan Yen * @author Christoph Wurst @@ -498,10 +497,6 @@ public function getUsersOwnCalendars($principalUri) { * @return array */ public function getPublicCalendars() { - // Sharing via link must be enabled. - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'no' ) { - return array_values([]); - } $fields = array_column($this->propertyMap, 0); $fields[] = 'a.id'; $fields[] = 'a.uri'; @@ -560,10 +555,6 @@ public function getPublicCalendars() { * @throws NotFound */ public function getPublicCalendar($uri) { - // Sharing via link must be enabled. - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'no' ) { - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); - } $fields = array_column($this->propertyMap, 0); $fields[] = 'a.id'; $fields[] = 'a.uri'; diff --git a/apps/dav/lib/CalDAV/PublicCalendarRoot.php b/apps/dav/lib/CalDAV/PublicCalendarRoot.php index 4f7dfea268227..1d20f505773a1 100644 --- a/apps/dav/lib/CalDAV/PublicCalendarRoot.php +++ b/apps/dav/lib/CalDAV/PublicCalendarRoot.php @@ -1,6 +1,7 @@ * @author Georg Ehrke @@ -29,6 +30,7 @@ use OCP\IL10N; use Psr\Log\LoggerInterface; use Sabre\DAV\Collection; +use Sabre\DAV\Exception\Forbidden; class PublicCalendarRoot extends Collection { @@ -70,6 +72,10 @@ public function getName() { * @inheritdoc */ public function getChild($name) { + // Sharing via link is allowed by default, but if the option is set it should be checked. + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'no' ) { + throw new \Sabre\DAV\Exception\Forbidden(); + } $calendar = $this->caldavBackend->getPublicCalendar($name); return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); } diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index e0078fa1fefd6..aabf78da1aa8b 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -1,7 +1,6 @@ - * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Christoph Wurst * @author Georg Ehrke @@ -206,11 +205,6 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) } } - // Sharing via link must be enabled. - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'no') { - return; - } - $node->setPublishStatus(true); // iCloud sends back the 202, so we will too. diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index a5833e5175f48..1a8f7058e92a9 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -184,10 +184,12 @@ public function __construct(IRequest $request, string $baseUri) { $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $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() - )); + if (\OC::$server->getConfig()->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( + \OC::$server->getConfig(), + \OC::$server->getURLGenerator() + )); + } } // addressbook plugins