Exemplo n.º 1
0
 private function init()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     Filesystem::initMountPoints($this->share['uid_owner']);
     // for updating our etags when changes are made to the share from the owners side (probably indirectly by us trough another share)
     $this->propagationManager->listenToOwnerChanges($this->share['uid_owner'], $this->user);
 }
Exemplo n.º 2
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
     $propagator = $this->propagationManager->getSharePropagator($user->getUID());
     $propagator->propagateDirtyMountPoints($shares);
     $shares = array_filter($shares, function ($share) {
         return $share['permissions'] > 0;
     });
     $shares = array_map(function ($share) use($user, $storageFactory) {
         // for updating etags for the share owner when we make changes to this share.
         $ownerPropagator = $this->propagationManager->getChangePropagator($share['uid_owner']);
         return new SharedMount('\\OC\\Files\\Storage\\Shared', '/' . $user->getUID() . '/' . $share['file_target'], array('propagationManager' => $this->propagationManager, 'propagator' => $ownerPropagator, 'share' => $share, 'user' => $user->getUID()), $storageFactory);
     }, $shares);
     // array_filter removes the null values from the array
     return array_filter($shares);
 }
Exemplo n.º 3
0
 /**
  * @param int $id
  */
 public function propagateById($id)
 {
     if (isset($this->propagatingIds[$id])) {
         return;
     }
     $this->propagatingIds[$id] = true;
     $shares = Share::getAllSharesForFileId($id);
     foreach ($shares as $share) {
         // propagate down the share tree
         $this->markDirty($share, microtime(true));
         // propagate up the share tree
         if ($share['share_with'] === $this->userId) {
             $user = $share['uid_owner'];
             $view = new View('/' . $user . '/files');
             try {
                 $path = $view->getPath($share['file_source']);
             } catch (NotFoundException $e) {
                 $path = null;
             }
             $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user));
             $watcher->writeHook(['path' => $path]);
         }
     }
     unset($this->propagatingIds[$id]);
 }
 /**
  * Propagate etag for the shares that are in $shares1 but not in $shares2.
  *
  * @param string $targetUserId user id for which to propagate shares
  * @param array $shares1
  * @param array $shares2
  */
 private function propagateSharesDiff($targetUserId, $shares1, $shares2)
 {
     $sharesToPropagate = array_udiff($shares1, $shares2, function ($share1, $share2) {
         return $share2['id'] - $share1['id'];
     });
     \OC\Files\Filesystem::initMountPoints($targetUserId);
     $this->propagationManager->propagateSharesToUser($sharesToPropagate, $targetUserId);
 }
Exemplo n.º 5
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
     $propagator = $this->propagationManager->getSharePropagator($user->getUID());
     $propagator->propagateDirtyMountPoints($shares);
     $shares = array_filter($shares, function ($share) {
         return $share['permissions'] > 0;
     });
     return array_map(function ($share) use($user, $storageFactory) {
         Filesystem::initMountPoints($share['uid_owner']);
         // for updating etags for the share owner when we make changes to this share.
         $ownerPropagator = $this->propagationManager->getChangePropagator($share['uid_owner']);
         // for updating our etags when changes are made to the share from the owners side (probably indirectly by us trough another share)
         $this->propagationManager->listenToOwnerChanges($share['uid_owner'], $user->getUID());
         return new SharedMount('\\OC\\Files\\Storage\\Shared', '/' . $user->getUID() . '/' . $share['file_target'], array('propagator' => $ownerPropagator, 'share' => $share, 'user' => $user->getUID()), $storageFactory);
     }, $shares);
 }
Exemplo n.º 6
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
     $propagator = $this->propagationManager->getSharePropagator($user->getUID());
     $propagator->propagateDirtyMountPoints($shares);
     $shares = array_filter($shares, function ($share) {
         return $share['permissions'] > 0;
     });
     $shares = array_map(function ($share) use($user, $storageFactory) {
         try {
             Filesystem::initMountPoints($share['uid_owner']);
         } catch (NoUserException $e) {
             \OC::$server->getLogger()->warning('The user \'' . $share['uid_owner'] . '\' of share with ID \'' . $share['id'] . '\' can\'t be retrieved.', array('app' => 'files_sharing'));
             return null;
         }
         // for updating etags for the share owner when we make changes to this share.
         $ownerPropagator = $this->propagationManager->getChangePropagator($share['uid_owner']);
         // for updating our etags when changes are made to the share from the owners side (probably indirectly by us trough another share)
         $this->propagationManager->listenToOwnerChanges($share['uid_owner'], $user->getUID());
         return new SharedMount('\\OC\\Files\\Storage\\Shared', '/' . $user->getUID() . '/' . $share['file_target'], array('propagator' => $ownerPropagator, 'share' => $share, 'user' => $user->getUID()), $storageFactory);
     }, $shares);
     // array_filter removes the null values from the array
     return array_filter($shares);
 }
Exemplo n.º 7
0
 public function propagateById($id)
 {
     $shares = Share::getAllSharesForFileId($id);
     foreach ($shares as $share) {
         // propagate down the share tree
         $this->markDirty($share, microtime(true));
         // propagate up the share tree
         if ($share['share_with'] === $this->userId) {
             $user = $share['uid_owner'];
             $view = new View('/' . $user . '/files');
             $path = $view->getPath($share['file_source']);
             $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user));
             $watcher->writeHook(['path' => $path]);
         }
     }
 }
 public function testPropagateWhenRemovedFromGroupWithSubdirTarget()
 {
     $this->recipientGroup->addUser($this->recipientUser);
     // relogin to refresh mount points
     $this->loginAsUser($this->recipientUser->getUID());
     $recipientView = new View('/' . $this->recipientUser->getUID() . '/files');
     $this->assertTrue($recipientView->mkdir('sub'));
     $this->assertTrue($recipientView->rename('folder', 'sub/folder'));
     $this->propagationManager->expects($this->once())->method('propagateSharesToUser')->with($this->callback(function ($shares) {
         if (count($shares) !== 1) {
             return false;
         }
         $share = array_values($shares)[0];
         return $share['file_source'] === $this->fileInfo['fileid'] && $share['share_with'] === $this->recipientGroup->getGID() && $share['file_target'] === '/sub/folder';
     }), $this->recipientUser->getUID());
     $this->recipientGroup->removeUser($this->recipientUser);
 }