Merge pull request #25003 from owncloud/fix_ocs_path_response
Fix OCS Share API path response
This commit is contained in:
commit
14fde6650c
|
@ -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 {
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue