1
0

VersionHome.php 2.7 KB

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