]> source.dussan.org Git - nextcloud-server.git/commitdiff
we need the file_source to delete a share successfully
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 10 Mar 2014 10:16:09 +0000 (11:16 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Mon, 10 Mar 2014 10:35:54 +0000 (11:35 +0100)
apps/files_sharing/lib/api.php
apps/files_sharing/tests/api.php

index 0ba58aa896a1dfa2a9f28027c8ccf76ea4d98963..dc95a791d2934c33980b7cdc344fdbde196294b1 100644 (file)
@@ -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);
index 0d3d9b98b2e937c1252a3a9fdd06f827beb94745..073e2dd8c500d476713c422b55a3a7f31e8a4ce1 100644 (file)
@@ -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());
+
+       }
 }