]> source.dussan.org Git - nextcloud-server.git/commitdiff
[WIP] Add logging to Scheduling Plugin 34865/head
authorAnna Larch <anna@nextcloud.com>
Fri, 28 Oct 2022 08:37:49 +0000 (10:37 +0200)
committerAnna Larch <anna@nextcloud.com>
Wed, 4 Jan 2023 15:58:00 +0000 (16:58 +0100)
Signed-off-by: Anna Larch <anna@nextcloud.com>
apps/dav/appinfo/v1/caldav.php
apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
apps/dav/lib/CalDAV/Schedule/Plugin.php
apps/dav/lib/Server.php
apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php

index 1f55266a21f258e3fb423b516a2ed8a143906acc..24a81e9af9400c3b5fb3022005d38fc89eaf14cb 100644 (file)
@@ -110,7 +110,7 @@ if ($debugging) {
 
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
 $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
-$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
+$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
 
 if ($sendInvitations) {
        $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
index e64c815753b948f4b4440696a3babe7769f44004..e92eae2d3f173ae6dd0e1f3a110287ea7d46af9f 100644 (file)
@@ -89,7 +89,7 @@ class InvitationResponseServer {
                // calendar plugins
                $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
                $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
-               $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
+               $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
                $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
                $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
                //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
index ed160cac2c226dad521bb4d599c08821fa0c66fe..ac8521acfee3a6a5e49f2617cadb42577f759ca3 100644 (file)
@@ -34,6 +34,7 @@ use OCA\DAV\CalDAV\CalDavBackend;
 use OCA\DAV\CalDAV\Calendar;
 use OCA\DAV\CalDAV\CalendarHome;
 use OCP\IConfig;
+use Psr\Log\LoggerInterface;
 use Sabre\CalDAV\ICalendar;
 use Sabre\DAV\INode;
 use Sabre\DAV\IProperties;
@@ -70,12 +71,14 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
 
        public const CALENDAR_USER_TYPE = '{' . self::NS_CALDAV . '}calendar-user-type';
        public const SCHEDULE_DEFAULT_CALENDAR_URL = '{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL';
+       private LoggerInterface $logger;
 
        /**
         * @param IConfig $config
         */
-       public function __construct(IConfig $config) {
+       public function __construct(IConfig $config, LoggerInterface $logger) {
                $this->config = $config;
+               $this->logger = $logger;
        }
 
        /**
@@ -166,7 +169,7 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
         * @inheritDoc
         */
        public function scheduleLocalDelivery(ITip\Message $iTipMessage):void {
-               /** @var Component|null $vevent */
+               /** @var VEvent|null $vevent */
                $vevent = $iTipMessage->message->VEVENT ?? null;
 
                // Strip VALARMs from incoming VEVENT
@@ -175,12 +178,13 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
                }
 
                parent::scheduleLocalDelivery($iTipMessage);
-
                // We only care when the message was successfully delivered locally
+               // Log all possible codes returned from the parent method that mean something went wrong
+               // 3.7, 3.8, 5.0, 5.2
                if ($iTipMessage->scheduleStatus !== '1.2;Message delivered locally') {
+                       $this->logger->debug('Message not delivered locally with status: ' . $iTipMessage->scheduleStatus);
                        return;
                }
-
                // We only care about request. reply and cancel are properly handled
                // by parent::scheduleLocalDelivery already
                if (strcasecmp($iTipMessage->method, 'REQUEST') !== 0) {
@@ -196,26 +200,31 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
                $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
                $calendarUserType = $this->getCalendarUserTypeForPrincipal($principalUri);
                if (strcasecmp($calendarUserType, 'ROOM') !== 0 && strcasecmp($calendarUserType, 'RESOURCE') !== 0) {
+                       $this->logger->debug('Calendar user type is room or resource, not processing further');
                        return;
                }
 
                $attendee = $this->getCurrentAttendee($iTipMessage);
                if (!$attendee) {
+                       $this->logger->debug('No attendee set for scheduling message');
                        return;
                }
 
                // We only respond when a response was actually requested
                $rsvp = $this->getAttendeeRSVP($attendee);
                if (!$rsvp) {
+                       $this->logger->debug('No RSVP requested for attendee ' . $attendee->getValue());
                        return;
                }
 
                if (!$vevent) {
+                       $this->logger->debug('No VEVENT set to process on scheduling message');
                        return;
                }
 
                // We don't support autoresponses for recurrencing events for now
                if (isset($vevent->RRULE) || isset($vevent->RDATE)) {
+                       $this->logger->debug('VEVENT is a recurring event, autoresponding not supported');
                        return;
                }
 
index 437a425fcd35150f9d35a96a24c576930bf96c04..a5833e5175f48ab3ddef9b8480d17918161f94d0 100644 (file)
@@ -171,7 +171,7 @@ class Server {
                if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
                        $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
                        $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), $logger));
-                       $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
+                       $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
                        if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
                                $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
                        }
index b651379c2bda1ec5890f72d9615a24f5d349a3da..797023cdfaee2a0ffa2326f08c3fe3938b136091 100644 (file)
@@ -57,6 +57,9 @@ class PluginTest extends TestCase {
        /** @var IConfig|MockObject  */
        private $config;
 
+       /** @var MockObject|LoggerInterface */
+       private $logger;
+
        protected function setUp(): void {
                parent::setUp();
 
@@ -70,12 +73,14 @@ class PluginTest extends TestCase {
                $this->server->httpResponse = $response;
                $this->server->xml = new Service();
 
-               $this->plugin = new Plugin($this->config);
+               $this->logger = $this->createMock(LoggerInterface::class);
+
+               $this->plugin = new Plugin($this->config, $this->logger);
                $this->plugin->initialize($this->server);
        }
 
        public function testInitialize() {
-               $plugin = new Plugin($this->config);
+               $plugin = new Plugin($this->config, $this->logger);
 
                $this->server->expects($this->exactly(10))
                        ->method('on')