From 71b61e90012d7614a663801c14e78e047fd7833c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Mar 2021 15:35:51 +0100 Subject: [PATCH 1/4] move files sidebar navigation manager into it's own service Signed-off-by: Robin Appelman --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/files/lib/App.php | 25 +++------------ apps/files/lib/SidebarNavigationManager.php | 32 +++++++++++++++++++ lib/private/NavigationManager.php | 2 +- 5 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 apps/files/lib/SidebarNavigationManager.php diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index bc2e496294b4e..87a7fa3672bdb 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -53,4 +53,5 @@ 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php', 'OCA\\Files\\Settings\\PersonalSettings' => $baseDir . '/../lib/Settings/PersonalSettings.php', + 'OCA\\Files\\SidebarNavigationManager' => $baseDir . '/../lib/SidebarNavigationManager.php', ); diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index ba39b2c57073a..5a1c1943ebc5e 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -68,6 +68,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php', 'OCA\\Files\\Settings\\PersonalSettings' => __DIR__ . '/..' . '/../lib/Settings/PersonalSettings.php', + 'OCA\\Files\\SidebarNavigationManager' => __DIR__ . '/..' . '/../lib/SidebarNavigationManager.php', ); public static function getInitializer(ClassLoader $loader) diff --git a/apps/files/lib/App.php b/apps/files/lib/App.php index 9bb50d6f9ab66..22cb223687ead 100644 --- a/apps/files/lib/App.php +++ b/apps/files/lib/App.php @@ -25,31 +25,16 @@ namespace OCA\Files; -class App { - /** - * @var \OCP\INavigationManager - */ - private static $navigationManager; +use OCP\INavigationManager; +class App { /** * Returns the app's navigation manager * - * @return \OCP\INavigationManager + * @return INavigationManager */ - public static function getNavigationManager() { - // TODO: move this into a service in the Application class - if (self::$navigationManager === null) { - self::$navigationManager = new \OC\NavigationManager( - \OC::$server->getAppManager(), - \OC::$server->getURLGenerator(), - \OC::$server->getL10NFactory(), - \OC::$server->getUserSession(), - \OC::$server->getGroupManager(), - \OC::$server->getConfig() - ); - self::$navigationManager->clear(false); - } - return self::$navigationManager; + public static function getNavigationManager(): INavigationManager { + return \OC::$server->get(SidebarNavigationManager::class); } public static function extendJsConfig($settings) { diff --git a/apps/files/lib/SidebarNavigationManager.php b/apps/files/lib/SidebarNavigationManager.php new file mode 100644 index 0000000000000..2c0cb59ad494e --- /dev/null +++ b/apps/files/lib/SidebarNavigationManager.php @@ -0,0 +1,32 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files; + +use OC\NavigationManager; + +class SidebarNavigationManager extends NavigationManager { + protected function init() { + // don't load the normal navigation items + } +} diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index e250523b98ff5..a068da5fb48ba 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -177,7 +177,7 @@ public function getActiveEntry() { return $this->activeEntry; } - private function init() { + protected function init() { if ($this->init) { return; } From 92fd92d0798ef97694e617aab21056a14be3618a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Mar 2021 15:37:22 +0100 Subject: [PATCH 2/4] depricate OCA\Files\App::getNavigationManager now it can be queried Signed-off-by: Robin Appelman --- apps/files/lib/App.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/files/lib/App.php b/apps/files/lib/App.php index 22cb223687ead..c0ef197af9daf 100644 --- a/apps/files/lib/App.php +++ b/apps/files/lib/App.php @@ -25,15 +25,14 @@ namespace OCA\Files; -use OCP\INavigationManager; - class App { /** * Returns the app's navigation manager * - * @return INavigationManager + * @return SidebarNavigationManager + * @deprecated query OCA\Files\SidebarNavigationManager from a container instead */ - public static function getNavigationManager(): INavigationManager { + public static function getNavigationManager(): SidebarNavigationManager { return \OC::$server->get(SidebarNavigationManager::class); } From 1aa103ef6945487b8c7118102b508760dd2d314d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Mar 2021 15:44:57 +0100 Subject: [PATCH 3/4] remove usages of deprecated OCA\Files\App::getNavigationManager Signed-off-by: Robin Appelman --- apps/files/lib/AppInfo/Application.php | 9 ++++--- apps/files/lib/Controller/ApiController.php | 25 ++++++++++++------- apps/files/lib/Controller/ViewController.php | 9 +++++-- apps/files_external/appinfo/app.php | 4 ++- .../files_sharing/lib/AppInfo/Application.php | 6 +++-- .../lib/AppInfo/Application.php | 23 +++++++++-------- apps/systemtags/lib/AppInfo/Application.php | 21 +++++++++------- 7 files changed, 60 insertions(+), 37 deletions(-) diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 92f29bfe410ad..e2f79a0a42c39 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -47,6 +47,7 @@ use OCA\Files\Notification\Notifier; use OCA\Files\Search\FilesSearchProvider; use OCA\Files\Service\TagService; +use OCA\Files\SidebarNavigationManager; use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -149,8 +150,8 @@ private function registerTemplates(): void { $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); } - private function registerNavigation(IL10N $l10n): void { - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + private function registerNavigation(IL10N $l10n, SidebarNavigationManager $navigation): void { + $navigation->add(function () use ($l10n) { return [ 'id' => 'files', 'appname' => 'files', @@ -159,7 +160,7 @@ private function registerNavigation(IL10N $l10n): void { 'name' => $l10n->t('All files') ]; }); - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + $navigation->add(function () use ($l10n) { return [ 'id' => 'recent', 'appname' => 'files', @@ -168,7 +169,7 @@ private function registerNavigation(IL10N $l10n): void { 'name' => $l10n->t('Recent') ]; }); - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + $navigation->add(function () use ($l10n) { return [ 'id' => 'favorites', 'appname' => 'files', diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 0cf261af72678..d2d5d40ec3f0e 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -39,6 +39,7 @@ use OC\Files\Node\Node; use OCA\Files\Service\TagService; +use OCA\Files\SidebarNavigationManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -73,6 +74,8 @@ class ApiController extends Controller { private $config; /** @var Folder */ private $userFolder; + /** @var SidebarNavigationManager */ + private $navigationManager; /** * @param string $appName @@ -84,14 +87,17 @@ class ApiController extends Controller { * @param IConfig $config * @param Folder $userFolder */ - public function __construct($appName, - IRequest $request, - IUserSession $userSession, - TagService $tagService, - IPreview $previewManager, - IManager $shareManager, - IConfig $config, - Folder $userFolder) { + public function __construct( + $appName, + IRequest $request, + IUserSession $userSession, + TagService $tagService, + IPreview $previewManager, + IManager $shareManager, + IConfig $config, + Folder $userFolder, + SidebarNavigationManager $navigationManager + ) { parent::__construct($appName, $request); $this->userSession = $userSession; $this->tagService = $tagService; @@ -99,6 +105,7 @@ public function __construct($appName, $this->shareManager = $shareManager; $this->config = $config; $this->userFolder = $userFolder; + $this->navigationManager = $navigationManager; } /** @@ -331,7 +338,7 @@ public function getGridView() { */ public function toggleShowFolder(int $show, string $key) { // ensure the edited key exists - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); + $navItems = $this->navigationManager->getAll(); foreach ($navItems as $item) { // check if data is valid if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index efaf2dc602f0e..8b0381592b5c1 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -37,6 +37,7 @@ use OCA\Files\Activity\Helper; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSidebar; +use OCA\Files\SidebarNavigationManager; use OCA\Viewer\Event\LoadViewer; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -86,6 +87,8 @@ class ViewController extends Controller { private $initialState; /** @var ITemplateManager */ private $templateManager; + /** @var SidebarNavigationManager */ + private $navigationManager; public function __construct(string $appName, IRequest $request, @@ -98,7 +101,8 @@ public function __construct(string $appName, IRootFolder $rootFolder, Helper $activityHelper, IInitialState $initialState, - ITemplateManager $templateManager + ITemplateManager $templateManager, + SidebarNavigationManager $navigationManager ) { parent::__construct($appName, $request); $this->appName = $appName; @@ -113,6 +117,7 @@ public function __construct(string $appName, $this->activityHelper = $activityHelper; $this->initialState = $initialState; $this->templateManager = $templateManager; + $this->navigationManager = $navigationManager; } /** @@ -233,7 +238,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $navBarPositionPosition++; } - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); + $navItems = $this->navigationManager->getAll(); // add the favorites entry in menu $navItems['favorites']['sublist'] = $favoritesSublistArray; diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index f8f7d377bc717..c1f7b275d034d 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -26,6 +26,7 @@ * */ +use OCA\Files\SidebarNavigationManager; use OCA\Files_External\Config\ConfigAdapter; require_once __DIR__ . '/../3rdparty/autoload.php'; @@ -36,7 +37,8 @@ $appContainer = \OCA\Files_External\MountConfig::$app->getContainer(); -\OCA\Files\App::getNavigationManager()->add(function () { +$navigationManager = $appContainer->get(SidebarNavigationManager::class); +$navigationManager->add(function () { $l = \OC::$server->getL10N('files_external'); return [ 'id' => 'extstoragemounts', diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 078a0a5f59dee..087cf545f8800 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -31,6 +31,7 @@ namespace OCA\Files_Sharing\AppInfo; use OC\AppFramework\Utility\SimpleContainer; +use OCA\Files\SidebarNavigationManager; use OCA\Files_Sharing\Capabilities; use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Files_Sharing\External\Manager; @@ -172,9 +173,10 @@ protected function setupSharingMenus() { return; } + /** @var SidebarNavigationManager $navigationManager */ + $navigationManager = $this->getContainer()->get(SidebarNavigationManager::class); // show_Quick_Access stored as string - \OCA\Files\App::getNavigationManager()->add(function () { - $config = \OC::$server->getConfig(); + $navigationManager->add(function () use ($config) { $l = \OC::$server->getL10N('files_sharing'); $sharingSublistArray = []; diff --git a/apps/files_trashbin/lib/AppInfo/Application.php b/apps/files_trashbin/lib/AppInfo/Application.php index a14b49ba77b02..c680b6e0c6622 100644 --- a/apps/files_trashbin/lib/AppInfo/Application.php +++ b/apps/files_trashbin/lib/AppInfo/Application.php @@ -27,6 +27,7 @@ namespace OCA\Files_Trashbin\AppInfo; use OCA\DAV\Connector\Sabre\Principal; +use OCA\Files\SidebarNavigationManager; use OCA\Files_Trashbin\Capabilities; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Trash\ITrashManager; @@ -65,16 +66,18 @@ public function boot(IBootContext $context): void { // pre and post-rename, disable trash logic for the copy+unlink case \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_trashbin'); - return [ - 'id' => 'trashbin', - 'appname' => 'files_trashbin', - 'script' => 'list.php', - 'order' => 50, - 'name' => $l->t('Deleted files'), - 'classes' => 'pinned', - ]; + $context->injectFn(function (SidebarNavigationManager $navigationManager) { + $navigationManager->add(function () { + $l = \OC::$server->getL10N('files_trashbin'); + return [ + 'id' => 'trashbin', + 'appname' => 'files_trashbin', + 'script' => 'list.php', + 'order' => 50, + 'name' => $l->t('Deleted files'), + 'classes' => 'pinned', + ]; + }); }); } diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php index 15f2a6e698958..5e72a10b5a35a 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -26,6 +26,7 @@ namespace OCA\SystemTags\AppInfo; +use OCA\Files\SidebarNavigationManager; use OCA\SystemTags\Activity\Listener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -77,15 +78,17 @@ function () { $dispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); }); - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N(self::APP_ID); - return [ - 'id' => 'systemtagsfilter', - 'appname' => self::APP_ID, - 'script' => 'list.php', - 'order' => 25, - 'name' => $l->t('Tags'), - ]; + $context->injectFn(function (SidebarNavigationManager $navigationManager) { + $navigationManager->add(function () { + $l = \OC::$server->getL10N(self::APP_ID); + return [ + 'id' => 'systemtagsfilter', + 'appname' => self::APP_ID, + 'script' => 'list.php', + 'order' => 25, + 'name' => $l->t('Tags'), + ]; + }); }); } } From f6be7a4be5872b09b92606d4cd48fdfeacb10b80 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Mar 2021 16:02:36 +0100 Subject: [PATCH 4/4] fix api controller contstruction and routes Signed-off-by: Robin Appelman --- apps/files/appinfo/routes.php | 20 ++++++++--------- apps/files/lib/AppInfo/Application.php | 24 --------------------- apps/files/lib/Controller/ApiController.php | 13 +++++------ 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 03a025cadf5e3..b286328f36921 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -50,44 +50,44 @@ ], [ - 'name' => 'API#getThumbnail', + 'name' => 'Api#getThumbnail', 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', 'verb' => 'GET', 'requirements' => ['file' => '.+'] ], [ - 'name' => 'API#updateFileTags', + 'name' => 'Api#updateFileTags', 'url' => '/api/v1/files/{path}', 'verb' => 'POST', 'requirements' => ['path' => '.+'], ], [ - 'name' => 'API#getRecentFiles', + 'name' => 'Api#getRecentFiles', 'url' => '/api/v1/recent/', 'verb' => 'GET' ], [ - 'name' => 'API#updateFileSorting', + 'name' => 'Api#updateFileSorting', 'url' => '/api/v1/sorting', 'verb' => 'POST' ], [ - 'name' => 'API#showHiddenFiles', + 'name' => 'Api#showHiddenFiles', 'url' => '/api/v1/showhidden', 'verb' => 'POST' ], [ - 'name' => 'API#cropImagePreviews', + 'name' => 'Api#cropImagePreviews', 'url' => '/api/v1/cropimagepreviews', 'verb' => 'POST' ], [ - 'name' => 'API#showGridView', + 'name' => 'Api#showGridView', 'url' => '/api/v1/showgridview', 'verb' => 'POST' ], [ - 'name' => 'API#getGridView', + 'name' => 'Api#getGridView', 'url' => '/api/v1/showgridview', 'verb' => 'GET' ], @@ -102,12 +102,12 @@ 'verb' => 'GET', ], [ - 'name' => 'API#toggleShowFolder', + 'name' => 'Api#toggleShowFolder', 'url' => '/api/v1/toggleShowFolder/{key}', 'verb' => 'POST' ], [ - 'name' => 'API#getNodeType', + 'name' => 'Api#getNodeType', 'url' => '/api/v1/quickaccess/get/NodeType', 'verb' => 'GET', ], diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index e2f79a0a42c39..e0e2ce825a89c 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -39,7 +39,6 @@ use OCA\Files\Capabilities; use OCA\Files\Collaboration\Resources\Listener; use OCA\Files\Collaboration\Resources\ResourceProvider; -use OCA\Files\Controller\ApiController; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSidebar; use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter; @@ -54,16 +53,12 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Collaboration\Resources\IProviderManager; -use OCP\IConfig; use OCP\IL10N; -use OCP\IPreview; use OCP\ISearch; -use OCP\IRequest; use OCP\IServerContainer; use OCP\ITagManager; use OCP\IUserSession; use OCP\Notification\IManager; -use OCP\Share\IManager as IShareManager; use OCP\Util; use Psr\Container\ContainerInterface; @@ -75,25 +70,6 @@ public function __construct(array $urlParams = []) { } 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() - ); - }); - /** * Services */ diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index d2d5d40ec3f0e..3064b68b1844a 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -38,6 +38,7 @@ namespace OCA\Files\Controller; use OC\Files\Node\Node; +use OCA\Files\AppInfo\Application; use OCA\Files\Service\TagService; use OCA\Files\SidebarNavigationManager; use OCP\AppFramework\Controller; @@ -48,6 +49,7 @@ use OCP\AppFramework\Http\Response; use OCP\Files\File; use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IPreview; @@ -78,33 +80,32 @@ class ApiController extends Controller { private $navigationManager; /** - * @param string $appName * @param IRequest $request * @param IUserSession $userSession * @param TagService $tagService * @param IPreview $previewManager * @param IManager $shareManager * @param IConfig $config - * @param Folder $userFolder + * @param IRootFolder $rootFolder + * @param SidebarNavigationManager $navigationManager */ public function __construct( - $appName, IRequest $request, IUserSession $userSession, TagService $tagService, IPreview $previewManager, IManager $shareManager, IConfig $config, - Folder $userFolder, + IRootFolder $rootFolder, SidebarNavigationManager $navigationManager ) { - parent::__construct($appName, $request); + parent::__construct(Application::APP_ID, $request); $this->userSession = $userSession; $this->tagService = $tagService; $this->previewManager = $previewManager; $this->shareManager = $shareManager; $this->config = $config; - $this->userFolder = $userFolder; + $this->userFolder = $rootFolder->getUserFolder($userSession->getUser()->getUID()); $this->navigationManager = $navigationManager; }