TrashHome.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_Trashbin\Sabre;
  25. use OCA\Files_Trashbin\Trash\ITrashManager;
  26. use OCP\IUser;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\Exception\NotFound;
  29. use Sabre\DAV\ICollection;
  30. class TrashHome implements ICollection {
  31. /** @var ITrashManager */
  32. private $trashManager;
  33. /** @var array */
  34. private $principalInfo;
  35. /** @var IUser */
  36. private $user;
  37. public function __construct(
  38. array $principalInfo,
  39. ITrashManager $trashManager,
  40. IUser $user
  41. ) {
  42. $this->principalInfo = $principalInfo;
  43. $this->trashManager = $trashManager;
  44. $this->user = $user;
  45. }
  46. public function delete() {
  47. throw new Forbidden();
  48. }
  49. public function getName(): string {
  50. list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']);
  51. return $name;
  52. }
  53. public function setName($name) {
  54. throw new Forbidden('Permission denied to rename this trashbin');
  55. }
  56. public function createFile($name, $data = null) {
  57. throw new Forbidden('Not allowed to create files in the trashbin');
  58. }
  59. public function createDirectory($name) {
  60. throw new Forbidden('Not allowed to create folders in the trashbin');
  61. }
  62. public function getChild($name) {
  63. if ($name === 'restore') {
  64. return new RestoreFolder();
  65. }
  66. if ($name === 'trash') {
  67. return new TrashRoot($this->user, $this->trashManager);
  68. }
  69. throw new NotFound();
  70. }
  71. public function getChildren(): array {
  72. return [
  73. new RestoreFolder(),
  74. new TrashRoot($this->user, $this->trashManager)
  75. ];
  76. }
  77. public function childExists($name): bool {
  78. return $name === 'restore' || $name === 'trash';
  79. }
  80. public function getLastModified(): int {
  81. return 0;
  82. }
  83. }