/** * Delete a share * * @param int $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(); }
/** * test unshare of a reshared file */ function testDeleteReshare() { // user 1 shares a folder with user2 \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); $fileInfo1 = $this->view->getFileInfo($this->folder); $fileInfo2 = $this->view->getFileInfo($this->folder . '/' . $this->filename); $result1 = \OCP\Share::shareItem('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result1); // user2 shares a file from the folder as link \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $result2 = \OCP\Share::shareItem('file', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1); $this->assertTrue(is_string($result2)); // test if we can unshare the link again $items = \OCP\Share::getItemShared('file', null); $this->assertEquals(1, count($items)); $item = reset($items); $result3 = \OCA\Files_Sharing\API\Local::deleteShare(array('id' => $item['id'])); $this->assertTrue($result3->succeeded()); // cleanup \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); $result = \OCP\Share::unshare('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); }
/** * 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(); }