1
0

TrashHome.php 2.5 KB

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