Пример #1
0
 public function testGetSharedByWithLimit()
 {
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->method('getId')->willReturn(42);
     $node->method('getName')->willReturn('myFile');
     $this->tokenHandler->method('generateToken')->willReturn('token');
     $this->notifications->method('sendRemoteShare')->willReturn(true);
     $this->rootFolder->expects($this->never())->method($this->anything());
     $share = $this->shareManager->newShare();
     $share->setSharedWith('*****@*****.**')->setSharedBy('sharedBy')->setShareOwner('shareOwner')->setPermissions(19)->setNode($node);
     $this->provider->create($share);
     $share2 = $this->shareManager->newShare();
     $share2->setSharedWith('*****@*****.**')->setSharedBy('sharedBy')->setShareOwner('shareOwner')->setPermissions(19)->setNode($node);
     $this->provider->create($share2);
     $shares = $this->provider->getSharesBy('shareOwner', \OCP\Share::SHARE_TYPE_REMOTE, null, true, 1, 1);
     $this->assertCount(1, $shares);
     $this->assertEquals('*****@*****.**', $shares[0]->getSharedWith());
 }
Пример #2
0
 /**
  * create re-share on behalf of another user
  *
  * @param $params
  * @return \OC_OCS_Result
  */
 public function reShare($params)
 {
     $id = isset($params['id']) ? (int) $params['id'] : null;
     $token = $this->request->getParam('token', null);
     $shareWith = $this->request->getParam('shareWith', null);
     $permission = (int) $this->request->getParam('permission', null);
     $remoteId = (int) $this->request->getParam('remoteId', null);
     if ($id === null || $token === null || $shareWith === null || $permission === null || $remoteId === null) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
     }
     try {
         $share = $this->federatedShareProvider->getShareById($id);
     } catch (Share\Exceptions\ShareNotFound $e) {
         return new \OC_OCS_Result(null, Http::STATUS_NOT_FOUND);
     }
     // don't allow to share a file back to the owner
     list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
     $owner = $share->getShareOwner();
     $currentServer = $this->addressHandler->generateRemoteURL();
     if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
         return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
     }
     if ($this->verifyShare($share, $token)) {
         // check if re-sharing is allowed
         if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) {
             $share->setPermissions($share->getPermissions() & $permission);
             // the recipient of the initial share is now the initiator for the re-share
             $share->setSharedBy($share->getSharedWith());
             $share->setSharedWith($shareWith);
             try {
                 $result = $this->federatedShareProvider->create($share);
                 $this->federatedShareProvider->storeRemoteId((int) $result->getId(), $remoteId);
                 return new \OC_OCS_Result(['token' => $result->getToken(), 'remoteId' => $result->getId()]);
             } catch (\Exception $e) {
                 return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
             }
         } else {
             return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
         }
     }
     return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
 }