diff --git a/apps/files_trashbin/composer/composer/autoload_classmap.php b/apps/files_trashbin/composer/composer/autoload_classmap.php index 89e06f32c64..3713de530c6 100644 --- a/apps/files_trashbin/composer/composer/autoload_classmap.php +++ b/apps/files_trashbin/composer/composer/autoload_classmap.php @@ -27,6 +27,7 @@ return array( 'OCA\\Files_Trashbin\\Sabre\\TrashFolderFile' => $baseDir . '/../lib/Sabre/TrashFolderFile.php', 'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => $baseDir . '/../lib/Sabre/TrashFolderFolder.php', 'OCA\\Files_Trashbin\\Sabre\\TrashHome' => $baseDir . '/../lib/Sabre/TrashHome.php', + 'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => $baseDir . '/../lib/Sabre/TrashRoot.php', 'OCA\\Files_Trashbin\\Storage' => $baseDir . '/../lib/Storage.php', 'OCA\\Files_Trashbin\\Trashbin' => $baseDir . '/../lib/Trashbin.php', ); diff --git a/apps/files_trashbin/composer/composer/autoload_static.php b/apps/files_trashbin/composer/composer/autoload_static.php index e57fcec2653..b00778741b3 100644 --- a/apps/files_trashbin/composer/composer/autoload_static.php +++ b/apps/files_trashbin/composer/composer/autoload_static.php @@ -42,6 +42,7 @@ class ComposerStaticInitFiles_Trashbin 'OCA\\Files_Trashbin\\Sabre\\TrashFolderFile' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolderFile.php', 'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolderFolder.php', 'OCA\\Files_Trashbin\\Sabre\\TrashHome' => __DIR__ . '/..' . '/../lib/Sabre/TrashHome.php', + 'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => __DIR__ . '/..' . '/../lib/Sabre/TrashRoot.php', 'OCA\\Files_Trashbin\\Storage' => __DIR__ . '/..' . '/../lib/Storage.php', 'OCA\\Files_Trashbin\\Trashbin' => __DIR__ . '/..' . '/../lib/Trashbin.php', ); diff --git a/apps/files_trashbin/lib/Sabre/ITrash.php b/apps/files_trashbin/lib/Sabre/ITrash.php index 5c776966ad0..b0ff2b1570a 100644 --- a/apps/files_trashbin/lib/Sabre/ITrash.php +++ b/apps/files_trashbin/lib/Sabre/ITrash.php @@ -1,4 +1,5 @@ * diff --git a/apps/files_trashbin/lib/Sabre/PropfindPlugin.php b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php index 11cfabe141a..e50ee08590a 100644 --- a/apps/files_trashbin/lib/Sabre/PropfindPlugin.php +++ b/apps/files_trashbin/lib/Sabre/PropfindPlugin.php @@ -1,4 +1,5 @@ * diff --git a/apps/files_trashbin/lib/Sabre/RestoreFolder.php b/apps/files_trashbin/lib/Sabre/RestoreFolder.php index b2416b1aeb0..04f23db0ed4 100644 --- a/apps/files_trashbin/lib/Sabre/RestoreFolder.php +++ b/apps/files_trashbin/lib/Sabre/RestoreFolder.php @@ -63,19 +63,19 @@ class RestoreFolder implements ICollection, IMoveTarget { throw new Forbidden(); } - public function getLastModified() { + public function getLastModified(): int { return 0; } - public function getChildren() { + public function getChildren(): array { return []; } - public function childExists($name) { + public function childExists($name): bool { return false; } - function moveInto($targetName, $sourcePath, INode $sourceNode) { + public function moveInto($targetName, $sourcePath, INode $sourceNode): bool { if (!($sourceNode instanceof ITrash)) { return false; } diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php index 226fc33e58e..e425fb448e2 100644 --- a/apps/files_trashbin/lib/Sabre/RootCollection.php +++ b/apps/files_trashbin/lib/Sabre/RootCollection.php @@ -1,4 +1,5 @@ * @@ -42,7 +43,7 @@ class RootCollection extends AbstractPrincipalCollection { * @param array $principalInfo * @return INode */ - public function getChildForPrincipal(array $principalInfo) { + public function getChildForPrincipal(array $principalInfo): TrashHome { list(,$name) = \Sabre\Uri\split($principalInfo['uri']); $user = \OC::$server->getUserSession()->getUser(); if (is_null($user) || $name !== $user->getUID()) { @@ -51,7 +52,7 @@ class RootCollection extends AbstractPrincipalCollection { return new TrashHome($principalInfo); } - public function getName() { + public function getName(): string { return 'trashbin'; } diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php index 215dcec5770..29e7a955623 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFile.php +++ b/apps/files_trashbin/lib/Sabre/TrashFile.php @@ -1,4 +1,5 @@ * @@ -46,15 +47,15 @@ class TrashFile implements IFile, ITrash { return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb'); } - public function getContentType() { + public function getContentType(): string { return $this->data->getMimetype(); } - public function getETag() { + public function getETag(): string { return $this->data->getEtag(); } - public function getSize() { + public function getSize(): int { return $this->data->getSize(); } @@ -62,7 +63,7 @@ class TrashFile implements IFile, ITrash { \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); } - public function getName() { + public function getName(): string { return $this->data->getName() . '.d' . $this->getLastModified(); } @@ -70,7 +71,7 @@ class TrashFile implements IFile, ITrash { throw new Forbidden(); } - public function getLastModified() { + public function getLastModified(): int { return $this->data->getMtime(); } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php index 390f1956ffb..33236eea262 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolder.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php @@ -1,4 +1,5 @@ * @@ -24,6 +25,7 @@ namespace OCA\Files_Trashbin\Sabre; use OCP\Files\FileInfo; use Sabre\DAV\Exception\Forbidden; +use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; class TrashFolder implements ICollection, ITrash { @@ -46,7 +48,7 @@ class TrashFolder implements ICollection, ITrash { throw new Forbidden(); } - public function getChild($name) { + public function getChild($name): ITrash { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); foreach ($entries as $entry) { @@ -57,9 +59,11 @@ class TrashFolder implements ICollection, ITrash { return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } } + + throw new NotFound(); } - public function getChildren() { + public function getChildren(): array { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); $children = array_map(function (FileInfo $entry) { @@ -72,7 +76,7 @@ class TrashFolder implements ICollection, ITrash { return $children; } - public function childExists($name) { + public function childExists($name): bool { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); foreach ($entries as $entry) { @@ -88,7 +92,7 @@ class TrashFolder implements ICollection, ITrash { \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); } - public function getName() { + public function getName(): string { return $this->data->getName() . '.d' . $this->getLastModified(); } @@ -96,7 +100,7 @@ class TrashFolder implements ICollection, ITrash { throw new Forbidden(); } - public function getLastModified() { + public function getLastModified(): int { return $this->data->getMtime(); } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php index a9b8e838e0a..95e82d95a6e 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php @@ -1,4 +1,5 @@ * @@ -57,15 +58,15 @@ class TrashFolderFile implements IFile, ITrash { return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb'); } - public function getContentType() { + public function getContentType(): string { return $this->data->getMimetype(); } - public function getETag() { + public function getETag(): string { return $this->data->getEtag(); } - public function getSize() { + public function getSize(): int { return $this->data->getSize(); } @@ -73,7 +74,7 @@ class TrashFolderFile implements IFile, ITrash { \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); } - public function getName() { + public function getName(): string { return $this->data->getName(); } @@ -81,7 +82,7 @@ class TrashFolderFile implements IFile, ITrash { throw new Forbidden(); } - public function getLastModified() { + public function getLastModified(): int { return $this->data->getMtime(); } diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php index 435e1f00196..d2923c58916 100644 --- a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php +++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php @@ -1,4 +1,5 @@ * @@ -24,6 +25,7 @@ namespace OCA\Files_Trashbin\Sabre; use OCP\Files\FileInfo; use Sabre\DAV\Exception\Forbidden; +use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; class TrashFolderFolder implements ICollection, ITrash { @@ -31,7 +33,6 @@ class TrashFolderFolder implements ICollection, ITrash { /** @var string */ private $root; - /** @var string */ private $userId; @@ -59,7 +60,7 @@ class TrashFolderFolder implements ICollection, ITrash { throw new Forbidden(); } - public function getChild($name) { + public function getChild($name): ITrash { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); foreach ($entries as $entry) { @@ -70,9 +71,11 @@ class TrashFolderFolder implements ICollection, ITrash { return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); } } + + throw new NotFound(); } - public function getChildren() { + public function getChildren(): array { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); $children = array_map(function (FileInfo $entry) { @@ -85,7 +88,7 @@ class TrashFolderFolder implements ICollection, ITrash { return $children; } - public function childExists($name) { + public function childExists($name): bool { $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); foreach ($entries as $entry) { @@ -101,7 +104,7 @@ class TrashFolderFolder implements ICollection, ITrash { \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); } - public function getName() { + public function getName(): string { return $this->data->getName(); } @@ -110,7 +113,7 @@ class TrashFolderFolder implements ICollection, ITrash { throw new Forbidden(); } - function getLastModified() { + public function getLastModified(): int { return $this->data->getMtime(); } diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php index 4b2713ad694..d1c50c9c6a3 100644 --- a/apps/files_trashbin/lib/Sabre/TrashHome.php +++ b/apps/files_trashbin/lib/Sabre/TrashHome.php @@ -1,4 +1,5 @@ * @@ -22,29 +23,21 @@ */ namespace OCA\Files_Trashbin\Sabre; -use OCP\Files\FileInfo; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; class TrashHome implements ICollection { - /** - * @var array - */ + /** @var array */ private $principalInfo; - /** - * FilesHome constructor. - * - * @param array $principalInfo - */ - public function __construct($principalInfo) { + public function __construct(array $principalInfo) { $this->principalInfo = $principalInfo; } public function delete() { - \OCA\Files_Trashbin\Trashbin::deleteAll(); + throw new Forbidden(); } public function getName(): string { @@ -70,53 +63,27 @@ class TrashHome implements ICollection { if ($name === 'restore') { return new RestoreFolder($userId); } - - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId); - - foreach ($entries as $entry) { - if ($entry->getName() . '.d'.$entry->getMtime() === $name) { - if ($entry->getType() === FileInfo::TYPE_FOLDER) { - return new TrashFolder('/', $userId, $entry); - } - return new TrashFile($userId, $entry); - } + if ($name === 'trash') { + return new TrashRoot($userId); } throw new NotFound(); } - public function getChildren() { + public function getChildren(): array { list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']); - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId); - - $children = array_map(function (FileInfo $entry) use ($userId) { - if ($entry->getType() === FileInfo::TYPE_FOLDER) { - return new TrashFolder('/', $userId, $entry); - } - return new TrashFile($userId, $entry); - }, $entries); - - $children[] = new RestoreFolder($userId); - - return $children; + return [ + new RestoreFolder($userId), + new TrashRoot($userId), + ]; } - public function childExists($name) { - list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']); - - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId); - - foreach ($entries as $entry) { - if ($entry->getName() . '.d'.$entry->getMtime() === $name) { - return true; - } - } - - return false; + public function childExists($name): bool { + return $name === 'restore' || $name === 'trash'; } - public function getLastModified() { + public function getLastModified(): int { return 0; } } diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php new file mode 100644 index 00000000000..73b9d44d7e1 --- /dev/null +++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php @@ -0,0 +1,103 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ +namespace OCA\Files_Trashbin\Sabre; + +use OCP\Files\FileInfo; +use Sabre\DAV\Exception\Forbidden; +use Sabre\DAV\Exception\NotFound; +use Sabre\DAV\ICollection; + +class TrashRoot implements ICollection { + + /** @var string */ + private $userId; + + public function __construct(string $userId) { + $this->userId = $userId; + } + + public function delete() { + \OCA\Files_Trashbin\Trashbin::deleteAll(); + } + + public function getName(): string { + return 'trash'; + } + + public function setName($name) { + throw new Forbidden('Permission denied to rename this trashbin'); + } + + public function createFile($name, $data = null) { + throw new Forbidden('Not allowed to create files in the trashbin'); + } + + public function createDirectory($name) { + throw new Forbidden('Not allowed to create folders in the trashbin'); + } + + public function getChild($name): ITrash { + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId); + + foreach ($entries as $entry) { + if ($entry->getName() . '.d'.$entry->getMtime() === $name) { + if ($entry->getType() === FileInfo::TYPE_FOLDER) { + return new TrashFolder('/', $this->userId, $entry); + } + return new TrashFile($this->userId, $entry); + } + } + + throw new NotFound(); + } + + public function getChildren(): array { + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId); + + $children = array_map(function (FileInfo $entry) { + if ($entry->getType() === FileInfo::TYPE_FOLDER) { + return new TrashFolder('/', $this->userId, $entry); + } + return new TrashFile($this->userId, $entry); + }, $entries); + + return $children; + } + + public function childExists($name): bool { + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId); + + foreach ($entries as $entry) { + if ($entry->getName() . '.d'.$entry->getMtime() === $name) { + return true; + } + } + + return false; + } + + public function getLastModified(): int { + return 0; + } +}