Browse Source
Merge pull request #9202 from nextcloud/feature/1332/trashbin_dav
Merge pull request #9202 from nextcloud/feature/1332/trashbin_dav
Trashbin endpoint in DAVpull/9346/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 923 additions and 1 deletions
-
12apps/files_trashbin/appinfo/info.xml
-
10apps/files_trashbin/composer/composer/autoload_classmap.php
-
10apps/files_trashbin/composer/composer/autoload_static.php
-
13apps/files_trashbin/lib/AppInfo/Application.php
-
32apps/files_trashbin/lib/Sabre/ITrash.php
-
64apps/files_trashbin/lib/Sabre/PropfindPlugin.php
-
86apps/files_trashbin/lib/Sabre/RestoreFolder.php
-
59apps/files_trashbin/lib/Sabre/RootCollection.php
-
91apps/files_trashbin/lib/Sabre/TrashFile.php
-
120apps/files_trashbin/lib/Sabre/TrashFolder.php
-
102apps/files_trashbin/lib/Sabre/TrashFolderFile.php
-
133apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
-
89apps/files_trashbin/lib/Sabre/TrashHome.php
-
103apps/files_trashbin/lib/Sabre/TrashRoot.php
@ -0,0 +1,32 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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; |
|||
|
|||
interface ITrash { |
|||
public function restore(): bool; |
|||
|
|||
public function getFilename(): string; |
|||
|
|||
public function getOriginalLocation(): string; |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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(); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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\Exception\Forbidden; |
|||
use Sabre\DAV\ICollection; |
|||
use Sabre\DAV\IMoveTarget; |
|||
use Sabre\DAV\INode; |
|||
|
|||
|
|||
class RestoreFolder implements ICollection, IMoveTarget { |
|||
|
|||
/** @var string */ |
|||
protected $userId; |
|||
|
|||
public function __construct(string $userId) { |
|||
$this->userId = $userId; |
|||
} |
|||
|
|||
public function createFile($name, $data = null) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function createDirectory($name) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getChild($name) { |
|||
return null; |
|||
} |
|||
|
|||
public function delete() { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getName() { |
|||
return 'restore'; |
|||
} |
|||
|
|||
public function setName($name) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getLastModified(): int { |
|||
return 0; |
|||
} |
|||
|
|||
public function getChildren(): array { |
|||
return []; |
|||
} |
|||
|
|||
public function childExists($name): bool { |
|||
return false; |
|||
} |
|||
|
|||
public function moveInto($targetName, $sourcePath, INode $sourceNode): bool { |
|||
if (!($sourceNode instanceof ITrash)) { |
|||
return false; |
|||
} |
|||
|
|||
return $sourceNode->restore(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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\DAVACL\AbstractPrincipalCollection; |
|||
use Sabre\DAVACL\PrincipalBackend; |
|||
|
|||
class RootCollection extends AbstractPrincipalCollection { |
|||
|
|||
public function __construct(PrincipalBackend\BackendInterface $principalBackend) { |
|||
parent::__construct($principalBackend, 'principals/users'); |
|||
} |
|||
|
|||
/** |
|||
* This method returns a node for a principal. |
|||
* |
|||
* The passed array contains principal information, and is guaranteed to |
|||
* at least contain a uri item. Other properties may or may not be |
|||
* supplied by the authentication backend. |
|||
* |
|||
* @param array $principalInfo |
|||
* @return INode |
|||
*/ |
|||
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()) { |
|||
throw new \Sabre\DAV\Exception\Forbidden(); |
|||
} |
|||
return new TrashHome($principalInfo); |
|||
} |
|||
|
|||
public function getName(): string { |
|||
return 'trashbin'; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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 OCP\Files\FileInfo; |
|||
use Sabre\DAV\Exception\Forbidden; |
|||
use Sabre\DAV\IFile; |
|||
|
|||
class TrashFile implements IFile, ITrash { |
|||
/** @var string */ |
|||
private $userId; |
|||
|
|||
/** @var FileInfo */ |
|||
private $data; |
|||
|
|||
public function __construct(string $userId, FileInfo $data) { |
|||
$this->userId = $userId; |
|||
$this->data = $data; |
|||
} |
|||
|
|||
public function put($data) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function get() { |
|||
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()); |
|||
} |
|||
|
|||
public function getName(): string { |
|||
return $this->data->getName() . '.d' . $this->getLastModified(); |
|||
} |
|||
|
|||
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->getName(), $this->data->getName(), $this->getLastModified()); |
|||
} |
|||
|
|||
public function getFilename(): string { |
|||
return $this->data->getName(); |
|||
} |
|||
|
|||
public function getOriginalLocation(): string { |
|||
return $this->data['extraData']; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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 OCP\Files\FileInfo; |
|||
use Sabre\DAV\Exception\Forbidden; |
|||
use Sabre\DAV\Exception\NotFound; |
|||
use Sabre\DAV\ICollection; |
|||
|
|||
class TrashFolder 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; |
|||
} |
|||
|
|||
public function createFile($name, $data = null) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function createDirectory($name) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getChild($name): ITrash { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|||
|
|||
foreach ($entries as $entry) { |
|||
if ($entry->getName() === $name) { |
|||
if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|||
return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
} |
|||
|
|||
throw new NotFound(); |
|||
} |
|||
|
|||
public function getChildren(): array { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|||
|
|||
$children = array_map(function (FileInfo $entry) { |
|||
if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|||
return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
}, $entries); |
|||
|
|||
return $children; |
|||
} |
|||
|
|||
public function childExists($name): bool { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|||
|
|||
foreach ($entries as $entry) { |
|||
if ($entry->getName() === $name) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public function delete() { |
|||
\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
|||
} |
|||
|
|||
public function getName(): string { |
|||
return $this->data->getName() . '.d' . $this->getLastModified(); |
|||
} |
|||
|
|||
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->getName(), $this->data->getName(), $this->getLastModified()); |
|||
} |
|||
|
|||
public function getFilename(): string { |
|||
return $this->data->getName(); |
|||
} |
|||
|
|||
public function getOriginalLocation(): string { |
|||
return $this->data['extraData']; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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 OCP\Files\FileInfo; |
|||
use Sabre\DAV\Exception\Forbidden; |
|||
use Sabre\DAV\IFile; |
|||
|
|||
class TrashFolderFile implements IFile, ITrash { |
|||
/** @var string */ |
|||
private $root; |
|||
|
|||
/** @var string */ |
|||
private $userId; |
|||
|
|||
/** @var FileInfo */ |
|||
private $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) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function get() { |
|||
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(); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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 OCP\Files\FileInfo; |
|||
use Sabre\DAV\Exception\Forbidden; |
|||
use Sabre\DAV\Exception\NotFound; |
|||
use Sabre\DAV\ICollection; |
|||
|
|||
class TrashFolderFolder implements ICollection, ITrash { |
|||
|
|||
/** @var string */ |
|||
private $root; |
|||
|
|||
/** @var string */ |
|||
private $userId; |
|||
|
|||
/** @var FileInfo */ |
|||
private $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) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function createDirectory($name) { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getChild($name): ITrash { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|||
|
|||
foreach ($entries as $entry) { |
|||
if ($entry->getName() === $name) { |
|||
if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|||
return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
} |
|||
|
|||
throw new NotFound(); |
|||
} |
|||
|
|||
public function getChildren(): array { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|||
|
|||
$children = array_map(function (FileInfo $entry) { |
|||
if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|||
return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
} |
|||
return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|||
}, $entries); |
|||
|
|||
return $children; |
|||
} |
|||
|
|||
public function childExists($name): bool { |
|||
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|||
|
|||
foreach ($entries as $entry) { |
|||
if ($entry->getName() === $name) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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\Exception\Forbidden; |
|||
use Sabre\DAV\Exception\NotFound; |
|||
use Sabre\DAV\ICollection; |
|||
|
|||
class TrashHome implements ICollection { |
|||
|
|||
/** @var array */ |
|||
private $principalInfo; |
|||
|
|||
public function __construct(array $principalInfo) { |
|||
$this->principalInfo = $principalInfo; |
|||
} |
|||
|
|||
public function delete() { |
|||
throw new Forbidden(); |
|||
} |
|||
|
|||
public function getName(): string { |
|||
list(,$name) = \Sabre\Uri\split($this->principalInfo['uri']); |
|||
return $name; |
|||
} |
|||
|
|||
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) { |
|||
list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']); |
|||
|
|||
if ($name === 'restore') { |
|||
return new RestoreFolder($userId); |
|||
} |
|||
if ($name === 'trash') { |
|||
return new TrashRoot($userId); |
|||
} |
|||
|
|||
throw new NotFound(); |
|||
} |
|||
|
|||
public function getChildren(): array { |
|||
list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']); |
|||
|
|||
return [ |
|||
new RestoreFolder($userId), |
|||
new TrashRoot($userId), |
|||
]; |
|||
} |
|||
|
|||
public function childExists($name): bool { |
|||
return $name === 'restore' || $name === 'trash'; |
|||
} |
|||
|
|||
public function getLastModified(): int { |
|||
return 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @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 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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue