summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-06-10 16:49:50 +0200
committerGitHub <noreply@github.com>2016-06-10 16:49:50 +0200
commit14fde6650c4b70e53999c21048ed58aa5981afb2 (patch)
tree00531b6289db83303e3a81fa2caf0271fc9197c7 /apps/files_sharing
parentffb2838dd89cc1eb4121f82c0954d6785b4448bb (diff)
parent72c5535492f10024f25f4b641c4c481f203a2872 (diff)
downloadnextcloud-server-14fde6650c4b70e53999c21048ed58aa5981afb2.tar.gz
nextcloud-server-14fde6650c4b70e53999c21048ed58aa5981afb2.zip
Merge pull request #25003 from owncloud/fix_ocs_path_response
Fix OCS Share API path response
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/API/Share20OCS.php24
-rw-r--r--apps/files_sharing/tests/API/Share20OCSTest.php21
-rw-r--r--apps/files_sharing/tests/ApiTest.php41
3 files changed, 65 insertions, 21 deletions
diff --git a/apps/files_sharing/lib/API/Share20OCS.php b/apps/files_sharing/lib/API/Share20OCS.php
index 90e1f19130c..53b27aae0b8 100644
--- a/apps/files_sharing/lib/API/Share20OCS.php
+++ b/apps/files_sharing/lib/API/Share20OCS.php
@@ -100,15 +100,8 @@ class Share20OCS {
*/
protected function formatShare(\OCP\Share\IShare $share) {
$sharedBy = $this->userManager->get($share->getSharedBy());
- // for federated shares the owner can be a remote user, in this
- // case we use the initiator
- if ($this->userManager->userExists($share->getShareOwner())) {
- $shareOwner = $this->userManager->get($share->getShareOwner());
- $localUser = $share->getShareOwner();
- } else {
- $shareOwner = $this->userManager->get($share->getSharedBy());
- $localUser = $share->getSharedBy();
- }
+ $shareOwner = $this->userManager->get($share->getShareOwner());
+
$result = [
'id' => $share->getId(),
'share_type' => $share->getShareType(),
@@ -123,8 +116,16 @@ class Share20OCS {
'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
];
- $node = $share->getNode();
- $result['path'] = $this->rootFolder->getUserFolder($localUser)->getRelativePath($node->getPath());
+ $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
+ $nodes = $userFolder->getById($share->getNodeId());
+
+ if (empty($nodes)) {
+ throw new NotFoundException();
+ }
+
+ $node = $nodes[0];
+
+ $result['path'] = $userFolder->getRelativePath($node->getPath());
if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder';
} else {
@@ -536,7 +537,6 @@ class Share20OCS {
$shares = array_merge($shares, $federatedShares);
}
-
$formatted = [];
foreach ($shares as $share) {
try {
diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/API/Share20OCSTest.php
index 02b16d7bf88..b760a0f47a0 100644
--- a/apps/files_sharing/tests/API/Share20OCSTest.php
+++ b/apps/files_sharing/tests/API/Share20OCSTest.php
@@ -433,8 +433,12 @@ class Share20OCSTest extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnArgument(0));
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
$this->rootFolder->method('getUserFolder')
- ->with($share->getShareOwner())
+ ->with($this->currentUser->getUID())
->willReturn($userFolder);
$this->urlGenerator
@@ -2006,8 +2010,19 @@ class Share20OCSTest extends \Test\TestCase {
->willReturn('myLink');
- $this->rootFolder->method('getUserFolder')->with($share->getShareOwner())->will($this->returnSelf());
- $this->rootFolder->method('getRelativePath')->will($this->returnArgument(0));
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser->getUID())
+ ->will($this->returnSelf());
+
+ if (!$exception) {
+ $this->rootFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
+ $this->rootFolder->method('getRelativePath')
+ ->with($share->getNode()->getPath())
+ ->will($this->returnArgument(0));
+ }
try {
$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index f44c346236e..058b0c4758c 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -764,8 +764,7 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
- $expectedPath = $this->folder . $this->subfolder;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ $this->assertEquals($this->subfolder, $data[0]['path']);
$this->shareManager->deleteShare($share2);
$this->shareManager->deleteShare($share1);
@@ -801,6 +800,9 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
+ /*
+ * Test as recipient
+ */
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
@@ -811,9 +813,37 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
+ $this->assertEquals($this->subsubfolder, $data[0]['path']);
- $expectedPath = $this->folder . $this->subfolder . $this->subsubfolder;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ /*
+ * Test for first owner/initiator
+ */
+ $request = $this->createRequest([]);
+ $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
+ $result = $ocs->getShares();
+ $this->assertTrue($result->succeeded());
+
+ // test should return one share within $this->folder
+ $data = $result->getData();
+
+ // we should get exactly one result
+ $this->assertCount(1, $data);
+ $this->assertEquals($this->folder . $this->subfolder, $data[0]['path']);
+
+ /*
+ * Test for second initiator
+ */
+ $request = $this->createRequest([]);
+ $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
+ $result = $ocs->getShares();
+ $this->assertTrue($result->succeeded());
+
+ // test should return one share within $this->folder
+ $data = $result->getData();
+
+ // we should get exactly one result
+ $this->assertCount(1, $data);
+ $this->assertEquals($this->subfolder . $this->subsubfolder, $data[0]['path']);
$this->shareManager->deleteShare($share1);
$this->shareManager->deleteShare($share2);
@@ -922,8 +952,7 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
- $expectedPath = $this->folder.$this->subfolder.$this->filename;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ $this->assertEquals($this->filename, $data[0]['path']);
$this->shareManager->deleteShare($share1);
$this->shareManager->deleteShare($share2);