Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/comments/lib/Listener/CommentsEntityEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
use OCP\Comments\CommentsEntityEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;

/** @template-implements IEventListener<CommentsEntityEvent> */
class CommentsEntityEventListener implements IEventListener {
public function __construct(
private IRootFolder $rootFolder,
private ?string $userId = null,
private ?IUserFolder $userFolder,
) {
}

Expand All @@ -29,12 +28,12 @@ public function handle(Event $event): void {
return;
}

if ($this->userId === null) {
if ($this->userFolder === null) {
return;
}

$event->addEntityCollection('files', function ($name): bool {
$node = $this->rootFolder->getUserFolder($this->userId)->getFirstNodeById((int)$name);
$node = $this->userFolder->getFirstNodeById((int)$name);
return $node !== null;
});
}
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/BulkUpload/BulkUploadPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use OCA\DAV\Connector\Sabre\MtimeSanitizer;
use OCP\AppFramework\Http;
use OCP\Files\DavUtil;
use OCP\Files\Folder;
use OCP\Files\IUserFolder;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
Expand All @@ -19,7 +19,7 @@

class BulkUploadPlugin extends ServerPlugin {
public function __construct(
private Folder $userFolder,
private IUserFolder $userFolder,
private LoggerInterface $logger,
) {
}
Expand Down
14 changes: 2 additions & 12 deletions apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\Files\Folder;
use OCP\Files\IUserFolder;
use OCP\Files\Node as INode;
use OCP\IGroupManager;
use OCP\ITagManager;
Expand Down Expand Up @@ -43,17 +44,6 @@ class FilesReportPlugin extends ServerPlugin {
*/
private $server;

/**
* @param Tree $tree
* @param View $fileView
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
* @param ITagManager $fileTagger manager for private tags
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param Folder $userFolder
* @param IAppManager $appManager
*/
public function __construct(
private Tree $tree,
private View $fileView,
Expand All @@ -65,7 +55,7 @@ public function __construct(
private ITagManager $fileTagger,
private IUserSession $userSession,
private IGroupManager $groupManager,
private Folder $userFolder,
private IUserFolder $userFolder,
private IAppManager $appManager,
) {
}
Expand Down
10 changes: 4 additions & 6 deletions apps/dav/lib/Controller/DirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
Expand All @@ -33,7 +33,7 @@ class DirectController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private IRootFolder $rootFolder,
private IUserFolder $userFolder,
private string $userId,
private DirectMapper $mapper,
private ISecureRandom $random,
Expand Down Expand Up @@ -63,9 +63,7 @@ public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResp
throw new OCSForbiddenException('Creating direct links is disabled');
}

$userFolder = $this->rootFolder->getUserFolder($this->userId);

$file = $userFolder->getFirstNodeById($fileId);
$file = $this->userFolder->getFirstNodeById($fileId);

if (!$file) {
throw new OCSNotFoundException();
Expand All @@ -79,7 +77,7 @@ public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResp
throw new OCSBadRequestException('Direct download only works for files');
}

$event = new BeforeDirectFileDownloadEvent($userFolder->getRelativePath($file->getPath()));
$event = new BeforeDirectFileDownloadEvent($this->userFolder->getRelativePath($file->getPath()));
$this->eventDispatcher->dispatchTyped($event);

if ($event->isSuccessful() === false) {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/DAV/ViewOnlyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\DAV\Connector\Sabre\File as DavFile;
use OCA\Files_Versions\Sabre\VersionFile;
use OCP\Files\Folder;
use OCP\Files\IUserFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
use Sabre\DAV\Exception\NotFound;
Expand All @@ -27,7 +27,7 @@ class ViewOnlyPlugin extends ServerPlugin {
private ?Server $server = null;

public function __construct(
private ?Folder $userFolder,
private ?IUserFolder $userFolder,
) {
}

Expand Down
1 change: 0 additions & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ public function __construct(
)
);

// TODO: switch to LazyUserFolder
$shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
$this->server->addPlugin(new SharesPlugin(
$this->server->tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IFilenameValidator;
use OCP\Files\IUserFolder;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IPreview;
Expand Down Expand Up @@ -73,7 +74,7 @@ protected function setUp(): void {
->willReturn('http://example.com/owncloud/remote.php/dav');

$this->groupManager = $this->createMock(IGroupManager::class);
$this->userFolder = $this->createMock(Folder::class);
$this->userFolder = $this->createMock(IUserFolder::class);
$this->previewManager = $this->createMock(IPreview::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->tagManager = $this->createMock(ISystemTagManager::class);
Expand Down
37 changes: 8 additions & 29 deletions apps/dav/tests/unit/Controller/DirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand All @@ -30,7 +29,7 @@
use Test\TestCase;

class DirectControllerTest extends TestCase {
private IRootFolder&MockObject $rootFolder;
private IUserFolder&MockObject $userFolder;
private DirectMapper&MockObject $directMapper;
private ISecureRandom&MockObject $random;
private ITimeFactory&MockObject $timeFactory;
Expand All @@ -43,7 +42,7 @@ class DirectControllerTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->rootFolder = $this->createMock(IRootFolder::class);
$this->userFolder = $this->createMock(IUserFolder::class);
$this->directMapper = $this->createMock(DirectMapper::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
Expand All @@ -54,7 +53,7 @@ protected function setUp(): void {
$this->controller = new DirectController(
'dav',
$this->createMock(IRequest::class),
$this->rootFolder,
$this->userFolder,
'awesomeUser',
$this->directMapper,
$this->random,
Expand All @@ -69,12 +68,7 @@ public function testGetUrlNonExistingFileId(): void {
$this->shareManager->method('shareApiAllowLinks')
->willReturn(true);

$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);

$userFolder->method('getById')
$this->userFolder->method('getById')
->with(101)
->willReturn([]);

Expand All @@ -86,14 +80,9 @@ public function testGetUrlForFolder(): void {
$this->shareManager->method('shareApiAllowLinks')
->willReturn(true);

$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);

$folder = $this->createMock(Folder::class);

$userFolder->method('getFirstNodeById')
$this->userFolder->method('getFirstNodeById')
->with(101)
->willReturn($folder);

Expand All @@ -105,21 +94,16 @@ public function testGetUrlValid(): void {
$this->shareManager->method('shareApiAllowLinks')
->willReturn(true);

$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);

$file = $this->createMock(File::class);

$this->timeFactory->method('getTime')
->willReturn(42);

$userFolder->method('getFirstNodeById')
$this->userFolder->method('getFirstNodeById')
->with(101)
->willReturn($file);

$userFolder->method('getRelativePath')
$this->userFolder->method('getRelativePath')
->willReturn('/path');

$this->random->method('generate')
Expand Down Expand Up @@ -156,14 +140,9 @@ public function testGetUrlNoLinkShares(): void {
$this->shareManager->method('shareApiAllowLinks')
->willReturn(false);

$userFolder = $this->createMock(IUserFolder::class);
$this->rootFolder->method('getUserFolder')
->with('awesomeUser')
->willReturn($userFolder);

$file = $this->createMock(File::class);

$userFolder->method('getFirstNodeById')
$this->userFolder->method('getFirstNodeById')
->with(101)
->willReturn($file);

Expand Down
3 changes: 2 additions & 1 deletion apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCA\Files_Versions\Versions\IVersion;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IUserFolder;
use OCP\Files\Storage\ISharedStorage;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
Expand All @@ -36,7 +37,7 @@ class ViewOnlyPluginTest extends TestCase {
public function setUp(): void {
parent::setUp();

$this->userFolder = $this->createMock(Folder::class);
$this->userFolder = $this->createMock(IUserFolder::class);
$this->request = $this->createMock(RequestInterface::class);
$this->tree = $this->createMock(Tree::class);
$server = $this->createMock(Server::class);
Expand Down
7 changes: 3 additions & 4 deletions core/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\NotPermittedException;
use OCP\IAvatarManager;
use OCP\IL10N;
Expand All @@ -42,7 +42,7 @@ public function __construct(
protected IAvatarManager $avatarManager,
protected IL10N $l10n,
protected IUserManager $userManager,
protected IRootFolder $rootFolder,
protected ?IUserFolder $userFolder,
protected LoggerInterface $logger,
protected ?string $userId,
protected TimeFactory $timeFactory,
Expand Down Expand Up @@ -158,9 +158,8 @@ public function postAvatar(?string $path = null): JSONResponse {

if (isset($path)) {
$path = stripslashes($path);
$userFolder = $this->rootFolder->getUserFolder($this->userId);
/** @var File $node */
$node = $userFolder->get($path);
$node = $this->userFolder->get($path);
if (!($node instanceof File)) {
return new JSONResponse(['data' => ['message' => $this->l10n->t('Please select a file.')]]);
}
Expand Down
11 changes: 4 additions & 7 deletions core/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
Expand All @@ -34,8 +34,7 @@ public function __construct(
string $appName,
IRequest $request,
private IPreview $preview,
private IRootFolder $root,
private ?string $userId,
private ?IUserFolder $userFolder,
private IMimeIconProvider $mimeIconProvider,
) {
parent::__construct($appName, $request);
Expand Down Expand Up @@ -76,8 +75,7 @@ public function getPreview(
}

try {
$userFolder = $this->root->getUserFolder($this->userId);
$node = $userFolder->get($file);
$node = $this->userFolder->get($file);
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
Expand Down Expand Up @@ -119,8 +117,7 @@ public function getPreviewByFileId(
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

$userFolder = $this->root->getUserFolder($this->userId);
$node = $userFolder->getFirstNodeById($fileId);
$node = $this->userFolder->getFirstNodeById($fileId);

if (!$node) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
Expand Down
10 changes: 0 additions & 10 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
use OCP\Group\ISubAdmin;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -106,14 +104,6 @@ public function __construct(
/* Cannot be an alias because Output is not in OCA */
$this->registerService(IOutput::class, fn (ContainerInterface $c): IOutput => new Output($c->get('webRoot')));

$this->registerService(Folder::class, function () {
$user = $this->get(IUserSession::class)->getUser();
if ($user === null) {
return null;
}
return $this->getServer()->get(IRootFolder::class)->getUserFolder($user->getUID());
});

$this->registerService(IAppData::class, function (ContainerInterface $c): IAppData {
return $c->get(IAppDataFactory::class)->get($c->get('appName'));
});
Expand Down
Loading
Loading