summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Sabre
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-09-03 18:30:10 +0200
committerRobin Appelman <robin@icewind.nl>2018-09-20 17:03:26 +0200
commit6372ae3a98537e8d1b5c5adf4fc446bc0651c2b1 (patch)
tree784a6fae2ac39cc4956ae42bbc24103a31b41ca3 /apps/files_trashbin/lib/Sabre
parent58e281857f421b69479f9fa2a01d5d52410cde6a (diff)
downloadnextcloud-server-6372ae3a98537e8d1b5c5adf4fc446bc0651c2b1.tar.gz
nextcloud-server-6372ae3a98537e8d1b5c5adf4fc446bc0651c2b1.zip
expose additional props from trashbin sabre endpoint
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_trashbin/lib/Sabre')
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrash.php69
-rw-r--r--apps/files_trashbin/lib/Sabre/ITrash.php4
-rw-r--r--apps/files_trashbin/lib/Sabre/PropfindPlugin.php36
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFile.php37
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolder.php27
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFile.php39
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFolder.php32
7 files changed, 114 insertions, 130 deletions
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
new file mode 100644
index 00000000000..43f9cc02749
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.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/>.
+ *
+ */
+
+namespace OCA\Files_Trashbin\Sabre;
+
+use OCP\Files\FileInfo;
+
+abstract class AbstractTrash implements ITrash {
+ /** @var FileInfo */
+ protected $data;
+
+ public function __construct(FileInfo $data) {
+ $this->data = $data;
+ }
+
+ public function getFilename(): string {
+ return $this->data->getName();
+ }
+
+ public function getDeletionTime(): int {
+ return $this->data->getMtime();
+ }
+
+ public function getFileId(): int {
+ return $this->data->getId();
+ }
+
+ public function getFileInfo(): FileInfo {
+ return $this->data;
+ }
+
+ public function getSize(): int {
+ return $this->data->getSize();
+ }
+
+ public function getLastModified(): int {
+ return $this->data->getMtime();
+ }
+
+ public function getContentType(): string {
+ return $this->data->getMimetype();
+ }
+
+ public function getETag(): string {
+ return $this->data->getEtag();
+ }
+
+ public function getName(): string {
+ return $this->data->getName();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/ITrash.php b/apps/files_trashbin/lib/Sabre/ITrash.php
index 6db9bccf0a2..49c600c3f18 100644
--- a/apps/files_trashbin/lib/Sabre/ITrash.php
+++ b/apps/files_trashbin/lib/Sabre/ITrash.php
@@ -23,6 +23,8 @@ declare(strict_types=1);
*/
namespace OCA\Files_Trashbin\Sabre;
+use OCP\Files\FileInfo;
+
interface ITrash {
public function restore(): bool;
@@ -35,4 +37,6 @@ interface ITrash {
public function getSize();
public function getFileId(): int;
+
+ public function getFileInfo(): FileInfo;
}
diff --git a/apps/files_trashbin/lib/Sabre/PropfindPlugin.php b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php
index 492035304ba..19da79fd2a3 100644
--- a/apps/files_trashbin/lib/Sabre/PropfindPlugin.php
+++ b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php
@@ -25,6 +25,8 @@ declare(strict_types=1);
namespace OCA\Files_Trashbin\Sabre;
use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCP\Constants;
+use OCP\IPreview;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
@@ -39,7 +41,13 @@ class PropfindPlugin extends ServerPlugin {
/** @var Server */
private $server;
- public function __construct() {
+ /** @var IPreview */
+ private $previewManager;
+
+ public function __construct(
+ IPreview $previewManager
+ ) {
+ $this->previewManager = $previewManager;
}
public function initialize(Server $server) {
@@ -54,11 +62,11 @@ class PropfindPlugin extends ServerPlugin {
return;
}
- $propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) {
+ $propFind->handle(self::TRASHBIN_FILENAME, function () use ($node) {
return $node->getFilename();
});
- $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) {
+ $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function () use ($node) {
return $node->getOriginalLocation();
});
@@ -73,6 +81,28 @@ class PropfindPlugin extends ServerPlugin {
$propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) {
return $node->getFileId();
});
+
+ $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () {
+ return 'GD'; // read + delete
+ });
+
+ $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, function () use ($node) {
+ // add fake etag, it is only needed to identify the preview image
+ return $node->getLastModified();
+ });
+
+ $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
+ // add fake etag, it is only needed to identify the preview image
+ return $node->getFileId();
+ });
+
+ $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
+ return $this->previewManager->isAvailable($node->getFileInfo());
+ });
+
+ $propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () {
+ return '';
+ });
}
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php
index eba9eee641b..840ca6a1938 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFile.php
@@ -27,16 +27,13 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\IFile;
-class TrashFile implements IFile, ITrash {
+class TrashFile extends AbstractTrash implements IFile, ITrash {
/** @var string */
private $userId;
- /** @var FileInfo */
- private $data;
-
public function __construct(string $userId, FileInfo $data) {
$this->userId = $userId;
- $this->data = $data;
+ parent::__construct($data);
}
public function put($data) {
@@ -47,18 +44,6 @@ class TrashFile implements IFile, ITrash {
return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
}
- public function getContentType(): string {
- return $this->data->getMimetype();
- }
-
- public function getETag(): string {
- return $this->data->getEtag();
- }
-
- public function getSize(): int {
- return $this->data->getSize();
- }
-
public function delete() {
\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
}
@@ -71,29 +56,11 @@ class TrashFile implements IFile, ITrash {
throw new Forbidden();
}
- public function getLastModified(): int {
- return $this->data->getMtime();
- }
-
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
}
- public function getFilename(): string {
- return $this->data->getName();
- }
-
public function getOriginalLocation(): string {
return $this->data['extraData'];
}
-
- public function getDeletionTime(): int {
- return $this->getLastModified();
- }
-
- public function getFileId(): int {
- return $this->data->getId();
- }
-
-
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php
index 6b7d71b80ee..d884eefcc9f 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php
@@ -28,16 +28,13 @@ use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
-class TrashFolder implements ICollection, ITrash {
+class TrashFolder extends AbstractTrash implements ICollection, ITrash {
/** @var string */
private $userId;
- /** @var FileInfo */
- private $data;
-
public function __construct(string $root, string $userId, FileInfo $data) {
$this->userId = $userId;
- $this->data = $data;
+ parent::__construct($data);
}
public function createFile($name, $data = null) {
@@ -100,31 +97,11 @@ class TrashFolder implements ICollection, ITrash {
throw new Forbidden();
}
- public function getLastModified(): int {
- return $this->data->getMtime();
- }
-
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
}
- public function getFilename(): string {
- return $this->data->getName();
- }
-
public function getOriginalLocation(): string {
return $this->data['extraData'];
}
-
- public function getDeletionTime(): int {
- return $this->getLastModified();
- }
-
- public function getSize(): int {
- return $this->data->getSize();
- }
-
- public function getFileId(): int {
- return $this->data->getId();
- }
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
index 921c98b02fb..3e28d048b42 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
@@ -27,16 +27,13 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\IFile;
-class TrashFolderFile implements IFile, ITrash {
+class TrashFolderFile extends AbstractTrash implements IFile, ITrash {
/** @var string */
private $root;
/** @var string */
private $userId;
- /** @var FileInfo */
- private $data;
-
/** @var string */
private $location;
@@ -46,8 +43,8 @@ class TrashFolderFile implements IFile, ITrash {
string $location) {
$this->root = $root;
$this->userId = $userId;
- $this->data = $data;
$this->location = $location;
+ parent::__construct($data);
}
public function put($data) {
@@ -58,51 +55,19 @@ class TrashFolderFile implements IFile, ITrash {
return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb');
}
- public function getContentType(): string {
- return $this->data->getMimetype();
- }
-
- public function getETag(): string {
- return $this->data->getEtag();
- }
-
- public function getSize(): int {
- return $this->data->getSize();
- }
-
public function delete() {
\OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
}
- public function getName(): string {
- return $this->data->getName();
- }
-
public function setName($name) {
throw new Forbidden();
}
- public function getLastModified(): int {
- return $this->data->getMtime();
- }
-
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
}
- public function getFilename(): string {
- return $this->data->getName();
- }
-
public function getOriginalLocation(): string {
return $this->location . '/' . $this->getFilename();
}
-
- public function getDeletionTime(): int {
- return $this->getLastModified();
- }
-
- public function getFileId(): int {
- return $this->data->getId();
- }
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
index 2fe75479c1b..4ee9a0e2db0 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
@@ -28,7 +28,7 @@ use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
-class TrashFolderFolder implements ICollection, ITrash {
+class TrashFolderFolder extends AbstractTrash implements ICollection, ITrash {
/** @var string */
private $root;
@@ -36,9 +36,6 @@ class TrashFolderFolder implements ICollection, ITrash {
/** @var string */
private $userId;
- /** @var FileInfo */
- private $data;
-
/** @var string */
private $location;
@@ -48,8 +45,8 @@ class TrashFolderFolder implements ICollection, ITrash {
string $location) {
$this->root = $root;
$this->userId = $userId;
- $this->data = $data;
$this->location = $location;
+ parent::__construct($data);
}
public function createFile($name, $data = null) {
@@ -104,40 +101,15 @@ class TrashFolderFolder implements ICollection, ITrash {
\OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
}
- public function getName(): string {
- return $this->data->getName();
-
- }
-
public function setName($name) {
throw new Forbidden();
}
- public function getLastModified(): int {
- return $this->data->getMtime();
- }
-
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
}
- public function getFilename(): string {
- return $this->data->getName();
- }
-
public function getOriginalLocation(): string {
return $this->location . '/' . $this->getFilename();
}
-
- public function getDeletionTime(): int {
- return $this->getLastModified();
- }
-
- public function getSize(): int {
- return $this->data->getSize();
- }
-
- public function getFileId(): int {
- return $this->data->getId();
- }
}