aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Sabre
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/Sabre')
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrash.php45
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFile.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php21
-rw-r--r--apps/files_trashbin/lib/Sabre/ITrash.php25
-rw-r--r--apps/files_trashbin/lib/Sabre/RestoreFolder.php21
-rw-r--r--apps/files_trashbin/lib/Sabre/RootCollection.php35
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFile.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolder.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFile.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFolder.php22
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashHome.php40
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashRoot.php44
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashbinPlugin.php106
13 files changed, 139 insertions, 308 deletions
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
index e02e4c5b8ba..f032395437b 100644
--- a/apps/files_trashbin/lib/Sabre/AbstractTrash.php
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
@@ -3,42 +3,23 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
- *
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Service\ConfigService;
use OCA\Files_Trashbin\Trash\ITrashItem;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Files\FileInfo;
+use OCP\IUser;
+use Sabre\DAV\Exception\Forbidden;
abstract class AbstractTrash implements ITrash {
- /** @var ITrashItem */
- protected $data;
-
- /** @var ITrashManager */
- protected $trashManager;
-
- public function __construct(ITrashManager $trashManager, ITrashItem $data) {
- $this->trashManager = $trashManager;
- $this->data = $data;
+ public function __construct(
+ protected ITrashManager $trashManager,
+ protected ITrashItem $data,
+ ) {
}
public function getFilename(): string {
@@ -89,7 +70,15 @@ abstract class AbstractTrash implements ITrash {
return $this->data->getTitle();
}
+ public function getDeletedBy(): ?IUser {
+ return $this->data->getDeletedBy();
+ }
+
public function delete() {
+ if (!ConfigService::getDeleteFromTrashEnabled()) {
+ throw new Forbidden('Not allowed to delete items from the trash bin');
+ }
+
$this->trashManager->removeItem($this->data);
}
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
index 520a2a6b6ec..03014d23669 100644
--- a/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
index 8a61823cf10..9e8f67f4db6 100644
--- a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
- *
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/ITrash.php b/apps/files_trashbin/lib/Sabre/ITrash.php
index b6b4e70f3b9..f37e1ccd9c3 100644
--- a/apps/files_trashbin/lib/Sabre/ITrash.php
+++ b/apps/files_trashbin/lib/Sabre/ITrash.php
@@ -3,30 +3,13 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
use OCP\Files\FileInfo;
+use OCP\IUser;
interface ITrash {
public function restore(): bool;
@@ -39,6 +22,8 @@ interface ITrash {
public function getDeletionTime(): int;
+ public function getDeletedBy(): ?IUser;
+
public function getSize(): int|float;
public function getFileId(): int;
diff --git a/apps/files_trashbin/lib/Sabre/RestoreFolder.php b/apps/files_trashbin/lib/Sabre/RestoreFolder.php
index 9076b3dc284..781a28bbc25 100644
--- a/apps/files_trashbin/lib/Sabre/RestoreFolder.php
+++ b/apps/files_trashbin/lib/Sabre/RestoreFolder.php
@@ -3,25 +3,8 @@
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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php
index f1b705f3e13..8886dae0895 100644
--- a/apps/files_trashbin/lib/Sabre/RootCollection.php
+++ b/apps/files_trashbin/lib/Sabre/RootCollection.php
@@ -3,47 +3,26 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\IConfig;
+use OCP\IUserSession;
+use OCP\Server;
use Sabre\DAV\INode;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend;
class RootCollection extends AbstractPrincipalCollection {
- /** @var ITrashManager */
- private $trashManager;
-
public function __construct(
- ITrashManager $trashManager,
+ private ITrashManager $trashManager,
PrincipalBackend\BackendInterface $principalBackend,
- IConfig $config
+ IConfig $config,
) {
parent::__construct($principalBackend, 'principals/users');
-
- $this->trashManager = $trashManager;
$this->disableListing = !$config->getSystemValue('debug', false);
}
@@ -59,7 +38,7 @@ class RootCollection extends AbstractPrincipalCollection {
*/
public function getChildForPrincipal(array $principalInfo): TrashHome {
[, $name] = \Sabre\Uri\split($principalInfo['uri']);
- $user = \OC::$server->getUserSession()->getUser();
+ $user = Server::get(IUserSession::class)->getUser();
if (is_null($user) || $name !== $user->getUID()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php
index a3351479487..29bcde769d9 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFile.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php
index fed39d67aa0..e1c495bf08e 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
index 5067d88cb48..37e70b717ae 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
index b276a6f29f9..1a5cb98e114 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php
index dda347f4c99..fc291c76f17 100644
--- a/apps/files_trashbin/lib/Sabre/TrashHome.php
+++ b/apps/files_trashbin/lib/Sabre/TrashHome.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
@@ -33,23 +15,11 @@ use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashHome implements ICollection {
- /** @var ITrashManager */
- private $trashManager;
-
- /** @var array */
- private $principalInfo;
-
- /** @var IUser */
- private $user;
-
public function __construct(
- array $principalInfo,
- ITrashManager $trashManager,
- IUser $user
+ private array $principalInfo,
+ private ITrashManager $trashManager,
+ private IUser $user,
) {
- $this->principalInfo = $principalInfo;
- $this->trashManager = $trashManager;
- $this->user = $user;
}
public function delete() {
diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php
index b61daacdf43..dd89583d9a1 100644
--- a/apps/files_trashbin/lib/Sabre/TrashRoot.php
+++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php
@@ -3,32 +3,15 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Service\ConfigService;
use OCA\Files_Trashbin\Trash\ITrashItem;
use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCA\Files_Trashbin\Trashbin;
use OCP\Files\FileInfo;
use OCP\IUser;
use Sabre\DAV\Exception\Forbidden;
@@ -37,19 +20,18 @@ use Sabre\DAV\ICollection;
class TrashRoot implements ICollection {
- /** @var IUser */
- private $user;
-
- /** @var ITrashManager */
- private $trashManager;
-
- public function __construct(IUser $user, ITrashManager $trashManager) {
- $this->user = $user;
- $this->trashManager = $trashManager;
+ public function __construct(
+ private IUser $user,
+ private ITrashManager $trashManager,
+ ) {
}
public function delete() {
- \OCA\Files_Trashbin\Trashbin::deleteAll();
+ if (!ConfigService::getDeleteFromTrashEnabled()) {
+ throw new Forbidden('Not allowed to delete items from the trash bin');
+ }
+
+ Trashbin::deleteAll();
foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) {
$this->trashManager->removeItem($trashItem);
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
index 72b7332d9b1..54bb1326966 100644
--- a/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
+++ b/apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
@@ -3,32 +3,17 @@
declare(strict_types=1);
/**
- * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Robin Appelman <robin@icewind.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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Sabre;
+use OC\Files\FileInfo;
+use OC\Files\View;
use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCA\Files_Trashbin\Trash\ITrashItem;
use OCP\IPreview;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
@@ -41,17 +26,17 @@ class TrashbinPlugin extends ServerPlugin {
public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time';
public const TRASHBIN_TITLE = '{http://nextcloud.org/ns}trashbin-title';
+ public const TRASHBIN_DELETED_BY_ID = '{http://nextcloud.org/ns}trashbin-deleted-by-id';
+ public const TRASHBIN_DELETED_BY_DISPLAY_NAME = '{http://nextcloud.org/ns}trashbin-deleted-by-display-name';
+ public const TRASHBIN_BACKEND = '{http://nextcloud.org/ns}trashbin-backend';
/** @var Server */
private $server;
- /** @var IPreview */
- private $previewManager;
-
public function __construct(
- IPreview $previewManager
+ private IPreview $previewManager,
+ private View $view,
) {
- $this->previewManager = $previewManager;
}
public function initialize(Server $server) {
@@ -59,6 +44,7 @@ class TrashbinPlugin extends ServerPlugin {
$this->server->on('propFind', [$this, 'propFind']);
$this->server->on('afterMethod:GET', [$this,'httpGet']);
+ $this->server->on('beforeMove', [$this, 'beforeMove']);
}
@@ -83,6 +69,19 @@ class TrashbinPlugin extends ServerPlugin {
return $node->getDeletionTime();
});
+ $propFind->handle(self::TRASHBIN_DELETED_BY_ID, function () use ($node) {
+ return $node->getDeletedBy()?->getUID();
+ });
+
+ $propFind->handle(self::TRASHBIN_DELETED_BY_DISPLAY_NAME, function () use ($node) {
+ return $node->getDeletedBy()?->getDisplayName();
+ });
+
+ // Pass the real filename as the DAV display name
+ $propFind->handle(FilesPlugin::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
+ return $node->getFilename();
+ });
+
$propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
return $node->getSize();
});
@@ -105,13 +104,21 @@ class TrashbinPlugin extends ServerPlugin {
return $node->getFileId();
});
- $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
- return $this->previewManager->isAvailable($node->getFileInfo());
+ $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node): string {
+ return $this->previewManager->isAvailable($node->getFileInfo()) ? 'true' : 'false';
});
$propFind->handle(FilesPlugin::MOUNT_TYPE_PROPERTYNAME, function () {
return '';
});
+
+ $propFind->handle(self::TRASHBIN_BACKEND, function () use ($node) {
+ $fileInfo = $node->getFileInfo();
+ if (!($fileInfo instanceof ITrashItem)) {
+ return '';
+ }
+ return $fileInfo->getTrashBackend()::class;
+ });
}
/**
@@ -127,4 +134,47 @@ class TrashbinPlugin extends ServerPlugin {
$response->addHeader('Content-Disposition', 'attachment; filename="' . $node->getFilename() . '"');
}
}
+
+ /**
+ * Check if a user has available space before attempting to
+ * restore from trashbin unless they have unlimited quota.
+ *
+ * @param string $sourcePath
+ * @param string $destinationPath
+ * @return bool
+ */
+ public function beforeMove(string $sourcePath, string $destinationPath): bool {
+ try {
+ $node = $this->server->tree->getNodeForPath($sourcePath);
+ $destinationNodeParent = $this->server->tree->getNodeForPath(dirname($destinationPath));
+ } catch (\Sabre\DAV\Exception $e) {
+ \OCP\Server::get(LoggerInterface::class)
+ ->error($e->getMessage(), ['app' => 'files_trashbin', 'exception' => $e]);
+ return true;
+ }
+
+ // Check if a file is being restored before proceeding
+ if (!$node instanceof ITrash || !$destinationNodeParent instanceof RestoreFolder) {
+ return true;
+ }
+
+ $fileInfo = $node->getFileInfo();
+ if (!$fileInfo instanceof ITrashItem) {
+ return true;
+ }
+ $restoreFolder = dirname($fileInfo->getOriginalLocation());
+ $freeSpace = $this->view->free_space($restoreFolder);
+ if ($freeSpace === FileInfo::SPACE_NOT_COMPUTED
+ || $freeSpace === FileInfo::SPACE_UNKNOWN
+ || $freeSpace === FileInfo::SPACE_UNLIMITED) {
+ return true;
+ }
+ $filesize = $fileInfo->getSize();
+ if ($freeSpace < $filesize) {
+ $this->server->httpResponse->setStatus(507);
+ return false;
+ }
+
+ return true;
+ }
}