Beispiel #1
0
 /**
  * @dataProvider dataGetShareById
  */
 public function testGetShareById($currentUserIs)
 {
     $otherUser1 = $this->getMock('\\OCP\\IUser');
     $otherUser2 = $this->getMock('\\OCP\\IUser');
     $otherUser3 = $this->getMock('\\OCP\\IUser');
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $share->method('getSharedWith')->with()->willReturn($currentUserIs === 'getSharedWith' ? $this->user : $otherUser1);
     $share->method('getSharedBy')->with()->willReturn($currentUserIs === 'getSharedBy' ? $this->user : $otherUser2);
     $share->method('getShareOwner')->with()->willReturn($currentUserIs === 'getShareOwner' ? $this->user : $otherUser3);
     $this->defaultProvider->expects($this->once())->method('getShareById')->with(42)->willReturn($share);
     $this->assertEquals($share, $this->manager->getShareById(42));
 }
Beispiel #2
0
 /**
  * @param int $id
  * @return \OC_OCS_Result
  */
 public function updateShare($id)
 {
     // Try both our default and our federated provider
     $share = null;
     try {
         $share = $this->shareManager->getShareById('ocinternal:' . $id);
     } catch (\OC\Share20\Exception\ShareNotFound $e) {
         //Ignore for now
         //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
     }
     // Could not find the share as internal share... maybe it is a federated share
     if ($share === null) {
         return \OCA\Files_Sharing\API\Local::updateShare(['id' => $id]);
     }
     if (!$this->canAccessShare($share)) {
         return new \OC_OCS_Result(null, 404, "wrong share Id, share doesn't exist.");
     }
     $permissions = $this->request->getParam('permissions', null);
     $password = $this->request->getParam('password', null);
     $publicUpload = $this->request->getParam('publicUpload', null);
     $expireDate = $this->request->getParam('expireDate', null);
     if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
         return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
     }
     if ($expireDate !== null) {
         try {
             $expireDate = $this->parseDate($expireDate);
         } catch (\Exception $e) {
             return new \OC_OCS_Result(null, 400, $e->getMessage());
         }
         $share->setExpirationDate($expireDate);
     }
     if ($permissions !== null) {
         $permissions = (int) $permissions;
         $share->setPermissions($permissions);
     }
     if ($password !== null) {
         $share->setPassword($password);
     }
     if ($publicUpload === 'true') {
         $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
     } else {
         if ($publicUpload === 'false') {
             $share->setPermissions(\OCP\Constants::PERMISSION_READ);
         }
     }
     try {
         $share = $this->shareManager->updateShare($share);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 400, $e->getMessage());
     }
     return new \OC_OCS_Result($this->formatShare($share));
 }
Beispiel #3
0
 /**
  * Delete a share
  *
  * @param string $id
  * @return \OC_OCS_Result
  */
 public function deleteShare($id)
 {
     try {
         $share = $this->shareManager->getShareById($id);
     } catch (\OC\Share20\Exception\ShareNotFound $e) {
         return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
     }
     /*
      * FIXME
      * User the old code path for remote shares until we have our remoteshareprovider
      */
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
         \OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]);
     }
     try {
         $this->shareManager->deleteShare($share);
     } catch (\OC\Share20\Exception\BackendError $e) {
         return new \OC_OCS_Result(null, 404, 'could not delete share');
     }
     return new \OC_OCS_Result();
 }
Beispiel #4
0
 /**
  * Delete a share
  *
  * @param string $id
  * @return \OC_OCS_Result
  */
 public function deleteShare($id)
 {
     // Try both our default and our federated provider
     $share = null;
     try {
         $share = $this->shareManager->getShareById('ocinternal:' . $id);
     } catch (\OC\Share20\Exception\ShareNotFound $e) {
         //Ignore for now
         //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
     }
     // Could not find the share as internal share... maybe it is a federated share
     if ($share === null) {
         return \OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]);
     }
     if (!$this->canAccessShare($share)) {
         return new \OC_OCS_Result(null, 404, 'could not delete share');
     }
     try {
         $this->shareManager->deleteShare($share);
     } catch (\OC\Share20\Exception\BackendError $e) {
         return new \OC_OCS_Result(null, 404, 'could not delete share');
     }
     return new \OC_OCS_Result();
 }
 public function testGetShareById()
 {
     $share = $this->getMock('\\OCP\\Share\\IShare');
     $this->defaultProvider->expects($this->once())->method('getShareById')->with(42)->willReturn($share);
     $this->assertEquals($share, $this->manager->getShareById('default:42'));
 }
Beispiel #6
0
 /**
  * @param int $id
  * @return \OC_OCS_Result
  */
 public function updateShare($id)
 {
     // Try both our default and our federated provider
     $share = null;
     try {
         $share = $this->shareManager->getShareById('ocinternal:' . $id);
     } catch (ShareNotFound $e) {
         //Ignore for now
         //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
     }
     // Could not find the share as internal share... maybe it is a federated share
     if ($share === null) {
         return \OCA\Files_Sharing\API\Local::updateShare(['id' => $id]);
     }
     if (!$this->canAccessShare($share)) {
         return new \OC_OCS_Result(null, 404, 'wrong share Id, share doesn\'t exist.');
     }
     $permissions = $this->request->getParam('permissions', null);
     $password = $this->request->getParam('password', null);
     $publicUpload = $this->request->getParam('publicUpload', null);
     $expireDate = $this->request->getParam('expireDate', null);
     /*
      * expirationdate, password and publicUpload only make sense for link shares
      */
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
         if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
             return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
         }
         $newPermissions = null;
         if ($publicUpload === 'true') {
             $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE;
         } else {
             if ($publicUpload === 'false') {
                 $newPermissions = \OCP\Constants::PERMISSION_READ;
             }
         }
         if ($permissions !== null) {
             $newPermissions = (int) $permissions;
         }
         if ($newPermissions !== null && $newPermissions !== \OCP\Constants::PERMISSION_READ && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) {
             return new \OC_OCS_Result(null, 400, 'can\'t change permission for public link share');
         }
         if ($newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) {
             if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
                 return new \OC_OCS_Result(null, 403, 'public upload disabled by the administrator');
             }
             if (!$share->getNode() instanceof \OCP\Files\Folder) {
                 return new \OC_OCS_Result(null, 400, "public upload is only possible for public shared folders");
             }
         }
         if ($newPermissions !== null) {
             $share->setPermissions($newPermissions);
         }
         if ($expireDate === '') {
             $share->setExpirationDate(null);
         } else {
             if ($expireDate !== null) {
                 try {
                     $expireDate = $this->parseDate($expireDate);
                 } catch (\Exception $e) {
                     return new \OC_OCS_Result(null, 400, $e->getMessage());
                 }
                 $share->setExpirationDate($expireDate);
             }
         }
         if ($password === '') {
             $share->setPassword(null);
         } else {
             if ($password !== null) {
                 $share->setPassword($password);
             }
         }
     } else {
         // For other shares only permissions is valid.
         if ($permissions === null) {
             return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
         } else {
             $permissions = (int) $permissions;
             $share->setPermissions($permissions);
         }
     }
     try {
         $share = $this->shareManager->updateShare($share);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 400, $e->getMessage());
     }
     return new \OC_OCS_Result($this->formatShare($share));
 }