diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index ca05d506993..ae58e9b73f1 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -14,7 +14,6 @@ use OCA\Files\Capabilities; use OCA\Files\Collaboration\Resources\Listener; use OCA\Files\Collaboration\Resources\ResourceProvider; use OCA\Files\ConfigLexicon; -use OCA\Files\Controller\ApiController; use OCA\Files\Dashboard\FavoriteWidget; use OCA\Files\DirectEditingCapabilities; use OCA\Files\Event\LoadSearchPlugins; @@ -29,8 +28,6 @@ use OCA\Files\Listener\UserFirstTimeLoggedInListener; use OCA\Files\Notification\Notifier; use OCA\Files\Search\FilesSearchProvider; use OCA\Files\Service\TagService; -use OCA\Files\Service\UserConfig; -use OCA\Files\Service\ViewConfig; use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -45,19 +42,12 @@ use OCP\Files\Events\Node\BeforeNodeRenamedEvent; use OCP\Files\Events\Node\NodeCopiedEvent; use OCP\Files\Events\NodeAddedToFavorite; use OCP\Files\Events\NodeRemovedFromFavorite; -use OCP\Files\IRootFolder; -use OCP\IConfig; -use OCP\IL10N; -use OCP\IPreview; -use OCP\IRequest; use OCP\IServerContainer; use OCP\ITagManager; use OCP\IUserSession; -use OCP\Share\IManager as IShareManager; use OCP\User\Events\UserFirstTimeLoggedInEvent; use OCP\Util; use Psr\Container\ContainerInterface; -use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { public const APP_ID = 'files'; @@ -68,30 +58,6 @@ class Application extends App implements IBootstrap { #[\Override] public function register(IRegistrationContext $context): void { - /** - * Controllers - */ - $context->registerService('APIController', function (ContainerInterface $c) { - /** @var IServerContainer $server */ - $server = $c->get(IServerContainer::class); - - return new ApiController( - $c->get('AppName'), - $c->get(IRequest::class), - $c->get(IUserSession::class), - $c->get(TagService::class), - $c->get(IPreview::class), - $c->get(IShareManager::class), - $c->get(IConfig::class), - $server->getUserFolder(), - $c->get(UserConfig::class), - $c->get(ViewConfig::class), - $c->get(IL10N::class), - $c->get(IRootFolder::class), - $c->get(LoggerInterface::class), - ); - }); - /** * Services */ diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 03c4bcf49a7..20eb7dba5de 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -53,6 +53,8 @@ use Throwable; * @package OCA\Files\Controller */ class ApiController extends Controller { + private ?Folder $userFolder = null; + public function __construct( string $appName, IRequest $request, @@ -61,7 +63,6 @@ class ApiController extends Controller { private IPreview $previewManager, private IManager $shareManager, private IConfig $config, - private ?Folder $userFolder, private UserConfig $userConfig, private ViewConfig $viewConfig, private IL10N $l10n, @@ -69,6 +70,10 @@ class ApiController extends Controller { private LoggerInterface $logger, ) { parent::__construct($appName, $request); + $user = $this->userSession->getUser(); + if ($user) { + $this->userFolder = $this->rootFolder->getUserFolder($user->getUID()); + } } /** diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php index 12b584fc56d..1bc0af3de50 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -77,6 +77,9 @@ class ApiControllerTest extends TestCase { $this->viewConfig = $this->createMock(ViewConfig::class); $this->l10n = $this->createMock(IL10N::class); $this->rootFolder = $this->createMock(IRootFolder::class); + $this->rootFolder->expects($this->any()) + ->method('getUserFolder') + ->willReturn($this->userFolder); $this->logger = $this->createMock(LoggerInterface::class); $this->apiController = new ApiController( @@ -87,7 +90,6 @@ class ApiControllerTest extends TestCase { $this->preview, $this->shareManager, $this->config, - $this->userFolder, $this->userConfig, $this->viewConfig, $this->l10n,