Пример #1
0
 /**
  * @medium
  */
 function testUpdateShareExpireDate()
 {
     $fileInfo = $this->view->getFileInfo($this->folder);
     $config = \OC::$server->getConfig();
     // enforce expire date, by default 7 days after the file was shared
     $config->setAppValue('core', 'shareapi_default_expire_date', 'yes');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes');
     $dateWithinRange = new \DateTime();
     $dateWithinRange->add(new \DateInterval('P5D'));
     $dateOutOfRange = new \DateTime();
     $dateOutOfRange->add(new \DateInterval('P8D'));
     $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1);
     // share was successful?
     $this->assertTrue(is_string($result));
     $items = \OCP\Share::getItemShared('file', null);
     // make sure that we found a link share
     $this->assertEquals(1, count($items));
     $linkShare = reset($items);
     // update expire date to a valid value
     $params = array();
     $params['id'] = $linkShare['id'];
     $params['_put'] = array();
     $params['_put']['expireDate'] = $dateWithinRange->format('Y-m-d');
     $result = \OCA\Files_Sharing\API\Local::updateShare($params);
     $this->assertTrue($result->succeeded());
     $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
     $updatedLinkShare = reset($items);
     // date should be changed
     $this->assertTrue(is_array($updatedLinkShare));
     $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
     // update expire date to a value out of range
     $params = array();
     $params['id'] = $linkShare['id'];
     $params['_put'] = array();
     $params['_put']['expireDate'] = $dateOutOfRange->format('Y-m-d');
     $result = \OCA\Files_Sharing\API\Local::updateShare($params);
     $this->assertFalse($result->succeeded());
     $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
     $updatedLinkShare = reset($items);
     // date shouldn't be changed
     $this->assertTrue(is_array($updatedLinkShare));
     $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
     // Try to remove expire date
     $params = array();
     $params['id'] = $linkShare['id'];
     $params['_put'] = ['expireDate' => ''];
     $result = \OCA\Files_Sharing\API\Local::updateShare($params);
     $this->assertFalse($result->succeeded());
     $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
     $updatedLinkShare = reset($items);
     // date shouldn't be changed
     $this->assertTrue(is_array($updatedLinkShare));
     $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
     // cleanup
     $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
 }
Пример #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));
 }
Пример #3
0
 public function updateShare($params)
 {
     return \OCA\Files_Sharing\API\Local::updateShare($params);
 }
Пример #4
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));
 }