Skip to content

Commit

Permalink
Export the CalDAV trash bin retention duration as property
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Jun 2, 2021
1 parent 6578a93 commit f1444ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions apps/dav/lib/CalDAV/RetentionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ public function __construct(IConfig $config,
$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,
(string) self::DEFAULT_RETENTION_SECONDS
),
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);
Expand Down
14 changes: 13 additions & 1 deletion apps/dav/lib/CalDAV/Trashbin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use Closure;
use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\RetentionService;
use OCP\IRequest;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode;
Expand All @@ -41,15 +42,21 @@
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 {
Expand Down Expand Up @@ -100,6 +107,11 @@ private function propFind(
return $node->getCalendarUri();
});
}
if ($node instanceof TrashbinHome) {
$propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
return $this->retentionService->getDuration();
});
}
}

public function getFeatures(): array {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function __construct(IRequest $request, $baseUri) {
$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());

Expand Down

0 comments on commit f1444ea

Please sign in to comment.