diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index f3a3157851137..e76567e0ac7c7 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -510,8 +510,9 @@ public function testGetShareFromSourceWithReshares() { ->setPermissions(19); $share1 = $this->shareManager->createShare($share1); + $node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->filename); $share2 = $this->shareManager->newShare(); - $share2->setNode($node) + $share2->setNode($node2) ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith(self::TEST_FILES_SHARING_API_USER3) ->setShareType(IShare::TYPE_USER) @@ -633,7 +634,7 @@ public function testGetShareFromFolderReshares() { $share1->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share1); - $node2 = $this->userFolder->get($this->folder.'/'.$this->filename); + $node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder.'/'.$this->filename); $share2 = $this->shareManager->newShare(); $share2->setNode($node2) ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) @@ -643,7 +644,7 @@ public function testGetShareFromFolderReshares() { $share2->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share2); - $node3 = $this->userFolder->get($this->folder.'/'.$this->subfolder.'/'.$this->filename); + $node3 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder.'/'.$this->subfolder.'/'.$this->filename); $share3 = $this->shareManager->newShare(); $share3->setNode($node3) ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) @@ -824,8 +825,9 @@ public function testGetShareMultipleSharedFolder() { $share2->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share2); + $node2 = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->folder . $this->subfolder); $share3 = $this->shareManager->newShare(); - $share3->setNode($node1) + $share3->setNode($node2) ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) ->setShareType(IShare::TYPE_LINK) ->setPermissions(1); diff --git a/build/integration/sharing_features/sharing-v1-part3.feature b/build/integration/sharing_features/sharing-v1-part3.feature index 42e0f1b6add04..00324093b0e35 100644 --- a/build/integration/sharing_features/sharing-v1-part3.feature +++ b/build/integration/sharing_features/sharing-v1-part3.feature @@ -472,6 +472,36 @@ Feature: sharing Then the OCS status code should be "404" And the HTTP status code should be "200" + Scenario: do allow to create links on a shared folder with two mountpoints + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And user "user1" belongs to group "group1" + And user "user0" created a folder "/TMP" + And user "user0" created a folder "/TMP/SUB" + And As an "user0" + And creating a share with + | path | TMP | + | shareType | 1 | + | shareWith | group1 | + | permissions | 15 | + When As an "user1" + And accepting last share + And As an "user0" + And creating a share with + | path | TMP/SUB | + | shareType | 0 | + | shareWith | user1 | + | permissions | 31 | + When As an "user1" + And accepting last share + And creating a share with + | path | TMP/SUB | + | shareType | 3 | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + Scenario: deleting file out of a share as recipient creates a backup for the owner Given As an "admin" And user "user0" exists diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ccc2d454a94de..0deae776caeea 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -52,6 +52,7 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; use OCP\Files\Node; +use OCP\Files\NotFoundException; use OCP\HintException; use OCP\IConfig; use OCP\IGroupManager; @@ -292,10 +293,18 @@ protected function generalCreateChecks(IShare $share) { $permissions = 0; if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) { - $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) { + try { + $targetNode = $share->getTarget() ? $userFolder->get($share->getTarget()) : null; + } catch (NotFoundException $e) { + $targetNode = null; + } + $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) use ($share, $targetNode) { // We need to filter since there might be other mountpoints that contain the file // e.g. if the user has access to the same external storage that the file is originating from - return $mount->getStorage()->instanceOfStorage(ISharedStorage::class); + return $mount->getStorage()->instanceOfStorage(ISharedStorage::class) && ( + $targetNode ? $targetNode->getPath() === $mount->getPath() : + $mount->getPath() === $share->getNode()->getPath() + ); }); $userMount = array_shift($userMounts); if ($userMount === null) {