RootCollection.php 2.1 KB

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