mountprovider.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OCA\Files_Sharing;
  9. use OC\Files\Filesystem;
  10. use OCA\Files_Sharing\Propagation\PropagationManager;
  11. use OCP\Files\Config\IMountProvider;
  12. use OCP\Files\Storage\IStorageFactory;
  13. use OCP\IConfig;
  14. use OCP\IUser;
  15. class MountProvider implements IMountProvider {
  16. /**
  17. * @var \OCP\IConfig
  18. */
  19. protected $config;
  20. /**
  21. * @var \OCA\Files_Sharing\Propagation\PropagationManager
  22. */
  23. protected $propagationManager;
  24. /**
  25. * @param \OCP\IConfig $config
  26. * @param \OCA\Files_Sharing\Propagation\PropagationManager $propagationManager
  27. */
  28. public function __construct(IConfig $config, PropagationManager $propagationManager) {
  29. $this->config = $config;
  30. $this->propagationManager = $propagationManager;
  31. }
  32. /**
  33. * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  34. *
  35. * @param \OCP\IUser $user
  36. * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  37. * @return \OCP\Files\Mount\IMountPoint[]
  38. */
  39. public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
  40. $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
  41. $propagator = $this->propagationManager->getSharePropagator($user->getUID());
  42. $propagator->propagateDirtyMountPoints($shares);
  43. $shares = array_filter($shares, function ($share) {
  44. return $share['permissions'] > 0;
  45. });
  46. return array_map(function ($share) use ($user, $storageFactory) {
  47. Filesystem::initMountPoints($share['uid_owner']);
  48. // for updating etags for the share owner when we make changes to this share.
  49. $ownerPropagator = $this->propagationManager->getChangePropagator($share['uid_owner']);
  50. // for updating our etags when changes are made to the share from the owners side (probably indirectly by us trough another share)
  51. $this->propagationManager->listenToOwnerChanges($share['uid_owner'], $user->getUID());
  52. return new SharedMount(
  53. '\OC\Files\Storage\Shared',
  54. '/' . $user->getUID() . '/' . $share['file_target'],
  55. array(
  56. 'propagator' => $ownerPropagator,
  57. 'share' => $share,
  58. 'user' => $user->getUID()
  59. ),
  60. $storageFactory
  61. );
  62. }, $shares);
  63. }
  64. }