Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
expose additional props from trashbin sabre endpoint
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Sep 20, 2018
commit 6372ae3a98537e8d1b5c5adf4fc446bc0651c2b1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
69 changes: 69 additions & 0 deletions apps/files_trashbin/lib/Sabre/AbstractTrash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]>
*
* @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();
}
}
4 changes: 4 additions & 0 deletions apps/files_trashbin/lib/Sabre/ITrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
namespace OCA\Files_Trashbin\Sabre;

use OCP\Files\FileInfo;

interface ITrash {
public function restore(): bool;

Expand All @@ -35,4 +37,6 @@ public function getDeletionTime(): int;
public function getSize();

public function getFileId(): int;

public function getFileInfo(): FileInfo;
}
36 changes: 33 additions & 3 deletions apps/files_trashbin/lib/Sabre/PropfindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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;
Expand All @@ -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) {
Expand All @@ -54,11 +62,11 @@ public function propFind(PropFind $propFind, INode $node) {
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();
});

Expand All @@ -73,6 +81,28 @@ public function propFind(PropFind $propFind, INode $node) {
$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 '';
});
}

}
37 changes: 2 additions & 35 deletions apps/files_trashbin/lib/Sabre/TrashFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@
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) {
Expand All @@ -47,18 +44,6 @@ 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());
}
Expand All @@ -71,29 +56,11 @@ 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'];
}

public function getDeletionTime(): int {
return $this->getLastModified();
}

public function getFileId(): int {
return $this->data->getId();
}


}
27 changes: 2 additions & 25 deletions apps/files_trashbin/lib/Sabre/TrashFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@
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) {
Expand Down Expand Up @@ -100,31 +97,11 @@ 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'];
}

public function getDeletionTime(): int {
return $this->getLastModified();
}

public function getSize(): int {
return $this->data->getSize();
}

public function getFileId(): int {
return $this->data->getId();
}
}
39 changes: 2 additions & 37 deletions apps/files_trashbin/lib/Sabre/TrashFolderFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@
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;

Expand All @@ -46,8 +43,8 @@ public function __construct(string $root,
string $location) {
$this->root = $root;
$this->userId = $userId;
$this->data = $data;
$this->location = $location;
parent::__construct($data);
}

public function put($data) {
Expand All @@ -58,51 +55,19 @@ 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();
}

public function getDeletionTime(): int {
return $this->getLastModified();
}

public function getFileId(): int {
return $this->data->getId();
}
}
Loading