Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-10-12 17:30:00 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-10-15 10:35:29 +0300
commit0401d6dc0ff33d31982f7aa7e752378d98d82f9d (patch)
treec1d4de4a3280bb338217c15d05bb3f59292462a2 /apps
parentacbe4b46c39703f0d3c1e205d4609c7a2607b4b1 (diff)
Add create method to extended calendar implementation
Signed-off-by: Anna Larch <anna@nextcloud.com> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/composer/composer/autoload_classmap.php2
-rw-r--r--apps/dav/composer/composer/autoload_static.php2
-rw-r--r--apps/dav/lib/CalDAV/Auth/CustomPrincipalPlugin.php38
-rw-r--r--apps/dav/lib/CalDAV/Auth/PublicPrincipalPlugin.php37
-rw-r--r--apps/dav/lib/CalDAV/CalendarImpl.php42
-rw-r--r--apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php17
6 files changed, 128 insertions, 10 deletions
diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php
index daf2cff3161..62c41a0828d 100644
--- a/apps/dav/composer/composer/autoload_classmap.php
+++ b/apps/dav/composer/composer/autoload_classmap.php
@@ -33,6 +33,8 @@ return array(
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Calendar' => $baseDir . '/../lib/CalDAV/Activity/Setting/Calendar.php',
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Event' => $baseDir . '/../lib/CalDAV/Activity/Setting/Event.php',
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Todo' => $baseDir . '/../lib/CalDAV/Activity/Setting/Todo.php',
+ 'OCA\\DAV\\CalDAV\\Auth\\CustomPrincipalPlugin' => $baseDir . '/../lib/CalDAV/Auth/CustomPrincipalPlugin.php',
+ 'OCA\\DAV\\CalDAV\\Auth\\PublicPrincipalPlugin' => $baseDir . '/../lib/CalDAV/Auth/PublicPrincipalPlugin.php',
'OCA\\DAV\\CalDAV\\BirthdayCalendar\\EnablePlugin' => $baseDir . '/../lib/CalDAV/BirthdayCalendar/EnablePlugin.php',
'OCA\\DAV\\CalDAV\\BirthdayService' => $baseDir . '/../lib/CalDAV/BirthdayService.php',
'OCA\\DAV\\CalDAV\\CachedSubscription' => $baseDir . '/../lib/CalDAV/CachedSubscription.php',
diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php
index d00299ed047..5d5f57eb51b 100644
--- a/apps/dav/composer/composer/autoload_static.php
+++ b/apps/dav/composer/composer/autoload_static.php
@@ -48,6 +48,8 @@ class ComposerStaticInitDAV
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Calendar.php',
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Event' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Event.php',
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Todo' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Todo.php',
+ 'OCA\\DAV\\CalDAV\\Auth\\CustomPrincipalPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Auth/CustomPrincipalPlugin.php',
+ 'OCA\\DAV\\CalDAV\\Auth\\PublicPrincipalPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Auth/PublicPrincipalPlugin.php',
'OCA\\DAV\\CalDAV\\BirthdayCalendar\\EnablePlugin' => __DIR__ . '/..' . '/../lib/CalDAV/BirthdayCalendar/EnablePlugin.php',
'OCA\\DAV\\CalDAV\\BirthdayService' => __DIR__ . '/..' . '/../lib/CalDAV/BirthdayService.php',
'OCA\\DAV\\CalDAV\\CachedSubscription' => __DIR__ . '/..' . '/../lib/CalDAV/CachedSubscription.php',
diff --git a/apps/dav/lib/CalDAV/Auth/CustomPrincipalPlugin.php b/apps/dav/lib/CalDAV/Auth/CustomPrincipalPlugin.php
new file mode 100644
index 00000000000..89e50c7da6b
--- /dev/null
+++ b/apps/dav/lib/CalDAV/Auth/CustomPrincipalPlugin.php
@@ -0,0 +1,38 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * CalDAV App
+ *
+ * @copyright 2021 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\CalDAV\Auth;
+
+use Sabre\DAV\Auth\Plugin;
+
+/**
+ * Set a custom principal uri to allow public requests to its calendar
+ */
+class CustomPrincipalPlugin extends Plugin {
+ public function setCurrentPrincipal(?string $currentPrincipal): void {
+ $this->currentPrincipal = $currentPrincipal;
+ }
+}
diff --git a/apps/dav/lib/CalDAV/Auth/PublicPrincipalPlugin.php b/apps/dav/lib/CalDAV/Auth/PublicPrincipalPlugin.php
new file mode 100644
index 00000000000..96669558818
--- /dev/null
+++ b/apps/dav/lib/CalDAV/Auth/PublicPrincipalPlugin.php
@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * CalDAV App
+ *
+ * @copyright 2021 Anna Larch <anna.larch@gmx.net>
+ *
+ * @author Anna Larch <anna.larch@gmx.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\DAV\CalDAV\Auth;
+
+use Sabre\DAV\Auth\Plugin;
+
+/**
+ * Defines the public facing principal option
+ */
+class PublicPrincipalPlugin extends Plugin {
+ public function getCurrentPrincipal(): ?string {
+ return 'principals/system/public';
+ }
+}
diff --git a/apps/dav/lib/CalDAV/CalendarImpl.php b/apps/dav/lib/CalDAV/CalendarImpl.php
index 356f2800031..ed37c0a745d 100644
--- a/apps/dav/lib/CalDAV/CalendarImpl.php
+++ b/apps/dav/lib/CalDAV/CalendarImpl.php
@@ -27,10 +27,14 @@ declare(strict_types=1);
*/
namespace OCA\DAV\CalDAV;
-use OCP\Calendar\ICalendar;
+use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
+use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
+use OCP\Calendar\Exceptions\CalendarException;
+use OCP\Calendar\ICreateFromString;
use OCP\Constants;
+use Sabre\DAV\Exception\Conflict;
-class CalendarImpl implements ICalendar {
+class CalendarImpl implements ICreateFromString {
/** @var CalDavBackend */
private $backend;
@@ -48,7 +52,8 @@ class CalendarImpl implements ICalendar {
* @param array $calendarInfo
* @param CalDavBackend $backend
*/
- public function __construct(Calendar $calendar, array $calendarInfo,
+ public function __construct(Calendar $calendar,
+ array $calendarInfo,
CalDavBackend $backend) {
$this->calendar = $calendar;
$this->calendarInfo = $calendarInfo;
@@ -120,4 +125,35 @@ class CalendarImpl implements ICalendar {
return $result;
}
+
+ /**
+ * Create a new calendar event for this calendar
+ * by way of an ICS string
+ *
+ * @param string $name the file name - needs to contan the .ics ending
+ * @param string $calendarData a string containing a valid VEVENT ics
+ *
+ * @throws CalendarException
+ */
+ public function createFromString(string $name, string $calendarData): void {
+ $server = new InvitationResponseServer(false);
+
+ /** @var CustomPrincipalPlugin $plugin */
+ $plugin = $server->server->getPlugin('auth');
+ // we're working around the previous implementation
+ // that only allowed the public system principal to be used
+ // so set the custom principal here
+ $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());
+
+ $stream = fopen('php://memory', 'rb+');
+ fwrite($stream, $calendarData);
+ rewind($stream);
+ try {
+ $server->server->createFile($name, $stream);
+ } catch (Conflict $e) {
+ throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e);
+ } finally {
+ fclose($stream);
+ }
+ }
}
diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
index d1ea6902af3..90e2e478e1c 100644
--- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
+++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
@@ -26,6 +26,8 @@
namespace OCA\DAV\CalDAV\InvitationResponse;
use OCA\DAV\AppInfo\PluginManager;
+use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
+use OCA\DAV\CalDAV\Auth\PublicPrincipalPlugin;
use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCA\DAV\Connector\Sabre\CachingTree;
@@ -33,7 +35,6 @@ use OCA\DAV\Connector\Sabre\DavAclPlugin;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\DAV\RootCollection;
use OCP\EventDispatcher\IEventDispatcher;
-use Sabre\DAV\Auth\Plugin;
use Sabre\VObject\ITip\Message;
class InvitationResponseServer {
@@ -44,7 +45,7 @@ class InvitationResponseServer {
/**
* InvitationResponseServer constructor.
*/
- public function __construct() {
+ public function __construct(bool $public = true) {
$baseUri = \OC::$WEBROOT . '/remote.php/dav/';
$logger = \OC::$server->getLogger();
/** @var IEventDispatcher $dispatcher */
@@ -62,11 +63,13 @@ class InvitationResponseServer {
$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
$this->server->addPlugin(new AnonymousOptionsPlugin());
- $this->server->addPlugin(new class() extends Plugin {
- public function getCurrentPrincipal() {
- return 'principals/system/public';
- }
- });
+
+ // allow custom principal uri option
+ if ($public) {
+ $this->server->addPlugin(new PublicPrincipalPlugin());
+ } else {
+ $this->server->addPlugin(new CustomPrincipalPlugin());
+ }
// allow setup of additional auth backends
$event = new SabrePluginAuthInitEvent($this->server);