RootCollection.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Vincent Petry <vincent@nextcloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\Files;
  27. use OCP\Files\FileInfo;
  28. use Sabre\DAV\INode;
  29. use Sabre\DAV\SimpleCollection;
  30. use Sabre\DAVACL\AbstractPrincipalCollection;
  31. class RootCollection extends AbstractPrincipalCollection {
  32. /**
  33. * This method returns a node for a principal.
  34. *
  35. * The passed array contains principal information, and is guaranteed to
  36. * at least contain a uri item. Other properties may or may not be
  37. * supplied by the authentication backend.
  38. *
  39. * @param array $principalInfo
  40. * @return INode
  41. */
  42. public function getChildForPrincipal(array $principalInfo) {
  43. [,$name] = \Sabre\Uri\split($principalInfo['uri']);
  44. $user = \OC::$server->getUserSession()->getUser();
  45. if (is_null($user) || $name !== $user->getUID()) {
  46. // a user is only allowed to see their own home contents, so in case another collection
  47. // is accessed, we return a simple empty collection for now
  48. // in the future this could be considered to be used for accessing shared files
  49. return new SimpleCollection($name);
  50. }
  51. $userFolder = \OC::$server->getUserFolder();
  52. if (!($userFolder instanceof FileInfo)) {
  53. throw new \Exception('Home does not exist');
  54. }
  55. return new FilesHome($principalInfo, $userFolder);
  56. }
  57. public function getName() {
  58. return 'files';
  59. }
  60. }