RootCollection.php 2.1 KB

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