diff --git a/apps/comments/lib/Search/CommentsSearchProvider.php b/apps/comments/lib/Search/CommentsSearchProvider.php index 3ce6abf306c55..81a05c7d37e70 100644 --- a/apps/comments/lib/Search/CommentsSearchProvider.php +++ b/apps/comments/lib/Search/CommentsSearchProvider.php @@ -53,10 +53,6 @@ public function getOrder(string $route, array $routeParameters): int { public function search(IUser $user, ISearchQuery $query): SearchResult { $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - if ($userFolder === null) { - return SearchResult::complete($this->l10n->t('Comments'), []); - } - $result = []; $numComments = 50; $offset = 0; diff --git a/apps/comments/tests/Unit/Activity/ListenerTest.php b/apps/comments/tests/Unit/Activity/ListenerTest.php index 949cdd70e13cb..efcf6b1c6e4b3 100644 --- a/apps/comments/tests/Unit/Activity/ListenerTest.php +++ b/apps/comments/tests/Unit/Activity/ListenerTest.php @@ -17,8 +17,8 @@ use OCP\Files\Config\ICachedMountFileInfo; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IUserMountCache; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IUser; use OCP\IUserSession; @@ -94,7 +94,7 @@ public function testCommentEvent(): void { $node = $this->createMock(Node::class); $nodes = [ $node ]; - $ownerFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); $ownerFolder->expects($this->any()) ->method('getById') ->willReturn($nodes); diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php index 04490ca63e84c..15fc146e46c8c 100644 --- a/apps/comments/tests/Unit/Controller/NotificationsTest.php +++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php @@ -15,8 +15,8 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IRequest; use OCP\IURLGenerator; @@ -99,7 +99,7 @@ public function testViewSuccess(): void { ->willReturn($comment); $file = $this->createMock(Node::class); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $user = $this->createMock(IUser::class); $this->rootFolder->expects($this->once()) @@ -176,7 +176,7 @@ public function testViewNoFile(): void { ->with('42') ->willReturn($comment); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index 37cad0b43df88..9d3af60752c01 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -12,8 +12,8 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IL10N; use OCP\IURLGenerator; @@ -80,7 +80,7 @@ public function testPrepareSuccess(): void { ->method('getPath') ->willReturn('/you/files/' . $fileName); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') @@ -196,7 +196,7 @@ public function testPrepareSuccessDeletedUser(): void { ->method('getPath') ->willReturn('/you/files/' . $fileName); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') @@ -491,7 +491,7 @@ public function testPrepareUnresolvableFileID(): void { $displayName = 'Huraga'; - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') diff --git a/apps/dav/tests/unit/Controller/DirectControllerTest.php b/apps/dav/tests/unit/Controller/DirectControllerTest.php index 837adde1da7fd..16cb14baeb86c 100644 --- a/apps/dav/tests/unit/Controller/DirectControllerTest.php +++ b/apps/dav/tests/unit/Controller/DirectControllerTest.php @@ -19,6 +19,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Security\ISecureRandom; @@ -59,7 +60,7 @@ protected function setUp(): void { } public function testGetUrlNonExistingFileId(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); @@ -73,7 +74,7 @@ public function testGetUrlNonExistingFileId(): void { } public function testGetUrlForFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); @@ -89,7 +90,7 @@ public function testGetUrlForFolder(): void { } public function testGetUrlValid(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); diff --git a/apps/dav/tests/unit/Direct/DirectFileTest.php b/apps/dav/tests/unit/Direct/DirectFileTest.php index f6f0f49fa8c37..e3b95cd4347c1 100644 --- a/apps/dav/tests/unit/Direct/DirectFileTest.php +++ b/apps/dav/tests/unit/Direct/DirectFileTest.php @@ -12,8 +12,8 @@ use OCA\DAV\Direct\DirectFile; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Exception\Forbidden; use Test\TestCase; @@ -21,7 +21,7 @@ class DirectFileTest extends TestCase { private Direct $direct; private IRootFolder&MockObject $rootFolder; - private Folder&MockObject $userFolder; + private IUserFolder&MockObject $userFolder; private File&MockObject $file; private IEventDispatcher&MockObject $eventDispatcher; private DirectFile $directFile; @@ -37,7 +37,7 @@ protected function setUp(): void { $this->rootFolder = $this->createMock(IRootFolder::class); - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('directUser') ->willReturn($this->userFolder); diff --git a/apps/files/tests/Controller/ConversionApiControllerTest.php b/apps/files/tests/Controller/ConversionApiControllerTest.php index 659fbe1a9560d..a994d3374d725 100644 --- a/apps/files/tests/Controller/ConversionApiControllerTest.php +++ b/apps/files/tests/Controller/ConversionApiControllerTest.php @@ -14,8 +14,8 @@ use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\Files\Conversion\IConversionManager; use OCP\Files\File; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IL10N; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; @@ -33,7 +33,7 @@ class ConversionApiControllerTest extends TestCase { private IConversionManager&MockObject $fileConversionManager; private IRootFolder&MockObject $rootFolder; private File&MockObject $file; - private Folder&MockObject $userFolder; + private IUserFolder&MockObject $userFolder; private IL10N&MockObject $l10n; private string $user; @@ -46,7 +46,7 @@ protected function setUp(): void { $this->l10n = $this->createMock(IL10N::class); $this->user = 'userid'; - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder->method('getUserFolder')->with($this->user)->willReturn($this->userFolder); diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index cd466b3e97ea9..a7fc8c8ad6f80 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -25,6 +25,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Template\ITemplateManager; use OCP\ICacheFactory; use OCP\IConfig; @@ -173,7 +174,7 @@ public function testIndexWithRegularBrowser(): void { [$this->user->getUID(), 'files', 'show_grid', true], ]); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->expects($this->any()) ->method('getUserFolder') @@ -221,7 +222,7 @@ public function testShortRedirect(?string $openfile, ?string $opendetails, strin ->with('files') ->willReturn(true); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->with('testuser1') @@ -256,7 +257,7 @@ public function testShowFileRouteWithTrashedFile(): void { ->method('getPath') ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); - $baseFolderFiles = $this->createMock(Folder::class); + $baseFolderFiles = $this->createMock(IUserFolder::class); $baseFolderTrash = $this->createMock(Folder::class); $this->rootFolder->expects($this->any()) diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 4a4d04be5c44f..4bd3da89662a9 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -85,7 +85,7 @@ protected function setUp(): void { $mount = $this->view->getMount($this->filename); $mount->getStorage()->getScanner()->scan('', Scanner::SCAN_RECURSIVE); - $this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $this->userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1); $this->appConfig = $this->createMock(IAppConfig::class); } diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php index 0be9fd9d50d70..9a0321348fce3 100644 --- a/apps/files_sharing/tests/ApplicationTest.php +++ b/apps/files_sharing/tests/ApplicationTest.php @@ -18,6 +18,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Storage\IStorage; use OCP\IUser; use OCP\IUserSession; @@ -78,7 +79,7 @@ public function testCheckDirectCanBeDownloaded( $file = $this->createMock(File::class); $file->method('getStorage')->willReturn($fileStorage); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get')->willReturn($file); $user = $this->createMock(IUser::class); @@ -166,7 +167,7 @@ function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) { $rootFolder->method('getStorage')->willReturn($nonSharedStorage); $rootFolder->method('getDirectoryListing')->willReturn([$folder]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get')->willReturn($rootFolder); $user = $this->createMock(IUser::class); diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php index 572463a9ebc4a..1c9c2186d4ebb 100644 --- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php +++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php @@ -7,8 +7,8 @@ namespace OCA\Files_Sharing\Tests\Collaboration; use OCA\Files_Sharing\Collaboration\ShareRecipientSorter; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IUser; use OCP\IUserSession; @@ -42,8 +42,7 @@ protected function setUp(): void { public function testSort($data): void { $node = $this->createMock(Node::class); - /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */ - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->willReturn($folder); @@ -81,8 +80,7 @@ public function testSort($data): void { } public function testSortNoNodes(): void { - /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */ - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->willReturn($folder); diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 93c9d6e817d97..fea31b3f14708 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -24,6 +24,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IShareOwnerlessMount; use OCP\Files\NotFoundException; @@ -270,7 +271,7 @@ public function testDeleteShareLocked(): void { $share = $this->newShare(); $share->setNode($node); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -435,7 +436,7 @@ public function testDeleteSharedWithMyGroup(): void { ->method('lock') ->with(ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -498,7 +499,7 @@ public function testDeleteSharedWithGroupIDontBelongTo(): void { ->method('lock') ->with(ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -534,7 +535,7 @@ public function testDeleteShareOwnerless(): void { ->method('getMountPoint') ->willReturn($mount); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getById') ->with(2) ->willReturn([$file]); @@ -913,7 +914,7 @@ public function testGetShare(array $shareParams, array $result, bool $attributes ->with($share->getFullId(), 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder ->method('getRelativePath') ->willReturnArgument(0); @@ -979,7 +980,7 @@ public function testGetShareInvalidNode(): void { ->with('ocinternal:42', 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1628,7 +1629,7 @@ function ($share) { } ); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get') ->with('path') ->willReturn($this->mockSimpleNode(...$getSharesParameters['node'])); @@ -1698,7 +1699,7 @@ public function testCannotAccessLinkShare(): void { $share->method('getShareType')->willReturn(IShare::TYPE_LINK); $share->method('getNodeId')->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1715,7 +1716,7 @@ public function testCanAccessShareWithPermissions(int $permissions, bool $expect $file = $this->createMock(File::class); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($file); @@ -1753,7 +1754,7 @@ public function testCanAccessShareAsGroupMember(string $group, bool $expected): $file = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($file); @@ -1814,7 +1815,7 @@ public function testCanAccessRoomShare( $share->method('getShareType')->willReturn(IShare::TYPE_ROOM); $share->method('getSharedWith')->willReturn('recipientRoom'); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1863,7 +1864,7 @@ public function testCreateShareInvalidPath(): void { $this->expectException(OCSNotFoundException::class); $this->expectExceptionMessage('Wrong path, file/folder does not exist'); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') @@ -2191,10 +2192,11 @@ public function testCreateShareLinkNoLinksAllowed(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -2217,10 +2219,11 @@ public function testCreateShareLinkNoPublicUpload(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2244,10 +2247,11 @@ public function testCreateShareLinkPublicUploadFile(): void { $file->method('getId')->willReturn(42); $file->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($file); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($file); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2268,10 +2272,11 @@ public function testCreateShareLinkPublicUploadFolder(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2307,10 +2312,11 @@ public function testCreateShareLinkPassword(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2346,10 +2352,11 @@ public function testCreateShareLinkSendPasswordByTalk(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2393,10 +2400,11 @@ public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void { ]); $path->method('getStorage')->willReturn($storage); $path->method('getPath')->willReturn('valid-path'); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2431,10 +2439,11 @@ public function testCreateShareValidExpireDate(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2477,10 +2486,11 @@ public function testCreateShareInvalidExpireDate(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2836,7 +2846,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions(): void { ])->onlyMethods(['formatShare']) ->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->exactly(2)) ->method('getUserFolder') ->with('currentUser') @@ -4023,7 +4033,7 @@ public function testUpdateShareOwnerless(): void { ->method('getMountPoint') ->willReturn($mount); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getById') ->with(2) ->willReturn([$file]); @@ -5001,20 +5011,19 @@ function ($user) { ->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken']) ->willReturn('myLink'); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); - + $userFolder = $this->createMock(IUserFolder::class); if (!$exception) { - $this->rootFolder->method('getFirstNodeById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($share->getNode()); - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($share->getNode()->getPath()) ->willReturnArgument(0); } + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); + $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); + $cm = $this->createMock(\OCP\Contacts\IManager::class); $this->overwriteService(\OCP\Contacts\IManager::class, $cm); @@ -5194,17 +5203,14 @@ public function testFormatRoomShare(array $expects, bool $helperAvailable, array ->setNote('personal note') ->setId(42); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($share->getNode()); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($share->getNode()->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); if (!$helperAvailable) { $this->appManager->method('isEnabledForUser') @@ -5242,7 +5248,7 @@ public function testFormatRoomShare(array $expects, bool $helperAvailable, array */ private function getNonSharedUserFolder(): array { $node = $this->getMockBuilder(Folder::class)->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -5259,11 +5265,11 @@ private function getNonSharedUserFolder(): array { } /** - * @return list{Folder, File} + * @return list{IUserFolder, File} */ private function getNonSharedUserFile(): array { $node = $this->getMockBuilder(File::class)->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -5351,17 +5357,14 @@ public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isT $this->previewManager->method('isAvailable')->with($node)->willReturn(false); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($node); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($node->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $serverName = 'remoteserver.com'; $this->trustedServers->method('isTrustedServer') @@ -5414,17 +5417,14 @@ public function testFormatShareWithFederatedShareWithAtInUsername(): void { $this->previewManager->method('isAvailable')->with($node)->willReturn(false); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($node); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($node->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $serverName = 'remoteserver.com'; $this->trustedServers->method('isTrustedServer') @@ -5441,7 +5441,7 @@ public function testOwnerCanAlwaysDownload(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $share->method('getSharedBy')->willReturn('sharedByUser'); @@ -5463,7 +5463,7 @@ public function testParentHideDownloadEnforcedOnChild(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5494,7 +5494,7 @@ public function testUserCanHideWhenParentAllows(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5525,7 +5525,7 @@ public function testParentDownloadAttributeInherited(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5563,7 +5563,7 @@ public function testFederatedStorageRespectsUserChoice(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(Storage::class); @@ -5592,7 +5592,7 @@ public function testUserAllowsDownloadWhenParentPermits(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5623,7 +5623,7 @@ public function testWrapperStorageUnwrapped(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $wrapperStorage = $this->createMock(Wrapper::class); $innerStorage = $this->createMock(SharedStorage::class); diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index 0e466e4aff24e..cf0ab30bc4ea9 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -192,6 +192,7 @@ protected function loginHelper($user, $create = false, $password = false) { Storage::getGlobalCache()->clearCache(); Server::get(IUserSession::class)->setUser(null); Filesystem::tearDown(); + \OC_User::setIncognitoMode(false); Server::get(IUserSession::class)->login($user, $password); \OC::$server->getUserFolder($user); diff --git a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php index bb951c9c8c7b1..ef36142555c8f 100644 --- a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php +++ b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php @@ -17,6 +17,7 @@ use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; use OCP\IRequest; @@ -81,7 +82,7 @@ public function testInvalidHeight(): void { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); @@ -134,7 +135,7 @@ public function testValidPreview(): void { } public function testTrashFileNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); @@ -158,7 +159,7 @@ public function testTrashFileNotFound(): void { } public function testTrashFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 3b8441a412443..0e28a52b5300a 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -23,6 +23,7 @@ use OCP\Files\Cache\ICache; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\Files\Storage\IStorage; use OCP\IUserManager; @@ -574,7 +575,7 @@ public function testShouldMoveToTrash(string $mountPoint, string $path, bool $us $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $eventDispatcher = $this->createMock(IEventDispatcher::class); $rootFolder = $this->createMock(IRootFolder::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock(); $trashManager = $this->createMock(ITrashManager::class); $event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock(); diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index ca3a130d9b394..039b18b126bd0 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -886,15 +886,11 @@ public static function expire($filename, $uid) { if ($softQuota) { $root = Server::get(IRootFolder::class); $userFolder = $root->getUserFolder($uid); - if (is_null($userFolder)) { - $availableSpace = 0; + $free = $quota - $userFolder->getSize(false); // remaining free space for user + if ($free > 0) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions } else { - $free = $quota - $userFolder->getSize(false); // remaining free space for user - if ($free > 0) { - $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions - } else { - $availableSpace = $free - $versionsSize; - } + $availableSpace = $free - $versionsSize; } } else { $availableSpace = $quota; diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php index 99b17bc2981bf..fe15c6431bc28 100644 --- a/apps/files_versions/tests/Command/CleanupTest.php +++ b/apps/files_versions/tests/Command/CleanupTest.php @@ -12,8 +12,8 @@ use OCA\Files_Versions\Command\CleanUp; use OCA\Files_Versions\Db\VersionsMapper; use OCP\Files\Cache\ICache; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Storage\IStorage; use OCP\UserInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -52,7 +52,7 @@ public function testDeleteVersions(bool $nodeExists): void { ->with('/testUser/files_versions') ->willReturn($nodeExists); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userHomeStorage = $this->createMock(IStorage::class); $userHomeStorageCache = $this->createMock(ICache::class); $this->rootFolder->expects($this->once()) diff --git a/apps/files_versions/tests/Controller/PreviewControllerTest.php b/apps/files_versions/tests/Controller/PreviewControllerTest.php index 542ea2b6b3485..7932f6399967c 100644 --- a/apps/files_versions/tests/Controller/PreviewControllerTest.php +++ b/apps/files_versions/tests/Controller/PreviewControllerTest.php @@ -15,6 +15,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; @@ -92,7 +93,7 @@ public function testInvalidVersion(): void { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') @@ -130,7 +131,7 @@ public function testValidPreview(): void { } public function testVersionNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 0e03b79bb1807..0705281d14f65 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -590,6 +590,9 @@ + + info, false)]]> + @@ -663,7 +666,6 @@ - @@ -1420,6 +1422,7 @@ + @@ -1437,6 +1440,7 @@ + @@ -2327,6 +2331,7 @@ + @@ -2533,6 +2538,7 @@ + @@ -3933,14 +3939,6 @@ __call(__FUNCTION__, func_get_args())]]> - - - - - - - - @@ -4428,9 +4426,6 @@ - - - diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index f8339f96056fc..0207382b78115 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -8,10 +8,12 @@ use OC\Core\Command\Base; use OC\Files\SetupManager; -use OCP\Files\NotFoundException; +use OC\User\NoUserException; +use OCP\Files\IRootFolder; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -84,20 +86,13 @@ private function formatLoginDate(int $timestamp): string { * @return array */ protected function getStorageInfo(IUser $user): array { - $this->setupManager->tearDown(); - $this->setupManager->setupForUser($user); + $root = Server::get(IRootFolder::class); try { - $storage = \OC_Helper::getStorageInfo('/'); - } catch (NotFoundException $e) { + $userFolder = $root->getUserFolder($user->getUID()); + return $userFolder->getUserQuota(); + } catch (NoUserException) { return []; } - return [ - 'free' => $storage['free'], - 'used' => $storage['used'], - 'total' => $storage['total'], - 'relative' => $storage['relative'], - 'quota' => $storage['quota'], - ]; } /** diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 0b6dd29f2040b..fccaa727b26e2 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -473,6 +473,7 @@ 'OCP\\Files\\IMimeTypeDetector' => $baseDir . '/lib/public/Files/IMimeTypeDetector.php', 'OCP\\Files\\IMimeTypeLoader' => $baseDir . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => $baseDir . '/lib/public/Files/IRootFolder.php', + 'OCP\\Files\\IUserFolder' => $baseDir . '/lib/public/Files/IUserFolder.php', 'OCP\\Files\\InvalidCharacterInPathException' => $baseDir . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => $baseDir . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => $baseDir . '/lib/public/Files/InvalidDirectoryException.php', @@ -1717,6 +1718,7 @@ 'OC\\Files\\Node\\NonExistingFile' => $baseDir . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => $baseDir . '/lib/private/Files/Node/NonExistingFolder.php', 'OC\\Files\\Node\\Root' => $baseDir . '/lib/private/Files/Node/Root.php', + 'OC\\Files\\Node\\UserFolder' => $baseDir . '/lib/private/Files/Node/UserFolder.php', 'OC\\Files\\Notify\\Change' => $baseDir . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => $baseDir . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\AppdataPreviewObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9c34d2cd4debd..b4c323b5c7920 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -514,6 +514,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\IMimeTypeDetector' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeDetector.php', 'OCP\\Files\\IMimeTypeLoader' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => __DIR__ . '/../../..' . '/lib/public/Files/IRootFolder.php', + 'OCP\\Files\\IUserFolder' => __DIR__ . '/../../..' . '/lib/public/Files/IUserFolder.php', 'OCP\\Files\\InvalidCharacterInPathException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidDirectoryException.php', @@ -1758,6 +1759,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Files\\Node\\NonExistingFile' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFolder.php', 'OC\\Files\\Node\\Root' => __DIR__ . '/../../..' . '/lib/private/Files/Node/Root.php', + 'OC\\Files\\Node\\UserFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/UserFolder.php', 'OC\\Files\\Notify\\Change' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\AppdataPreviewObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php', diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 3558664758816..c72a80f99bd6d 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -494,7 +494,7 @@ public function getOrCreateFolder(string $path, int $maxRetries = 5): IFolder { return $folder; } } catch (NotFoundException) { - $folder = dirname($path) === '.' ? $this : $this->get(dirname($path)); + $folder = in_array(dirname($path), ['.','/']) ? $this : $this->get(dirname($path)); if (!($folder instanceof Folder)) { throw new NotPermittedException("Unable to create folder $path. Parent is not a directory."); } diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index c4188b80ee5ec..ed05cf2ef091f 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -313,13 +313,6 @@ public function getName() { return $this->__call(__FUNCTION__, func_get_args()); } - /** - * @inheritDoc - */ - public function getUserFolder($userId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - public function getMimetype(): string { if (isset($this->data['mimetype'])) { return $this->data['mimetype']; diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php index bc3f3a2e80f38..412aad37719d9 100644 --- a/lib/private/Files/Node/LazyRoot.php +++ b/lib/private/Files/Node/LazyRoot.php @@ -9,6 +9,7 @@ use OCP\Files\Cache\ICacheEntry; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\Node as INode; @@ -34,7 +35,7 @@ protected function getRootFolder(): IRootFolder { return $folder; } - public function getUserFolder($userId) { + public function getUserFolder(string $userId): IUserFolder { return $this->__call(__FUNCTION__, func_get_args()); } diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index d7afb199b913f..bd4981a73f7b7 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -8,17 +8,19 @@ */ namespace OC\Files\Node; +use OC\Files\View; use OCP\Constants; -use OCP\Files\File; use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountManager; -use OCP\Files\NotFoundException; +use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IUser; -use Psr\Log\LoggerInterface; +use OCP\Server; -class LazyUserFolder extends LazyFolder { +class LazyUserFolder extends LazyFolder implements IUserFolder { private string $path; public function __construct( @@ -43,23 +45,19 @@ public function __construct( parent::__construct( $rootFolder, - function () use ($user): Folder { - try { - $node = $this->getRootFolder()->get($this->path); - if ($node instanceof File) { - $e = new \RuntimeException(); - \OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [ - 'exception' => $e, - ]); - throw $e; - } - return $node; - } catch (NotFoundException $e) { - if (!$this->getRootFolder()->nodeExists('/' . $user->getUID())) { - $this->getRootFolder()->newFolder('/' . $user->getUID()); - } - return $this->getRootFolder()->newFolder($this->path); - } + function () use ($user): UserFolder { + $root = $this->getRootFolder(); + $parent = $root->getOrCreateFolder('/' . $user->getUID(), maxRetries: 1); + $realFolder = $root->getOrCreateFolder('/' . $user->getUID() . '/files', maxRetries: 1); + return new UserFolder( + $root, + new View(), + $realFolder->getPath(), + $parent, + Server::get(IConfig::class), + $user, + Server::get(ICacheFactory::class), + ); }, $data, ); @@ -75,4 +73,8 @@ public function getMountPoint() { } return $mountPoint; } + + public function getUserQuota(bool $useCache = true): array { + return $this->__call(__FUNCTION__, func_get_args()); + } } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 9b0a48fa296fd..acbb5314fc391 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -22,6 +22,7 @@ use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node as INode; use OCP\Files\NotFoundException; @@ -29,6 +30,7 @@ use OCP\IAppConfig; use OCP\ICache; use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; use OCP\Server; @@ -67,7 +69,7 @@ public function __construct( private LoggerInterface $logger, private IUserManager $userManager, IEventDispatcher $eventDispatcher, - ICacheFactory $cacheFactory, + private ICacheFactory $cacheFactory, IAppConfig $appConfig, ) { parent::__construct($this, $view, ''); @@ -318,12 +320,10 @@ public function getName() { /** * Returns a view to user's files folder * - * @param string $userId user ID - * @return \OCP\Files\Folder * @throws NoUserException * @throws NotPermittedException */ - public function getUserFolder($userId) { + public function getUserFolder(string $userId): IUserFolder { $userObject = $this->userManager->get($userId); if (is_null($userObject)) { @@ -345,17 +345,17 @@ public function getUserFolder($userId) { if (!$this->userFolderCache->hasKey($userId)) { if ($this->mountManager->getSetupManager()->isSetupComplete($userObject)) { - try { - $folder = $this->get('/' . $userId . '/files'); - if (!$folder instanceof \OCP\Files\Folder) { - throw new \Exception("Account folder for \"$userId\" exists as a file"); - } - } catch (NotFoundException $e) { - if (!$this->nodeExists('/' . $userId)) { - $this->newFolder('/' . $userId); - } - $folder = $this->newFolder('/' . $userId . '/files'); - } + $parent = $this->getOrCreateFolder('/' . $userId, maxRetries: 1); + $realFolder = $this->getOrCreateFolder('/' . $userId . '/files', maxRetries: 1); + $folder = new UserFolder( + $this, + $this->view, + $realFolder->getPath(), + $parent, + Server::get(IConfig::class), + $userObject, + $this->cacheFactory, + ); } else { $folder = new LazyUserFolder($this, $userObject, $this->mountManager, $this->useDefaultHomeFoldersPermissions); } diff --git a/lib/private/Files/Node/UserFolder.php b/lib/private/Files/Node/UserFolder.php new file mode 100644 index 0000000000000..b7df31c05da55 --- /dev/null +++ b/lib/private/Files/Node/UserFolder.php @@ -0,0 +1,92 @@ +cacheFactory->createLocal('storage_info'); + if ($useCache) { + $cached = $memcache->get($this->getPath()); + if ($cached) { + return $cached; + } + } + + $quotaIncludeExternalStorage = $this->config->getSystemValueBool('quota_include_external_storage'); + $rootInfo = $this->getFileInfo($quotaIncludeExternalStorage); + + /** @var int|float $used */ + $used = max($rootInfo->getSize(), 0.0); + /** @var int|float $quota */ + $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; + $mount = $rootInfo->getMountPoint(); + $storage = $mount->getStorage(); + if ($storage === null) { + throw new \RuntimeException('Storage returned from mount point is null.'); + } + + if ($storage->instanceOfStorage(Quota::class)) { + $quota = $storage->getQuota(); + } elseif ($quotaIncludeExternalStorage) { + $quota = $this->user->getQuotaBytes(); + } + + $free = $storage->free_space($rootInfo->getInternalPath()); + if (is_bool($free)) { + $free = 0.0; + } + + if ($free >= 0) { + $total = $free + $used; + } else { + $total = $free; //either unknown or unlimited + } + + $relative = $total > 0 + ? $used / $total + : 0; + $this->config->setUserValue($this->user->getUID(), 'files', 'lastSeenQuotaUsage', (string)$relative); + + $info = [ + 'free' => $free, + 'used' => $used, + 'quota' => $quota, + 'total' => $total, + ]; + $memcache->set($this->getPath(), $info, 5 * 60); + + return $info; + } + +} diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 1de44193cbc97..78f9ebe5a7093 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -14,6 +14,7 @@ use OCP\Accounts\IAccountManager; use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\IRootFolder; use OCP\Group\Events\BeforeUserRemovedEvent; use OCP\Group\Events\UserRemovedEvent; use OCP\IAvatarManager; @@ -25,6 +26,7 @@ use OCP\IUser; use OCP\IUserBackend; use OCP\Notification\IManager as INotificationManager; +use OCP\Server; use OCP\User\Backend\IGetHomeBackend; use OCP\User\Backend\IPasswordHashBackend; use OCP\User\Backend\IProvideAvatarBackend; @@ -596,7 +598,11 @@ public function setQuota($quota) { $this->config->setUserValue($this->uid, 'files', 'quota', $quota); $this->triggerChange('quota', $quota, $oldQuota); } - \OC_Helper::clearStorageInfo('/' . $this->uid . '/files'); + + // Refresh the quota cache + $root = Server::get(IRootFolder::class); + $userFolder = $root->getUserFolder($this->uid); + $userFolder->getUserQuota(false); } public function getManagerUids(): array { diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 84ef0aee565e5..41eeb7eba529a 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -195,6 +195,7 @@ public static function findBinaryPath(string $program): ?string { * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct * @return StorageInfo * @throws \OCP\Files\NotFoundException + * @deprecated 33.0.0 use \OCP\Files\IUserFolder::getUserQuota */ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { if (!self::$cacheFactory) { @@ -257,7 +258,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin // TODO: need a better way to get total space from storage if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { - /** @var \OC\Files\Storage\Wrapper\Quota $storage */ + /** @var \OC\Files\Storage\Wrapper\Quota $sourceStorage */ $quota = $sourceStorage->getQuota(); } try { @@ -379,6 +380,9 @@ private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMou ]; } + /** + * @deprecated 33.0.0 + */ public static function clearStorageInfo(string $absolutePath): void { /** @var ICacheFactory $cacheFactory */ $cacheFactory = \OC::$server->get(ICacheFactory::class); diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index fb8532f8c8153..494c7bb42ea10 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -1,14 +1,18 @@ expects($this->once()) ->method('getMimeType') ->willReturn('image/jpeg'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); @@ -386,7 +387,7 @@ public function testPostAvatarFromFile(): void { */ public function testPostAvatarFromNoFile(): void { $file = $this->getMockBuilder('OCP\Files\Node')->getMock(); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder ->method('get') @@ -408,7 +409,7 @@ public function testPostAvatarInvalidType(): void { $file->expects($this->exactly(2)) ->method('getMimeType') ->willReturn('text/plain'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); @@ -425,7 +426,7 @@ public function testPostAvatarNotPermittedException(): void { $file->expects($this->once()) ->method('getMimeType') ->willReturn('image/jpeg'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index 5a6cd1fba0a53..a8ca55a392bb9 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -13,6 +13,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\Storage\ISharedStorage; @@ -72,7 +73,7 @@ public function testInvalidHeight(): void { } public function testFileNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -88,7 +89,7 @@ public function testFileNotFound(): void { } public function testNotAFile(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -105,7 +106,7 @@ public function testNotAFile(): void { } public function testNoPreviewAndNoIcon(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -126,7 +127,7 @@ public function testNoPreviewAndNoIcon(): void { } public function testNoPreview() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -157,7 +158,7 @@ public function testNoPreview() { $this->assertEquals($expected, $res); } public function testFileWithoutReadPermission() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -181,7 +182,7 @@ public function testFileWithoutReadPermission() { } public function testFileWithoutDownloadPermission() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -221,7 +222,7 @@ public function testFileWithoutDownloadPermission() { } public function testFileWithoutDownloadPermissionButHeader() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -274,7 +275,7 @@ public function testFileWithoutDownloadPermissionButHeader() { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -313,7 +314,7 @@ public function testValidPreview(): void { } public function testValidPreviewOfShare() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index f519aeb4ce1d2..100652e1cee99 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -17,6 +17,7 @@ use OCP\Encryption\IManager; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IDBConnection; use OCP\IL10N; use OCP\IUser; @@ -107,10 +108,7 @@ class ManagerTest extends TestCase { * @var MockObject|IRootFolder */ private $rootFolder; - /** - * @var MockObject|Folder - */ - private $userFolder; + private IUserFolder&MockObject $userFolder; /** * @var MockObject|IL10N */ @@ -129,7 +127,7 @@ protected function setUp(): void { $this->connection = Server::get(IDBConnection::class); $this->userSession = $this->createMock(IUserSession::class); $this->rootFolder = $this->createMock(IRootFolder::class); - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->l10n = $this->createMock(IL10N::class); $this->encryptionManager = $this->createMock(IManager::class); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 3821b6943b15b..0dee1a6dc1e79 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -10,7 +10,6 @@ use OC\Files\FileInfo; use OC\Files\Mount\Manager; -use OC\Files\Node\Folder; use OC\Files\Node\Root; use OC\Files\Storage\Storage; use OC\Files\View; @@ -19,6 +18,7 @@ use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IAppConfig; @@ -210,7 +210,7 @@ public function testGetUserFolder(): void { ->expects($this->once()) ->method('hasKey') ->willReturn(true); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $cappedMemoryCache ->expects($this->once()) ->method('get') diff --git a/tests/lib/Files/Template/TemplateManagerTest.php b/tests/lib/Files/Template/TemplateManagerTest.php index 7b3f0beff429d..fdd836845da8b 100644 --- a/tests/lib/Files/Template/TemplateManagerTest.php +++ b/tests/lib/Files/Template/TemplateManagerTest.php @@ -17,6 +17,7 @@ use OCP\Files\Folder; use OCP\Files\GenericFileException; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IDBConnection; @@ -91,7 +92,7 @@ public function testCreateFromTemplateShoudValidateFilename(): void { $fileDirectory = '/'; $filePath = $fileDirectory . str_repeat('a', 251); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get') ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { if ($path === $filePath) { diff --git a/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php b/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php index fc88ee5d226e1..caadb221f188d 100644 --- a/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php +++ b/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php @@ -11,6 +11,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IUserManager; @@ -48,7 +49,7 @@ public function setUp(): void { } public function testCleanupPreviewsUnfinished(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); @@ -96,7 +97,7 @@ public function testCleanupPreviewsUnfinished(): void { } public function testCleanupPreviewsFinished(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); @@ -161,7 +162,7 @@ public function testNoUserFolder(): void { } public function testNoThumbnailFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') @@ -189,7 +190,7 @@ public function testNoThumbnailFolder(): void { } public function testNotPermittedToDelete(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 2ceb77aeb5008..e52ce0cef2887 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -20,6 +20,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; @@ -217,7 +218,7 @@ public function testGetShareByIdUserShare(): void { $shareOwner->method('getUID')->willReturn('shareOwner'); $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -295,7 +296,7 @@ public function testGetShareByIdLazy2(): void { $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -339,7 +340,7 @@ public function testGetShareByIdGroupShare(): void { $id = $qb->getLastInsertId(); $ownerPath = $this->createMock(Folder::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -379,8 +380,9 @@ public function testGetShareByIdUserGroupShare(): void { $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myTarget'); - $this->rootFolder->method('getUserFolder')->with('user0')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($node); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->willReturn($node); + $this->rootFolder->method('getUserFolder')->with('user0')->willReturn($userFolder); $this->userManager->method('get')->willReturnMap([ ['user0', $user0], @@ -424,7 +426,7 @@ public function testGetShareByIdLinkShare(): void { $id = $qb->getLastInsertId(); $ownerPath = $this->createMock(Folder::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -647,7 +649,7 @@ public function testGetChildren(): void { $qb->executeStatement(); $ownerPath = $this->createMock(Folder::class); - $ownerFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); $ownerFolder->method('getFirstNodeById')->willReturn($ownerPath); $this->rootFolder @@ -696,8 +698,8 @@ public function testCreateUserShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -768,8 +770,8 @@ public function testCreateGroupShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -838,8 +840,8 @@ public function testCreateLinkShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -905,8 +907,9 @@ public function testGetShareByToken(): void { $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getShareByToken('secrettoken'); $this->assertEquals($id, $share->getId()); @@ -944,8 +947,9 @@ public function testGetShareByTokenNullLabel(): void { $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getShareByToken('secrettoken'); $this->assertEquals($id, $share->getId()); @@ -1027,8 +1031,9 @@ public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2): $this->assertEquals(1, $qb->executeStatement()); $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with($fileId)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1, 0); $this->assertCount(1, $share); @@ -1228,8 +1233,9 @@ public function testGetSharedWithUserWithNode($storageStringId, $fileName1, $fil $file = $this->createMock(File::class); $file->method('getId')->willReturn($fileId2); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($fileId2)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getSharedWith('user0', IShare::TYPE_USER, $file, -1, 0); $this->assertCount(1, $share); @@ -1269,8 +1275,9 @@ public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fi $node = $this->createMock(Folder::class); $node->method('getId')->willReturn($fileId2); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($node); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($fileId2)->willReturn($node); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getSharedWith('user0', IShare::TYPE_GROUP, $node, -1, 0); $this->assertCount(1, $share); @@ -1318,8 +1325,9 @@ public function testGetSharedWithWithDeletedFile($shareType, $trashed): void { $this->assertEquals(1, $qb->executeStatement()); $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($deletedFileId)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($deletedFileId)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $groups = []; foreach (range(0, 100) as $i) { @@ -1430,8 +1438,9 @@ public function testGetSharesNode(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, $file, false, 1, 0); $this->assertCount(1, $share); @@ -1480,8 +1489,9 @@ public function testGetSharesReshare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_USER, null, true, -1, 0); $this->assertCount(2, $shares); @@ -1540,8 +1550,9 @@ public function testDeleteFromSelfGroupNoCustomShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1612,8 +1623,9 @@ public function testDeleteFromSelfGroupAlreadyCustomShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1670,8 +1682,9 @@ public function testDeleteFromSelfGroupUserNotInGroup(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1712,8 +1725,9 @@ public function testDeleteFromSelfGroupDoesNotExist(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1750,8 +1764,9 @@ public function testDeleteFromSelfUser(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1804,8 +1819,9 @@ public function testDeleteFromSelfUserNotRecipient(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1841,8 +1857,9 @@ public function testDeleteFromSelfLink(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1872,9 +1889,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -1929,9 +1946,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -1995,9 +2012,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2066,9 +2083,9 @@ function ($groupId) use ($groups) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2145,9 +2162,9 @@ function ($groupId) use ($groups) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2223,8 +2240,9 @@ public function testMoveUserShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id, null); @@ -2259,8 +2277,9 @@ public function testMoveGroupShare(): void { $folder = $this->createMock(Folder::class); $folder->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($folder); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($folder); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id, 'user0'); @@ -2943,23 +2962,23 @@ public function testGetAllShares(): void { $id5 = $qb->getLastInsertId(); $ownerPath1 = $this->createMock(File::class); - $shareOwner1Folder = $this->createMock(Folder::class); + $shareOwner1Folder = $this->createMock(IUserFolder::class); $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1); $ownerPath2 = $this->createMock(File::class); - $shareOwner2Folder = $this->createMock(Folder::class); + $shareOwner2Folder = $this->createMock(IUserFolder::class); $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2); $ownerPath3 = $this->createMock(File::class); - $shareOwner3Folder = $this->createMock(Folder::class); + $shareOwner3Folder = $this->createMock(IUserFolder::class); $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3); $ownerPath4 = $this->createMock(File::class); - $shareOwner4Folder = $this->createMock(Folder::class); + $shareOwner4Folder = $this->createMock(IUserFolder::class); $shareOwner4Folder->method('getFirstNodeById')->willReturn($ownerPath4); $ownerPath5 = $this->createMock(File::class); - $shareOwner5Folder = $this->createMock(Folder::class); + $shareOwner5Folder = $this->createMock(IUserFolder::class); $shareOwner5Folder->method('getFirstNodeById')->willReturn($ownerPath5); $this->rootFolder diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index a7b93d35821b4..223476013c3c1 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -23,6 +23,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IShareOwnerlessMount; @@ -1074,7 +1075,7 @@ public function testGeneralChecks(array $shareParams, ?string $exceptionMessage, ['group0', true], ]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->expects($this->any()) ->method('getId') ->willReturn(42); @@ -1114,7 +1115,7 @@ public function testGeneralCheckShareRoot(): void { ['user1', true], ]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -3627,8 +3628,9 @@ public function testUpdateShareUser(): void { Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); $hookListener->expects($this->never())->method('post'); - $this->rootFolder->method('getUserFolder')->with('newUser')->willReturnSelf(); - $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); + $this->rootFolder->method('getUserFolder')->with('newUser')->willReturn($userFolder); $hookListener2 = $this->createMock(DummyShareManagerListener::class); Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post'); @@ -4755,7 +4757,7 @@ public function testGetAccessList(): void { $node->method('getId') ->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $file = $this->createMock(File::class); $folder = $this->createMock(Folder::class); @@ -4854,7 +4856,7 @@ public function testGetAccessListWithCurrentAccess(): void { $node->method('getId') ->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $file = $this->createMock(File::class); $owner = $this->createMock(IUser::class); diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php index 9528fc291848b..49087037cefb1 100644 --- a/tests/lib/TagsTest.php +++ b/tests/lib/TagsTest.php @@ -11,8 +11,8 @@ use OC\Tagging\TagMapper; use OC\TagManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IDBConnection; use OCP\ITagManager; @@ -55,7 +55,7 @@ protected function setUp(): void { ->expects($this->any()) ->method('getUser') ->willReturn($this->user); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $node = $this->createMock(Node::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index c1e07a0f153d9..4a0ab57f9e573 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -16,6 +16,7 @@ use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; use OCP\IURLGenerator; @@ -803,8 +804,13 @@ public function testSetQuota(): void { '23 TB' ); + /* Overwrite IRootFolder to avoid crash about unknown user */ + $this->overwriteService(IRootFolder::class, $this->createMock(IRootFolder::class)); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); $user->setQuota('23 TB'); + + $this->restoreService(IRootFolder::class); } public function testGetDefaultUnlimitedQuota(): void { @@ -890,8 +896,13 @@ public function testSetQuotaAddressNoChange(): void { $config->expects($this->never()) ->method('setUserValue'); + /* Overwrite IRootFolder to avoid crash about unknown user */ + $this->overwriteService(IRootFolder::class, $this->createMock(IRootFolder::class)); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); $user->setQuota('23 TB'); + + $this->restoreService(IRootFolder::class); } public function testGetLastLogin(): void {