RootCollection.php 2.6 KB

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