Export the CalDAV trash bin retention duration as property

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-06-02 16:00:29 +02:00
parent 6578a93463
commit f1444eac5d
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
3 changed files with 20 additions and 4 deletions

View File

@ -51,8 +51,8 @@ class RetentionService {
$this->calDavBackend = $calDavBackend; $this->calDavBackend = $calDavBackend;
} }
public function cleanUp(): void { public function getDuration(): int {
$retentionTime = max( return max(
(int) $this->config->getAppValue( (int) $this->config->getAppValue(
Application::APP_ID, Application::APP_ID,
self::RETENTION_CONFIG_KEY, 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 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(); $now = $this->time->getTime();
$calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime); $calendars = $this->calDavBackend->getDeletedCalendars($now - $retentionTime);

View File

@ -27,6 +27,7 @@ namespace OCA\DAV\CalDAV\Trashbin;
use Closure; use Closure;
use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\RetentionService;
use OCP\IRequest; use OCP\IRequest;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode; use Sabre\DAV\INode;
@ -41,15 +42,21 @@ use function implode;
class Plugin extends ServerPlugin { class Plugin extends ServerPlugin {
public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at'; 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_CALENDAR_URI = '{http://nextcloud.com/ns}calendar-uri';
public const PROPERTY_RETENTION_DURATION = '{http://nextcloud.com/ns}trash-bin-retention-duration';
/** @var bool */ /** @var bool */
private $disableTrashbin; private $disableTrashbin;
/** @var RetentionService */
private $retentionService;
/** @var Server */ /** @var Server */
private $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->disableTrashbin = $request->getHeader('X-NC-CalDAV-No-Trashbin') === '1';
$this->retentionService = $retentionService;
} }
public function initialize(Server $server): void { public function initialize(Server $server): void {
@ -100,6 +107,11 @@ class Plugin extends ServerPlugin {
return $node->getCalendarUri(); return $node->getCalendarUri();
}); });
} }
if ($node instanceof TrashbinHome) {
$propFind->handle(self::PROPERTY_RETENTION_DURATION, function () use ($node) {
return $this->retentionService->getDuration();
});
}
} }
public function getFeatures(): array { public function getFeatures(): array {

View File

@ -165,7 +165,7 @@ class Server {
$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); $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 \OCA\DAV\CalDAV\WebcalCaching\Plugin($request));
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());