]> source.dussan.org Git - nextcloud-server.git/commitdiff
Export the CalDAV trash bin retention duration as property 27348/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Wed, 2 Jun 2021 14:00:29 +0000 (16:00 +0200)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Wed, 2 Jun 2021 16:10:07 +0000 (18:10 +0200)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/dav/lib/CalDAV/RetentionService.php
apps/dav/lib/CalDAV/Trashbin/Plugin.php
apps/dav/lib/Server.php

index 934e6f71530e96b69d31454f565e14f189d7a807..7342b719c81015817aab6caa91c1bedad3ee8d48 100644 (file)
@@ -51,8 +51,8 @@ class RetentionService {
                $this->calDavBackend = $calDavBackend;
        }
 
-       public function cleanUp(): void {
-               $retentionTime = max(
+       public function getDuration(): int {
+               return max(
                        (int) $this->config->getAppValue(
                                Application::APP_ID,
                                self::RETENTION_CONFIG_KEY,
@@ -60,6 +60,10 @@ class RetentionService {
                        ),
                        0 // Just making sure we don't delete things in the future when a negative number is passed
                );
+       }
+
+       public function cleanUp(): void {
+               $retentionTime = $this->getDuration();
                $now = $this->time->getTime();
 
                $calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime);
index fd47e1faa30fae0ab3baa08f7de6aee6babc5ebe..93f17cc5b7c7d9b1f9caf44796f87a096526a0ba 100644 (file)
@@ -27,6 +27,7 @@ namespace OCA\DAV\CalDAV\Trashbin;
 
 use Closure;
 use OCA\DAV\CalDAV\Calendar;
+use OCA\DAV\CalDAV\RetentionService;
 use OCP\IRequest;
 use Sabre\DAV\Exception\NotFound;
 use Sabre\DAV\INode;
@@ -41,15 +42,21 @@ use function implode;
 class Plugin extends ServerPlugin {
        public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at';
        public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri';
+       public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration';
 
        /** @var bool */
        private $disableTrashbin;
 
+       /** @var RetentionService */
+       private $retentionService;
+
        /** @var Server */
        private $server;
 
-       public function __construct(IRequest $request) {
+       public function __construct(IRequest $request,
+                                                               RetentionService $retentionService) {
                $this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1';
+               $this->retentionService = $retentionService;
        }
 
        public function initialize(Server $server): void {
@@ -100,6 +107,11 @@ class Plugin extends ServerPlugin {
                                return $node->getCalendarUri();
                        });
                }
+               if ($node instanceof TrashbinHome) {
+                       $propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
+                               return $this->retentionService->getDuration();
+                       });
+               }
        }
 
        public function getFeatures(): array {
index 0999da3dbe1ee33d8cafee94d06d49e801593d6a..50c643801845238438389d77881a377dfe4f9716 100644 (file)
@@ -165,7 +165,7 @@ class Server {
                                $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
                        }
 
-                       $this->server->addPlugin(new \OCA\DAV\CalDAV\Trashbin\Plugin($request));
+                       $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
                        $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request));
                        $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());