mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
use existing node in SharesPlugin
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
151c800397
commit
ae7205f550
5 changed files with 82 additions and 49 deletions
|
|
@ -165,7 +165,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
|||
// if we already cached the folder this file is in we know there are no shares for this file
|
||||
if (array_search($parentPath, $this->cachedFolders) === false) {
|
||||
try {
|
||||
$node = $this->userFolder->get($sabreNode->getPath());
|
||||
$node = $sabreNode->getNode();
|
||||
} catch (NotFoundException $e) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -202,7 +202,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
|||
)
|
||||
) {
|
||||
try {
|
||||
$folderNode = $this->userFolder->get($sabreNode->getPath());
|
||||
$folderNode = $sabreNode->getNode();
|
||||
} catch (NotFoundException $e) {
|
||||
// If the folder can't be properly found just return
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
|
||||
|
||||
use OC\Files\FileInfo;
|
||||
use OC\Files\Node\Node;
|
||||
use OC\Files\Storage\Wrapper\Quota;
|
||||
use OCA\DAV\Connector\Sabre\Directory;
|
||||
use OCP\Files\ForbiddenException;
|
||||
|
|
@ -82,9 +83,12 @@ class DirectoryTest extends \Test\TestCase {
|
|||
|
||||
$this->view = $this->createMock('OC\Files\View');
|
||||
$this->info = $this->createMock('OC\Files\FileInfo');
|
||||
$this->info->expects($this->any())
|
||||
->method('isReadable')
|
||||
$this->info->method('isReadable')
|
||||
->willReturn(true);
|
||||
$this->info->method('getType')
|
||||
->willReturn(Node::TYPE_FOLDER);
|
||||
$this->info->method('getName')
|
||||
->willReturn("folder");
|
||||
}
|
||||
|
||||
private function getDir($path = '/') {
|
||||
|
|
@ -186,17 +190,17 @@ class DirectoryTest extends \Test\TestCase {
|
|||
$info2 = $this->getMockBuilder(FileInfo::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$info1->expects($this->any())
|
||||
->method('getName')
|
||||
$info1->method('getName')
|
||||
->willReturn('first');
|
||||
$info1->expects($this->any())
|
||||
->method('getEtag')
|
||||
$info1->method('getPath')
|
||||
->willReturn('folder/first');
|
||||
$info1->method('getEtag')
|
||||
->willReturn('abc');
|
||||
$info2->expects($this->any())
|
||||
->method('getName')
|
||||
$info2->method('getName')
|
||||
->willReturn('second');
|
||||
$info2->expects($this->any())
|
||||
->method('getEtag')
|
||||
$info2->method('getPath')
|
||||
->willReturn('folder/second');
|
||||
$info2->method('getEtag')
|
||||
->willReturn('def');
|
||||
|
||||
$this->view->expects($this->once())
|
||||
|
|
@ -403,8 +407,12 @@ class DirectoryTest extends \Test\TestCase {
|
|||
private function moveTest($source, $destination, $updatables, $deletables) {
|
||||
$view = new TestViewDirectory($updatables, $deletables);
|
||||
|
||||
$sourceInfo = new FileInfo($source, null, null, [], null);
|
||||
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
|
||||
$sourceInfo = new FileInfo($source, null, null, [
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$targetInfo = new FileInfo(dirname($destination), null, null, [
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$sourceNode = new Directory($view, $sourceInfo);
|
||||
$targetNode = $this->getMockBuilder(Directory::class)
|
||||
|
|
@ -429,8 +437,8 @@ class DirectoryTest extends \Test\TestCase {
|
|||
|
||||
$view = new TestViewDirectory($updatables, $deletables);
|
||||
|
||||
$sourceInfo = new FileInfo($source, null, null, [], null);
|
||||
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
|
||||
$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
|
||||
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);
|
||||
|
||||
$sourceNode = new Directory($view, $sourceInfo);
|
||||
$targetNode = $this->getMockBuilder(Directory::class)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ use OC\Files\Storage\Wrapper\PermissionsMask;
|
|||
use OC\Files\View;
|
||||
use OCA\DAV\Connector\Sabre\File;
|
||||
use OCP\Constants;
|
||||
use OCP\Files\FileInfo;
|
||||
use OCP\Files\ForbiddenException;
|
||||
use OCP\Files\Storage;
|
||||
use OCP\IConfig;
|
||||
|
|
@ -211,7 +212,8 @@ class FileTest extends TestCase {
|
|||
->willReturnArgument(0);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -272,7 +274,8 @@ class FileTest extends TestCase {
|
|||
$_SERVER['HTTP_OC_CHUNKED'] = true;
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
||||
|
|
@ -282,7 +285,8 @@ class FileTest extends TestCase {
|
|||
$file->releaseLock(ILockingProvider::LOCK_SHARED);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
||||
|
|
@ -326,7 +330,10 @@ class FileTest extends TestCase {
|
|||
$viewRoot . '/' . ltrim($path, '/'),
|
||||
$this->getMockStorage(),
|
||||
null,
|
||||
['permissions' => \OCP\Constants::PERMISSION_ALL],
|
||||
[
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
],
|
||||
null
|
||||
);
|
||||
|
||||
|
|
@ -690,7 +697,8 @@ class FileTest extends TestCase {
|
|||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -723,7 +731,8 @@ class FileTest extends TestCase {
|
|||
$view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -758,7 +767,8 @@ class FileTest extends TestCase {
|
|||
$_SERVER['HTTP_OC_CHUNKED'] = true;
|
||||
|
||||
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
$file->acquireLock(ILockingProvider::LOCK_SHARED);
|
||||
|
|
@ -766,7 +776,8 @@ class FileTest extends TestCase {
|
|||
$file->releaseLock(ILockingProvider::LOCK_SHARED);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
||||
|
|
@ -797,7 +808,8 @@ class FileTest extends TestCase {
|
|||
->willReturnArgument(0);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
||||
|
|
@ -836,7 +848,8 @@ class FileTest extends TestCase {
|
|||
->willReturnArgument(0);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
$file->setName('/super*star.txt');
|
||||
|
|
@ -863,7 +876,8 @@ class FileTest extends TestCase {
|
|||
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -897,7 +911,8 @@ class FileTest extends TestCase {
|
|||
->willReturn(true);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -915,7 +930,8 @@ class FileTest extends TestCase {
|
|||
->getMock();
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => 0
|
||||
'permissions' => 0,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -938,7 +954,8 @@ class FileTest extends TestCase {
|
|||
->willReturn(false);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -961,7 +978,8 @@ class FileTest extends TestCase {
|
|||
->willThrowException(new ForbiddenException('', true));
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -997,7 +1015,10 @@ class FileTest extends TestCase {
|
|||
'/' . $this->user . '/files/' . $path,
|
||||
$this->getMockStorage(),
|
||||
null,
|
||||
['permissions' => \OCP\Constants::PERMISSION_ALL],
|
||||
[
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
],
|
||||
null
|
||||
);
|
||||
|
||||
|
|
@ -1129,7 +1150,8 @@ class FileTest extends TestCase {
|
|||
->willReturn(false);
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -1149,7 +1171,8 @@ class FileTest extends TestCase {
|
|||
->willThrowException(new ForbiddenException('', true));
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -1168,7 +1191,8 @@ class FileTest extends TestCase {
|
|||
->method('fopen');
|
||||
|
||||
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
|
||||
'permissions' => \OCP\Constants::PERMISSION_CREATE // no read perm
|
||||
'permissions' => \OCP\Constants::PERMISSION_CREATE, // no read perm
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
], null);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
|
|
@ -1215,7 +1239,10 @@ class FileTest extends TestCase {
|
|||
'/' . $this->user . '/files/' . $path,
|
||||
$this->getMockStorage(),
|
||||
null,
|
||||
['permissions' => \OCP\Constants::PERMISSION_ALL],
|
||||
[
|
||||
'permissions' => \OCP\Constants::PERMISSION_ALL,
|
||||
'type' => FileInfo::TYPE_FOLDER,
|
||||
],
|
||||
null
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -167,17 +167,14 @@ class ObjectTreeTest extends \Test\TestCase {
|
|||
$fileInfo = $this->getMockBuilder(FileInfo::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$fileInfo->expects($this->once())
|
||||
->method('getType')
|
||||
$fileInfo->method('getType')
|
||||
->willReturn($type);
|
||||
$fileInfo->expects($this->once())
|
||||
->method('getName')
|
||||
$fileInfo->method('getName')
|
||||
->willReturn($outputFileName);
|
||||
$fileInfo->method('getStorage')
|
||||
->willReturn($this->createMock(\OC\Files\Storage\Common::class));
|
||||
|
||||
$view->expects($this->once())
|
||||
->method('getFileInfo')
|
||||
$view->method('getFileInfo')
|
||||
->with($fileInfoQueryPath)
|
||||
->willReturn($fileInfo);
|
||||
|
||||
|
|
|
|||
|
|
@ -111,9 +111,7 @@ class SharesPluginTest extends \Test\TestCase {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->userFolder->expects($this->once())
|
||||
->method('get')
|
||||
->with('/subdir')
|
||||
$sabreNode->method('getNode')
|
||||
->willReturn($node);
|
||||
|
||||
$this->shareManager->expects($this->any())
|
||||
|
|
@ -180,16 +178,19 @@ class SharesPluginTest extends \Test\TestCase {
|
|||
$node = $this->createMock(Folder::class);
|
||||
$node->method('getId')
|
||||
->willReturn(123);
|
||||
$node1 = $this->createMock(File::class);
|
||||
$node1 = $this->createMock(\OC\Files\Node\File::class);
|
||||
$node1->method('getId')
|
||||
->willReturn(111);
|
||||
$node2 = $this->createMock(File::class);
|
||||
$node2 = $this->createMock(\OC\Files\Node\File::class);
|
||||
$node2->method('getId')
|
||||
->willReturn(222);
|
||||
|
||||
$this->userFolder->method('get')
|
||||
->with('/subdir')
|
||||
$sabreNode->method('getNode')
|
||||
->willReturn($node);
|
||||
$sabreNode1->method('getNode')
|
||||
->willReturn($node1);
|
||||
$sabreNode2->method('getNode')
|
||||
->willReturn($node2);
|
||||
|
||||
$dummyShares = array_map(function ($type) {
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
|
|
|
|||
Loading…
Reference in a new issue