diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 0ba58aa896a..dc95a791d29 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -68,7 +68,7 @@ class Api { public static function getShare($params) { $s = self::getShareFromId($params['id']); - $params['itemSource'] = $s['item_source']; + $params['itemSource'] = $s['file_source']; $params['itemType'] = $s['item_type']; $params['specificShare'] = true; @@ -281,9 +281,8 @@ class Api { public static function updateShare($params) { $share = self::getShareFromId($params['id']); - $itemSource = isset($share['item_source']) ? $share['item_source'] : null; - if($itemSource === null) { + if(!isset($share['file_source'])) { return new \OC_OCS_Result(null, 404, "wrong share Id, share doesn't exist."); } @@ -431,10 +430,10 @@ class Api { public static function deleteShare($params) { $share = self::getShareFromId($params['id']); - $itemSource = isset($share['item_source']) ? $share['item_source'] : null; + $fileSource = isset($share['file_source']) ? $share['file_source'] : null; $itemType = isset($share['item_type']) ? $share['item_type'] : null;; - if($itemSource === null) { + if($fileSource === null) { return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); } @@ -448,7 +447,7 @@ class Api { try { $return = \OCP\Share::unshare( $itemType, - $itemSource, + $fileSource, $shareType, $shareWith); } catch (\Exception $e) { @@ -504,7 +503,7 @@ class Api { * @return array with: item_source, share_type, share_with, item_type, permissions */ private static function getShareFromId($shareID) { - $sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?'; + $sql = 'SELECT `file_source`, `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?'; $args = array($shareID); $query = \OCP\DB::prepare($sql); $result = $query->execute($args); diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php index 0d3d9b98b2e..073e2dd8c50 100644 --- a/apps/files_sharing/tests/api.php +++ b/apps/files_sharing/tests/api.php @@ -559,4 +559,38 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $this->assertTrue(empty($itemsAfterDelete)); } + + /** + * @brief 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 = Share\Api::deleteShare(array('id' => $item['id'])); + + $this->assertTrue($result3->succeeded()); + + } }