RootCollection.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 OCA\Files_Versions\Versions\IVersionManager;
  25. use OCP\Files\IRootFolder;
  26. use OCP\IConfig;
  27. use OCP\IUserManager;
  28. use Sabre\DAV\INode;
  29. use Sabre\DAVACL\AbstractPrincipalCollection;
  30. use Sabre\DAVACL\PrincipalBackend;
  31. class RootCollection extends AbstractPrincipalCollection {
  32. /** @var IRootFolder */
  33. private $rootFolder;
  34. /** @var IUserManager */
  35. private $userManager;
  36. /** @var IVersionManager */
  37. private $versionManager;
  38. public function __construct(
  39. PrincipalBackend\BackendInterface $principalBackend,
  40. IRootFolder $rootFolder,
  41. IConfig $config,
  42. IUserManager $userManager,
  43. IVersionManager $versionManager
  44. ) {
  45. parent::__construct($principalBackend, 'principals/users');
  46. $this->rootFolder = $rootFolder;
  47. $this->userManager = $userManager;
  48. $this->versionManager = $versionManager;
  49. $this->disableListing = !$config->getSystemValue('debug', false);
  50. }
  51. /**
  52. * This method returns a node for a principal.
  53. *
  54. * The passed array contains principal information, and is guaranteed to
  55. * at least contain a uri item. Other properties may or may not be
  56. * supplied by the authentication backend.
  57. *
  58. * @param array $principalInfo
  59. * @return INode
  60. */
  61. public function getChildForPrincipal(array $principalInfo) {
  62. list(, $name) = \Sabre\Uri\split($principalInfo['uri']);
  63. $user = \OC::$server->getUserSession()->getUser();
  64. if (is_null($user) || $name !== $user->getUID()) {
  65. throw new \Sabre\DAV\Exception\Forbidden();
  66. }
  67. return new VersionHome($principalInfo, $this->rootFolder, $this->userManager, $this->versionManager);
  68. }
  69. public function getName() {
  70. return 'versions';
  71. }
  72. }