Skip to content

Commit 5fc3f08

Browse files
Export the CalDAV trash bin retention duration as property
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 6578a93 commit 5fc3f08

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

apps/dav/lib/CalDAV/RetentionService.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,19 @@ public function __construct(IConfig $config,
5151
$this->calDavBackend = $calDavBackend;
5252
}
5353

54-
public function cleanUp(): void {
55-
$retentionTime = max(
54+
public function getDuration(): int {
55+
return max(
5656
(int) $this->config->getAppValue(
5757
Application::APP_ID,
5858
self::RETENTION_CONFIG_KEY,
5959
(string) self::DEFAULT_RETENTION_SECONDS
6060
),
6161
0 // Just making sure we don't delete things in the future when a negative number is passed
6262
);
63+
}
64+
65+
public function cleanUp(): void {
66+
$retentionTime = $this->getDuration();
6367
$now = $this->time->getTime();
6468

6569
$calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime);

apps/dav/lib/CalDAV/Trashbin/Plugin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use Closure;
2929
use OCA\DAV\CalDAV\Calendar;
30+
use OCA\DAV\CalDAV\RetentionService;
3031
use OCP\IRequest;
3132
use Sabre\DAV\Exception\NotFound;
3233
use Sabre\DAV\INode;
@@ -41,15 +42,21 @@
4142
class Plugin extends ServerPlugin {
4243
public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at';
4344
public const PROPERTY_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri';
45+
public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}caldav-trashbin-retention-duration';
4446

4547
/** @var bool */
4648
private $disableTrashbin;
4749

50+
/** @var RetentionService */
51+
private $retentionService;
52+
4853
/** @var Server */
4954
private $server;
5055

51-
public function __construct(IRequest $request) {
56+
public function __construct(IRequest $request,
57+
RetentionService $retentionService) {
5258
$this->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1';
59+
$this->retentionService = $retentionService;
5360
}
5461

5562
public function initialize(Server $server): void {
@@ -100,6 +107,11 @@ private function propFind(
100107
return $node->getCalendarUri();
101108
});
102109
}
110+
if ($node instanceof TrashbinHome) {
111+
$propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
112+
return $this->retentionService->getDuration();
113+
});
114+
}
103115
}
104116

105117
public function getFeatures(): array {

apps/dav/lib/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function __construct(IRequest $request, $baseUri) {
165165
$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
166166
}
167167

168-
$this->server->addPlugin(new \OCA\DAV\CalDAV\Trashbin\Plugin($request));
168+
$this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
169169
$this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request));
170170
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
171171

0 commit comments

Comments
 (0)