diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-11-25 10:25:11 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-11-25 10:25:11 +0100 |
commit | 132c454d21faade0a6059752962e15de2fb0fb6a (patch) | |
tree | fe7ce01ad201306310b5436f9544815451ff81bb | |
parent | 75b4abb0d24c0e3fa59937f6566af9c2e6ac74f8 (diff) | |
parent | 943782bdfe70abd61cac0fc09aa8211ce144a468 (diff) | |
download | nextcloud-server-132c454d21faade0a6059752962e15de2fb0fb6a.tar.gz nextcloud-server-132c454d21faade0a6059752962e15de2fb0fb6a.zip |
Merge pull request #20698 from owncloud/stable8.1-backport-19530
[stable8.1] 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 9b417e7403a..4dd92ac816e 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -1942,6 +1942,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)) { @@ -2024,7 +2026,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 92f6b612688..94a11300e44 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( |