Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-03-12 14:00:30 +0400
committerBjoern Schiessle <schiessle@owncloud.com>2014-03-13 23:28:08 +0400
commit30cca2524f26c030ba96c9c673e41fcedf8579a8 (patch)
tree15d7e066faf82302f9b205c43c24e3b83585e177 /apps/files_sharing
parent53ad7ebfea7ca7d6d34724f2eaebd59fe4e721d8 (diff)
finally fix the paths for the OCS Share API
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/api.php28
-rw-r--r--apps/files_sharing/tests/api.php105
2 files changed, 128 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php
index 668301123d8..494c1131491 100644
--- a/apps/files_sharing/lib/api.php
+++ b/apps/files_sharing/lib/api.php
@@ -98,8 +98,14 @@ class Api {
break;
}
}
+ } else {
+ $path = $params['path'];
+ foreach ($shares as $key => $share) {
+ $shares[$key]['path'] = $path;
+ }
}
+
// include also reshares in the lists. This means that the result
// will contain every user with access to the file.
if (isset($params['reshares']) && $params['reshares'] === true) {
@@ -107,8 +113,10 @@ class Api {
}
if ($receivedFrom) {
- $shares['received_from'] = $receivedFrom['uid_owner'];
- $shares['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
+ foreach ($shares as $key => $share) {
+ $shares[$key]['received_from'] = $receivedFrom['uid_owner'];
+ $shares[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
+ }
}
} else {
$shares = null;
@@ -174,9 +182,10 @@ class Api {
$share = \OCP\Share::getItemShared($itemType, $file['fileid']);
if($share) {
$receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']);
+ reset($share);
+ $key = key($share);
+ $share[$key]['path'] = self::correctPath($share[$key]['path'], $path);
if ($receivedFrom) {
- reset($share);
- $key = key($share);
$share[$key]['received_from'] = $receivedFrom['uid_owner'];
$share[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
}
@@ -522,4 +531,15 @@ class Api {
}
+ /**
+ * @brief make sure that the path has the correct root
+ *
+ * @param string $path path returned from the share API
+ * @param string $folder current root folder
+ * @return string the correct path
+ */
+ protected static function correctPath($path, $folder) {
+ return \OC_Filesystem::normalizePath('/' . $folder . '/' . basename($path));
+ }
+
}
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 30deb07c5b9..e2bbb548182 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -477,7 +477,90 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
}
- /**
+ /**
+ * @brief test multiple shared folder if the path gets constructed correctly
+ * @medium
+ */
+ function testGetShareMultipleSharedFolder() {
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ $fileInfo1 = $this->view->getFileInfo($this->folder);
+ $fileInfo2 = $this->view->getFileInfo($this->folder . $this->subfolder);
+
+
+ // share sub-folder to user2
+ $result = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ // share was successful?
+ $this->assertTrue($result);
+
+ // share folder to user2
+ $result = \OCP\Share::shareItem('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ // share was successful?
+ $this->assertTrue($result);
+
+
+ // login as user2
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+ $result = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1);
+ // share was successful?
+ $this->assertTrue(is_string($result));
+
+
+ // ask for shared/subfolder
+ $expectedPath1 = '/Shared' . $this->subfolder;
+ $_GET['path'] = $expectedPath1;
+
+ $result1 = Share\Api::getAllShares(array());
+
+ $this->assertTrue($result1->succeeded());
+
+ // test should return one share within $this->folder
+ $data1 = $result1->getData();
+ $share1 = reset($data1);
+
+ // ask for shared/folder/subfolder
+ $expectedPath2 = '/Shared' . $this->folder . $this->subfolder;
+ $_GET['path'] = $expectedPath2;
+
+ $result2 = Share\Api::getAllShares(array());
+
+ $this->assertTrue($result2->succeeded());
+
+ // test should return one share within $this->folder
+ $data2 = $result2->getData();
+ $share2 = reset($data2);
+
+
+ // validate results
+ // we should get exactly one result each time
+ $this->assertEquals(1, count($data1));
+ $this->assertEquals(1, count($data2));
+
+ $this->assertEquals($expectedPath1, $share1['path']);
+ $this->assertEquals($expectedPath2, $share2['path']);
+
+
+ // cleanup
+ $result = \OCP\Share::unshare('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
+ $this->assertTrue($result);
+
+ self::loginHelper(self::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);
+ $result = \OCP\Share::unshare('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+ $this->assertTrue($result);
+
+ }
+
+ /**
* @brief test re-re-share of folder if the path gets constructed correctly
* @medium
*/
@@ -784,4 +867,24 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
$this->assertTrue($result3->succeeded());
}
+
+ function testCorrectPath() {
+ $path = "/foo/bar/test.txt";
+ $folder = "/correct/path";
+ $expectedResult = "/correct/path/test.txt";
+
+ $shareApiDummy = new TestShareApi();
+
+ $this->assertSame($expectedResult, $shareApiDummy->correctPathTest($path, $folder));
+ }
+
+}
+
+/**
+ * @brief dumnmy class to test protected methods
+ */
+class TestShareApi extends \OCA\Files\Share\Api {
+ public function correctPathTest($path, $folder) {
+ return self::correctPath($path, $folder);
+}
}