1
0

RootCollection.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Files;
  8. use OCP\Files\FileInfo;
  9. use Sabre\DAV\INode;
  10. use Sabre\DAV\SimpleCollection;
  11. use Sabre\DAVACL\AbstractPrincipalCollection;
  12. class RootCollection extends AbstractPrincipalCollection {
  13. /**
  14. * This method returns a node for a principal.
  15. *
  16. * The passed array contains principal information, and is guaranteed to
  17. * at least contain a uri item. Other properties may or may not be
  18. * supplied by the authentication backend.
  19. *
  20. * @param array $principalInfo
  21. * @return INode
  22. */
  23. public function getChildForPrincipal(array $principalInfo) {
  24. [,$name] = \Sabre\Uri\split($principalInfo['uri']);
  25. $user = \OC::$server->getUserSession()->getUser();
  26. if (is_null($user) || $name !== $user->getUID()) {
  27. // a user is only allowed to see their own home contents, so in case another collection
  28. // is accessed, we return a simple empty collection for now
  29. // in the future this could be considered to be used for accessing shared files
  30. return new SimpleCollection($name);
  31. }
  32. $userFolder = \OC::$server->getUserFolder();
  33. if (!($userFolder instanceof FileInfo)) {
  34. throw new \Exception('Home does not exist');
  35. }
  36. return new FilesHome($principalInfo, $userFolder);
  37. }
  38. public function getName() {
  39. return 'files';
  40. }
  41. }