aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib/Sabre
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib/Sabre')
-rw-r--r--apps/files_versions/lib/Sabre/Plugin.php65
-rw-r--r--apps/files_versions/lib/Sabre/RestoreFolder.php22
-rw-r--r--apps/files_versions/lib/Sabre/RootCollection.php48
-rw-r--r--apps/files_versions/lib/Sabre/VersionCollection.php40
-rw-r--r--apps/files_versions/lib/Sabre/VersionFile.php75
-rw-r--r--apps/files_versions/lib/Sabre/VersionHome.php46
-rw-r--r--apps/files_versions/lib/Sabre/VersionRoot.php46
7 files changed, 118 insertions, 224 deletions
diff --git a/apps/files_versions/lib/Sabre/Plugin.php b/apps/files_versions/lib/Sabre/Plugin.php
index 5a127b4251d..984c4a36e5b 100644
--- a/apps/files_versions/lib/Sabre/Plugin.php
+++ b/apps/files_versions/lib/Sabre/Plugin.php
@@ -3,45 +3,39 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
use OC\AppFramework\Http\Request;
+use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCP\IPreview;
use OCP\IRequest;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\INode;
+use Sabre\DAV\PropFind;
+use Sabre\DAV\PropPatch;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
class Plugin extends ServerPlugin {
+ private Server $server;
- /** @var Server */
- private $server;
- /** @var IRequest */
- private $request;
+ public const LABEL = 'label';
- public function __construct(IRequest $request) {
+ public const AUTHOR = 'author';
+
+ public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label';
+
+ public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author
+
+ public function __construct(
+ private IRequest $request,
+ private IPreview $previewManager,
+ ) {
$this->request = $request;
}
@@ -49,6 +43,8 @@ class Plugin extends ServerPlugin {
$this->server = $server;
$server->on('afterMethod:GET', [$this, 'afterGet']);
+ $server->on('propFind', [$this, 'propFind']);
+ $server->on('propPatch', [$this, 'propPatch']);
}
public function afterGet(RequestInterface $request, ResponseInterface $response) {
@@ -81,4 +77,23 @@ class Plugin extends ServerPlugin {
. '; filename="' . rawurlencode($filename) . '"');
}
}
+
+ public function propFind(PropFind $propFind, INode $node): void {
+ if ($node instanceof VersionFile) {
+ $propFind->handle(self::VERSION_LABEL, fn () => $node->getMetadataValue(self::LABEL));
+ $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataValue(self::AUTHOR));
+ $propFind->handle(
+ FilesPlugin::HAS_PREVIEW_PROPERTYNAME,
+ fn (): string => $this->previewManager->isMimeSupported($node->getContentType()) ? 'true' : 'false',
+ );
+ }
+ }
+
+ public function propPatch($path, PropPatch $propPatch): void {
+ $node = $this->server->tree->getNodeForPath($path);
+
+ if ($node instanceof VersionFile) {
+ $propPatch->handle(self::VERSION_LABEL, fn (string $label) => $node->setMetadataValue(self::LABEL, $label));
+ }
+ }
}
diff --git a/apps/files_versions/lib/Sabre/RestoreFolder.php b/apps/files_versions/lib/Sabre/RestoreFolder.php
index 31d87cc7112..7904b098a4f 100644
--- a/apps/files_versions/lib/Sabre/RestoreFolder.php
+++ b/apps/files_versions/lib/Sabre/RestoreFolder.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
diff --git a/apps/files_versions/lib/Sabre/RootCollection.php b/apps/files_versions/lib/Sabre/RootCollection.php
index 835df5930bc..1e7129f23da 100644
--- a/apps/files_versions/lib/Sabre/RootCollection.php
+++ b/apps/files_versions/lib/Sabre/RootCollection.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
@@ -34,33 +17,16 @@ use Sabre\DAVACL\PrincipalBackend;
class RootCollection extends AbstractPrincipalCollection {
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IVersionManager */
- private $versionManager;
-
- /** @var IUserSession */
- private $userSession;
-
public function __construct(
PrincipalBackend\BackendInterface $principalBackend,
- IRootFolder $rootFolder,
+ private IRootFolder $rootFolder,
IConfig $config,
- IUserManager $userManager,
- IVersionManager $versionManager,
- IUserSession $userSession
+ private IUserManager $userManager,
+ private IVersionManager $versionManager,
+ private IUserSession $userSession,
) {
parent::__construct($principalBackend, 'principals/users');
- $this->rootFolder = $rootFolder;
- $this->userManager = $userManager;
- $this->versionManager = $versionManager;
- $this->userSession = $userSession;
-
$this->disableListing = !$config->getSystemValue('debug', false);
}
diff --git a/apps/files_versions/lib/Sabre/VersionCollection.php b/apps/files_versions/lib/Sabre/VersionCollection.php
index 946ac9baad7..375d5cf99f2 100644
--- a/apps/files_versions/lib/Sabre/VersionCollection.php
+++ b/apps/files_versions/lib/Sabre/VersionCollection.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
@@ -36,19 +18,11 @@ use Sabre\DAV\ICollection;
class VersionCollection implements ICollection {
- /** @var File */
- private $file;
-
- /** @var IUser */
- private $user;
-
- /** @var IVersionManager */
- private $versionManager;
-
- public function __construct(File $file, IUser $user, IVersionManager $versionManager) {
- $this->file = $file;
- $this->user = $user;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private File $file,
+ private IUser $user,
+ private IVersionManager $versionManager,
+ ) {
}
public function createFile($name, $data = null) {
diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php
index b7c7e6db1a6..faa03473648 100644
--- a/apps/files_versions/lib/Sabre/VersionFile.php
+++ b/apps/files_versions/lib/Sabre/VersionFile.php
@@ -3,29 +3,16 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
+use OCA\Files_Versions\Versions\IDeletableVersionBackend;
+use OCA\Files_Versions\Versions\IMetadataVersion;
+use OCA\Files_Versions\Versions\IMetadataVersionBackend;
+use OCA\Files_Versions\Versions\INameableVersion;
+use OCA\Files_Versions\Versions\INameableVersionBackend;
use OCA\Files_Versions\Versions\IVersion;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\NotFoundException;
@@ -34,15 +21,10 @@ use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile;
class VersionFile implements IFile {
- /** @var IVersion */
- private $version;
-
- /** @var IVersionManager */
- private $versionManager;
-
- public function __construct(IVersion $version, IVersionManager $versionManager) {
- $this->version = $version;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private IVersion $version,
+ private IVersionManager $versionManager,
+ ) {
}
public function put($data) {
@@ -65,12 +47,20 @@ class VersionFile implements IFile {
return (string)$this->version->getRevisionId();
}
- public function getSize(): int {
+ /**
+ * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
+ * @return int|float
+ */
+ public function getSize(): int|float {
return $this->version->getSize();
}
public function delete() {
- throw new Forbidden();
+ if ($this->versionManager instanceof IDeletableVersionBackend) {
+ $this->versionManager->deleteVersion($this->version);
+ } else {
+ throw new Forbidden();
+ }
}
public function getName(): string {
@@ -81,6 +71,29 @@ class VersionFile implements IFile {
throw new Forbidden();
}
+ public function setMetadataValue(string $key, string $value): bool {
+ $backend = $this->version->getBackend();
+
+ if ($backend instanceof IMetadataVersionBackend) {
+ $backend->setMetadataValue($this->version->getSourceFile(), $this->version->getTimestamp(), $key, $value);
+ return true;
+ } elseif ($key === 'label' && $backend instanceof INameableVersionBackend) {
+ $backend->setVersionLabel($this->version, $value);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function getMetadataValue(string $key): ?string {
+ if ($this->version instanceof IMetadataVersion) {
+ return $this->version->getMetadataValue($key);
+ } elseif ($key === 'label' && $this->version instanceof INameableVersion) {
+ return $this->version->getLabel();
+ }
+ return null;
+ }
+
public function getLastModified(): int {
return $this->version->getTimestamp();
}
diff --git a/apps/files_versions/lib/Sabre/VersionHome.php b/apps/files_versions/lib/Sabre/VersionHome.php
index 13505d9a96c..07ac491f2a1 100644
--- a/apps/files_versions/lib/Sabre/VersionHome.php
+++ b/apps/files_versions/lib/Sabre/VersionHome.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
@@ -32,23 +15,12 @@ use Sabre\DAV\ICollection;
class VersionHome implements ICollection {
- /** @var array */
- private $principalInfo;
-
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IVersionManager */
- private $versionManager;
-
- public function __construct(array $principalInfo, IRootFolder $rootFolder, IUserManager $userManager, IVersionManager $versionManager) {
- $this->principalInfo = $principalInfo;
- $this->rootFolder = $rootFolder;
- $this->userManager = $userManager;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private array $principalInfo,
+ private IRootFolder $rootFolder,
+ private IUserManager $userManager,
+ private IVersionManager $versionManager,
+ ) {
}
private function getUser() {
diff --git a/apps/files_versions/lib/Sabre/VersionRoot.php b/apps/files_versions/lib/Sabre/VersionRoot.php
index 69ac12ed8e9..7f7014fbee3 100644
--- a/apps/files_versions/lib/Sabre/VersionRoot.php
+++ b/apps/files_versions/lib/Sabre/VersionRoot.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Versions\Sabre;
@@ -36,19 +18,11 @@ use Sabre\DAV\ICollection;
class VersionRoot implements ICollection {
- /** @var IUser */
- private $user;
-
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var IVersionManager */
- private $versionManager;
-
- public function __construct(IUser $user, IRootFolder $rootFolder, IVersionManager $versionManager) {
- $this->user = $user;
- $this->rootFolder = $rootFolder;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private IUser $user,
+ private IRootFolder $rootFolder,
+ private IVersionManager $versionManager,
+ ) {
}
public function delete() {
@@ -75,14 +49,12 @@ class VersionRoot implements ICollection {
$userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
$fileId = (int)$name;
- $nodes = $userFolder->getById($fileId);
+ $node = $userFolder->getFirstNodeById($fileId);
- if ($nodes === []) {
+ if (!$node) {
throw new NotFound();
}
- $node = array_pop($nodes);
-
if (!$node instanceof File) {
throw new NotFound();
}