Expose deletion timestamp for deleted CalDAV objects

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-05-31 10:47:07 +02:00
parent 30a595af2c
commit fe31373a93
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
2 changed files with 19 additions and 3 deletions

View File

@ -93,4 +93,8 @@ class DeletedCalendarObject implements ICalendarObject, IRestorable {
public function restore(): void { public function restore(): void {
$this->calDavBackend->restoreCalendarObject($this->objectData); $this->calDavBackend->restoreCalendarObject($this->objectData);
} }
public function getDeletedAt(): ?int {
return $this->objectData['deleted_at'] ? (int) $this->objectData['deleted_at'] : null;
}
} }

View File

@ -25,9 +25,12 @@ declare(strict_types=1);
namespace OCA\DAV\CalDAV\Trashbin; namespace OCA\DAV\CalDAV\Trashbin;
use Closure;
use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Calendar;
use OCP\IRequest; use OCP\IRequest;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server; use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin; use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface; use Sabre\HTTP\RequestInterface;
@ -35,10 +38,8 @@ use Sabre\HTTP\ResponseInterface;
use function array_slice; use function array_slice;
use function implode; use function implode;
/**
* Conditional logic to bypass the calendar trashbin
*/
class Plugin extends ServerPlugin { class Plugin extends ServerPlugin {
public const PROPERTY_DELETED_AT = '{http://nextcloud.com/ns}deleted-at';
/** @var bool */ /** @var bool */
private $disableTrashbin; private $disableTrashbin;
@ -53,6 +54,7 @@ class Plugin extends ServerPlugin {
public function initialize(Server $server): void { public function initialize(Server $server): void {
$this->server = $server; $this->server = $server;
$server->on('beforeMethod:*', [$this, 'beforeMethod']); $server->on('beforeMethod:*', [$this, 'beforeMethod']);
$server->on('propFind', Closure::fromCallable([$this, 'propFind']));
} }
public function beforeMethod(RequestInterface $request, ResponseInterface $response): void { public function beforeMethod(RequestInterface $request, ResponseInterface $response): void {
@ -86,6 +88,16 @@ class Plugin extends ServerPlugin {
} }
} }
private function propFind(
PropFind $propFind,
INode $node): void {
if ($node instanceof DeletedCalendarObject) {
$propFind->handle(self::PROPERTY_DELETED_AT, function () use ($node) {
return $node->getDeletedAt();
});
}
}
public function getFeatures(): array { public function getFeatures(): array {
return ['nc-calendar-trashbin']; return ['nc-calendar-trashbin'];
} }