expose additional props from trashbin sabre endpoint

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-09-03 18:30:10 +02:00
parent 58e281857f
commit 6372ae3a98
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
9 changed files with 116 additions and 130 deletions

View File

@ -18,6 +18,7 @@ return array(
'OCA\\Files_Trashbin\\Expiration' => $baseDir . '/../lib/Expiration.php',
'OCA\\Files_Trashbin\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files_Trashbin\\Hooks' => $baseDir . '/../lib/Hooks.php',
'OCA\\Files_Trashbin\\Sabre\\AbstractTrash' => $baseDir . '/../lib/Sabre/AbstractTrash.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',

View File

@ -33,6 +33,7 @@ class ComposerStaticInitFiles_Trashbin
'OCA\\Files_Trashbin\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php',
'OCA\\Files_Trashbin\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files_Trashbin\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
'OCA\\Files_Trashbin\\Sabre\\AbstractTrash' => __DIR__ . '/..' . '/../lib/Sabre/AbstractTrash.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',

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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 '';
});
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}