diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-06 09:23:44 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-06 09:23:44 +0200 |
commit | 26b92c406c20c13cfa37e7de0dbfa06de50a4eb9 (patch) | |
tree | 03a178d4b2fb265da023a5f9681427663ae886db | |
parent | 1525ef43f9a08f1da463228f9e3c7827f4a3b3c2 (diff) | |
parent | ac5b3161e44729b746e3a365b1011156a63e8fb6 (diff) | |
download | nextcloud-server-26b92c406c20c13cfa37e7de0dbfa06de50a4eb9.tar.gz nextcloud-server-26b92c406c20c13cfa37e7de0dbfa06de50a4eb9.zip |
Merge pull request #19530 from owncloud/issue-13213-sharing-conflict-when-sharing-subfile
Make sure the share we found is for the same item
-rw-r--r-- | lib/private/share/share.php | 4 | ||||
-rw-r--r-- | tests/lib/share/share.php | 33 |
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 32389f34868..42fec03d3ae 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -1989,6 +1989,8 @@ class Share extends Constants { $queriesToExecute = array(); $suggestedItemTarget = null; + $groupFileTarget = $fileTarget = $suggestedFileTarget = $filePath = ''; + $groupItemTarget = $itemTarget = $fileSource = $parent = 0; $result = self::checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate); if(!empty($result)) { @@ -2070,7 +2072,7 @@ class Share extends Constants { $userShareType = ($isGroupShare) ? self::$shareTypeGroupUserUnique : $shareType; - if ($sourceExists) { + if ($sourceExists && $sourceExists['item_source'] === $itemSource) { $fileTarget = $sourceExists['file_target']; $itemTarget = $sourceExists['item_target']; diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 58a76470afa..f0dc921e969 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -533,6 +533,39 @@ class Test_Share extends \Test\TestCase { $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']); } + public function testSharingAFileInsideAFolderThatIsAlreadyShared() { + OC_User::setUserId($this->user1); + $view = new \OC\Files\View('/' . $this->user1 . '/'); + $view->mkdir('files/test'); + $view->mkdir('files/test/sub1'); + $view->file_put_contents('files/test/sub1/file.txt', 'abc'); + + $folderInfo = $view->getFileInfo('files/test/sub1'); + $folderId = $folderInfo->getId(); + + $fileInfo = $view->getFileInfo('files/test/sub1/file.txt'); + $fileId = $fileInfo->getId(); + + $this->assertTrue( + OCP\Share::shareItem('folder', $folderId, OCP\Share::SHARE_TYPE_GROUP, $this->group2, \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_UPDATE), + 'Failed asserting that user 1 successfully shared "test/sub1" with group 2.' + ); + + $this->assertTrue( + OCP\Share::shareItem('file', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ), + 'Failed asserting that user 1 successfully shared "test/sub1/file.txt" with user 2.' + ); + + $result = \OCP\Share::getItemsSharedWithUser('file', $this->user2); + $this->assertCount(2, $result); + + foreach ($result as $share) { + $itemName = substr($share['path'], strrpos($share['path'], '/')); + $this->assertSame($itemName, $share['file_target'], 'Asserting that the file_target is the last segment of the path'); + $this->assertSame($share['item_target'], '/' . $share['item_source'], 'Asserting that the item is the item that was shared'); + } + } + protected function shareUserOneTestFileWithGroupOne() { OC_User::setUserId($this->user1); $this->assertTrue( |