diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-04-17 22:22:41 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-04-25 20:25:10 +0200 |
commit | d5937e0fd6098b90cdfc6ea826d2ba7f1f37ad97 (patch) | |
tree | 772e579897b0d1dc7267a8020350c03b4a0af107 /apps | |
parent | cb617c4949f9b8570f65bf972c29d4cd78bc9b6e (diff) | |
download | nextcloud-server-d5937e0fd6098b90cdfc6ea826d2ba7f1f37ad97.tar.gz nextcloud-server-d5937e0fd6098b90cdfc6ea826d2ba7f1f37ad97.zip |
Add propfind properties to trashbin
* get original filename (without the weird timestamp)
* get original location
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_trashbin/appinfo/info.xml | 3 | ||||
-rw-r--r-- | apps/files_trashbin/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/files_trashbin/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/ITrash.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/PropfindPlugin.php | 63 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashFile.php | 9 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashFolder.php | 16 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashFolderFile.php | 18 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/TrashFolderFolder.php | 26 |
9 files changed, 131 insertions, 10 deletions
diff --git a/apps/files_trashbin/appinfo/info.xml b/apps/files_trashbin/appinfo/info.xml index a71443e6949..4ca60c0e269 100644 --- a/apps/files_trashbin/appinfo/info.xml +++ b/apps/files_trashbin/appinfo/info.xml @@ -40,5 +40,8 @@ To prevent a user from running out of disk space, the Deleted files app will not <collections> <collection>OCA\Files_Trashbin\Sabre\RootCollection</collection> </collections> + <plugins> + <plugin>OCA\Files_Trashbin\Sabre\PropfindPlugin</plugin> + </plugins> </sabre> </info> diff --git a/apps/files_trashbin/composer/composer/autoload_classmap.php b/apps/files_trashbin/composer/composer/autoload_classmap.php index fee5a3abb06..89e06f32c64 100644 --- a/apps/files_trashbin/composer/composer/autoload_classmap.php +++ b/apps/files_trashbin/composer/composer/autoload_classmap.php @@ -19,6 +19,7 @@ return array( 'OCA\\Files_Trashbin\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files_Trashbin\\Hooks' => $baseDir . '/../lib/Hooks.php', 'OCA\\Files_Trashbin\\Sabre\\ITrash' => $baseDir . '/../lib/Sabre/ITrash.php', + 'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => $baseDir . '/../lib/Sabre/PropfindPlugin.php', 'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => $baseDir . '/../lib/Sabre/RestoreFolder.php', 'OCA\\Files_Trashbin\\Sabre\\RootCollection' => $baseDir . '/../lib/Sabre/RootCollection.php', 'OCA\\Files_Trashbin\\Sabre\\TrashFile' => $baseDir . '/../lib/Sabre/TrashFile.php', diff --git a/apps/files_trashbin/composer/composer/autoload_static.php b/apps/files_trashbin/composer/composer/autoload_static.php index 9b37b8955a8..e57fcec2653 100644 --- a/apps/files_trashbin/composer/composer/autoload_static.php +++ b/apps/files_trashbin/composer/composer/autoload_static.php @@ -34,6 +34,7 @@ class ComposerStaticInitFiles_Trashbin 'OCA\\Files_Trashbin\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files_Trashbin\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', 'OCA\\Files_Trashbin\\Sabre\\ITrash' => __DIR__ . '/..' . '/../lib/Sabre/ITrash.php', + 'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => __DIR__ . '/..' . '/../lib/Sabre/PropfindPlugin.php', 'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => __DIR__ . '/..' . '/../lib/Sabre/RestoreFolder.php', 'OCA\\Files_Trashbin\\Sabre\\RootCollection' => __DIR__ . '/..' . '/../lib/Sabre/RootCollection.php', 'OCA\\Files_Trashbin\\Sabre\\TrashFile' => __DIR__ . '/..' . '/../lib/Sabre/TrashFile.php', diff --git a/apps/files_trashbin/lib/Sabre/ITrash.php b/apps/files_trashbin/lib/Sabre/ITrash.php index 1c44334ffce..5c776966ad0 100644 --- a/apps/files_trashbin/lib/Sabre/ITrash.php +++ b/apps/files_trashbin/lib/Sabre/ITrash.php @@ -24,4 +24,8 @@ namespace OCA\Files_Trashbin\Sabre; interface ITrash { public function restore(): bool; + + public function getFilename(): string; + + public function getOriginalLocation(): string; } diff --git a/apps/files_trashbin/lib/Sabre/PropfindPlugin.php b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php new file mode 100644 index 00000000000..11cfabe141a --- /dev/null +++ b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php @@ -0,0 +1,63 @@ +<?php +/** + * @copyright 2018, Roeland Jago Douma <roeland@famdouma.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/>. + * + */ + +namespace OCA\Files_Trashbin\Sabre; + +use Sabre\DAV\INode; +use Sabre\DAV\PropFind; +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; + +class PropfindPlugin extends ServerPlugin { + + const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename'; + const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location'; + + /** @var Server */ + private $server; + + public function __construct() { + } + + public function initialize(Server $server) { + $this->server = $server; + + $this->server->on('propFind', [$this, 'propFind']); + } + + + public function propFind(PropFind $propFind, INode $node) { + if (!($node instanceof ITrash)) { + return; + } + + $propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) { + return $node->getFilename(); + }); + + $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) { + return $node->getOriginalLocation(); + }); + } + +} diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php index 3e801a27579..215dcec5770 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFile.php +++ b/apps/files_trashbin/lib/Sabre/TrashFile.php @@ -78,4 +78,13 @@ class TrashFile implements IFile, ITrash { 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']; + } + + } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php index ebe7f7d4871..495c98c9202 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolder.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php @@ -52,9 +52,9 @@ class TrashFolder implements ICollection, ITrash { foreach ($entries as $entry) { if ($entry->getName() === $name) { if ($entry->getMimetype() === 'httpd/unix-directory') { - return new TrashFolderFolder($this->getName(), $this->userId, $entry); + return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } - return new TrashFolderFile($this->getName(), $this->userId, $entry); + return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } } } @@ -64,9 +64,9 @@ class TrashFolder implements ICollection, ITrash { $children = array_map(function (FileInfo $entry) { if ($entry->getMimetype() === 'httpd/unix-directory') { - return new TrashFolderFolder($this->getName(), $this->userId, $entry); + return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } - return new TrashFolderFile($this->getName(), $this->userId, $entry); + return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); }, $entries); return $children; @@ -104,5 +104,13 @@ class TrashFolder implements ICollection, ITrash { 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']; + } + } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php index b927d0a0870..a9b8e838e0a 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php @@ -36,10 +36,17 @@ class TrashFolderFile implements IFile, ITrash { /** @var FileInfo */ private $data; - public function __construct(string $root, string $userId, FileInfo $data) { + /** @var string */ + private $location; + + public function __construct(string $root, + string $userId, + FileInfo $data, + string $location) { $this->root = $root; $this->userId = $userId; $this->data = $data; + $this->location = $location; } public function put($data) { @@ -82,4 +89,13 @@ class TrashFolderFile implements IFile, ITrash { 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(); + } + + } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php index efd208a1d8d..3607f90c568 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php @@ -38,10 +38,17 @@ class TrashFolderFolder implements ICollection, ITrash { /** @var FileInfo */ private $data; - public function __construct(string $root, string $userId, FileInfo $data) { + /** @var string */ + private $location; + + public function __construct(string $root, + string $userId, + FileInfo $data, + string $location) { $this->root = $root; $this->userId = $userId; $this->data = $data; + $this->location = $location; } public function createFile($name, $data = null) { @@ -58,9 +65,9 @@ class TrashFolderFolder implements ICollection, ITrash { foreach ($entries as $entry) { if ($entry->getName() === $name) { if ($entry->getMimetype() === 'httpd/unix-directory') { - return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry); + return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } - return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry); + return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } } } @@ -70,9 +77,9 @@ class TrashFolderFolder implements ICollection, ITrash { $children = array_map(function (FileInfo $entry) { if ($entry->getMimetype() === 'httpd/unix-directory') { - return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry); + return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } - return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry); + return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); }, $entries); return $children; @@ -111,4 +118,13 @@ class TrashFolderFolder implements ICollection, ITrash { 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(); + } + + } |