Exemplo n.º 1
0
 /**
  * Return a list of share types for outgoing shares
  *
  * @param \OCP\Files\Node $node file node
  *
  * @return int[] array of share types
  */
 private function getShareTypes(\OCP\Files\Node $node)
 {
     $shareTypes = [];
     $requestedShareTypes = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE];
     foreach ($requestedShareTypes as $requestedShareType) {
         // one of each type is enough to find out about the types
         $shares = $this->shareManager->getSharesBy($this->userId, $requestedShareType, $node, false, 1);
         if (!empty($shares)) {
             $shareTypes[] = $requestedShareType;
         }
     }
     return $shareTypes;
 }
Exemplo n.º 2
0
 protected function tearDown()
 {
     if ($this->sharedCache) {
         $this->sharedCache->clear();
     }
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER);
     foreach ($shares as $share) {
         $this->shareManager->deleteShare($share);
     }
     $this->view->deleteAll('container');
     $this->ownerCache->clear();
     parent::tearDown();
 }
Exemplo n.º 3
0
 /**
  * The getShares function.
  *
  * - Get shares by the current user
  * - Get shares by the current user and reshares (?reshares=true)
  * - Get shares with the current user (?shared_with_me=true)
  * - Get shares for a specific path (?path=...)
  * - Get all shares in a folder (?subfiles=true&path=..)
  *
  * @return \OC_OCS_Result
  */
 public function getShares()
 {
     $sharedWithMe = $this->request->getParam('shared_with_me', null);
     $reshares = $this->request->getParam('reshares', null);
     $subfiles = $this->request->getParam('subfiles');
     $path = $this->request->getParam('path', null);
     if ($path !== null) {
         $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
         try {
             $path = $userFolder->get($path);
         } catch (\OCP\Files\NotFoundException $e) {
             return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist');
         }
     }
     if ($sharedWithMe === 'true') {
         return $this->getSharedWithMe($path);
     }
     if ($subfiles === 'true') {
         return $this->getSharesInDir($path);
     }
     if ($reshares === 'true') {
         $reshares = true;
     } else {
         $reshares = false;
     }
     // Get all shares
     $userShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
     $groupShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
     $linkShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
     $shares = array_merge($userShares, $groupShares, $linkShares);
     if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
         $federatedShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
         $shares = array_merge($shares, $federatedShares);
     }
     $formatted = [];
     foreach ($shares as $share) {
         try {
             $formatted[] = $this->formatShare($share);
         } catch (NotFoundException $e) {
             //Ignore share
         }
     }
     return new \OC_OCS_Result($formatted);
 }
Exemplo n.º 4
0
 /**
  * @param OutputInterface $output
  */
 private function collectUsersShares(OutputInterface $output)
 {
     $output->writeln("Collecting all share information for files and folder of {$this->sourceUser} ...");
     $progress = new ProgressBar($output, count($this->shares));
     foreach ([\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
         $offset = 0;
         while (true) {
             $sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset);
             $progress->advance(count($sharePage));
             if (empty($sharePage)) {
                 break;
             }
             $this->shares = array_merge($this->shares, $sharePage);
             $offset += 50;
         }
     }
     $progress->finish();
     $output->writeln('');
 }