[Pkg-owncloud-commits] [owncloud] 11/44: fix path in sharing results if it is a file in the Shared folder

David Prévot taffit at moszumanska.debian.org
Fri Mar 7 13:27:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit b4f154f9b4e76ac237c66705ffb9b5ab976352ee
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Tue Feb 25 15:28:21 2014 +0100

    fix path in sharing results if it is a file in the Shared folder
---
 apps/files_sharing/tests/api.php  | 68 +++++++++++++++++++++++++++++++++++++++
 apps/files_sharing/tests/base.php |  1 +
 lib/public/share.php              | 16 ++++++++-
 3 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 1278e0c..0d3d9b9 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -33,13 +33,16 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
 		parent::setUp();
 
 		$this->folder = '/folder_share_api_test';
+		$this->subfolder  = '/subfolder_share_api_test';
 
 		$this->filename = 'share-api-test.txt';
 
 		// save file with content
 		$this->view->file_put_contents($this->filename, $this->data);
 		$this->view->mkdir($this->folder);
+		$this->view->mkdir($this->folder . '/' . $this->subfolder);
 		$this->view->file_put_contents($this->folder.'/'.$this->filename, $this->data);
+		$this->view->file_put_contents($this->folder.'/' . $this->subfolder . '/' .$this->filename, $this->data);
 	}
 
 	function tearDown() {
@@ -287,6 +290,71 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
 	}
 
 	/**
+	 * @brief share a folder, than reshare a file within the shared folder and check if we construct the correct path
+	 * @medium
+	 */
+	function testGetShareFromFolderReshares() {
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+		$fileInfo1 = $this->view->getFileInfo($this->folder);
+		$fileInfo2 = $this->view->getFileInfo($this->folder.'/'.$this->filename);
+		$fileInfo3 = $this->view->getFileInfo($this->folder.'/' . $this->subfolder . '/' .$this->filename);
+
+		// share root 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);
+
+		// share file in root folder
+		$result = \OCP\Share::shareItem('file', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1);
+		// share was successful?
+		$this->assertTrue(is_string($result));
+
+		// share file in subfolder
+		$result = \OCP\Share::shareItem('file', $fileInfo3['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1);
+		// share was successful?
+		$this->assertTrue(is_string($result));
+
+		$testValues=array(
+			array('query' => 'Shared/' . $this->folder,
+				'expectedResult' => '/Shared' . $this->folder . '/' . $this->filename),
+			array('query' => 'Shared/' . $this->folder . $this->subfolder,
+				'expectedResult' => '/Shared' . $this->folder . $this->subfolder . '/' . $this->filename),
+		);
+		foreach ($testValues as $value) {
+
+			$_GET['path'] = $value['query'];
+			$_GET['subfiles'] = 'true';
+
+			$result = Share\Api::getAllShares(array());
+
+			$this->assertTrue($result->succeeded());
+
+			// test should return one share within $this->folder
+			$data = $result->getData();
+
+			$this->assertEquals($value['expectedResult'], $data[0]['path']);
+		}
+
+		// cleanup
+
+		\OCP\Share::unshare('file', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
+		\OCP\Share::unshare('file', $fileInfo3['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+		\OCP\Share::unshare('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+				\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+
+	}
+
+	/**
 	 * @medium
 	 */
 	function testGetShareFromUnknownId() {
diff --git a/apps/files_sharing/tests/base.php b/apps/files_sharing/tests/base.php
index 3e28327..d44972d 100644
--- a/apps/files_sharing/tests/base.php
+++ b/apps/files_sharing/tests/base.php
@@ -43,6 +43,7 @@ abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase {
 	 */
 	public $view;
 	public $folder;
+	public $subfolder;
 
 	public static function setUpBeforeClass() {
 		// reset backend
diff --git a/lib/public/share.php b/lib/public/share.php
index ae7d29e..c23ab08 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -1241,7 +1241,21 @@ class Share {
 			// Remove root from file source paths if retrieving own shared items
 			if (isset($uidOwner) && isset($row['path'])) {
 				if (isset($row['parent'])) {
-					$row['path'] = '/Shared/'.basename($row['path']);
+					$query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?');
+					$parentResult = $query->execute(array($row['parent']));
+					if (\OC_DB::isError($result)) {
+						\OC_Log::write('OCP\Share', 'Can\'t select parent: ' .
+								\OC_DB::getErrorMessage($result) . ', select=' . $select . ' where=' . $where,
+								\OC_Log::ERROR);
+					} else {
+						$parentRow = $parentResult->fetchRow();
+						$splitPath = explode('/', $row['path']);
+						$tmpPath = '/Shared' . $parentRow['file_target'];
+						foreach (array_slice($splitPath, 2) as $pathPart) {
+							$tmpPath = $tmpPath . '/' . $pathPart;
+						}
+						$row['path'] =  $tmpPath;
+					}
 				} else {
 					if (!isset($mounts[$row['storage']])) {
 						$mountPoints = \OC\Files\Filesystem::getMountByNumericId($row['storage']);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list