Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup files sidebar navigation manager #26320

Closed
wants to merge 4 commits into from
Closed
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
20 changes: 10 additions & 10 deletions apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand All @@ -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',
],
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 4 additions & 20 deletions apps/files/lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,14 @@
namespace OCA\Files;

class App {
/**
* @var \OCP\INavigationManager
*/
private static $navigationManager;

/**
* Returns the app's navigation manager
*
* @return \OCP\INavigationManager
* @return SidebarNavigationManager
* @deprecated query OCA\Files\SidebarNavigationManager from a container instead
*/
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(): SidebarNavigationManager {
return \OC::$server->get(SidebarNavigationManager::class);
}

public static function extendJsConfig($settings) {
Expand Down
33 changes: 5 additions & 28 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@
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;
use OCA\Files\Listener\LoadSidebarListener;
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;
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;

Expand All @@ -74,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
*/
Expand Down Expand Up @@ -149,8 +126,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',
Expand All @@ -159,7 +136,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',
Expand All @@ -168,7 +145,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',
Expand Down
34 changes: 21 additions & 13 deletions apps/files/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
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;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -47,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;
Expand All @@ -73,32 +76,37 @@ class ApiController extends Controller {
private $config;
/** @var Folder */
private $userFolder;
/** @var SidebarNavigationManager */
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) {
parent::__construct($appName, $request);
public function __construct(
IRequest $request,
IUserSession $userSession,
TagService $tagService,
IPreview $previewManager,
IManager $shareManager,
IConfig $config,
IRootFolder $rootFolder,
SidebarNavigationManager $navigationManager
) {
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;
}

/**
Expand Down Expand Up @@ -331,7 +339,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']) {
Expand Down
9 changes: 7 additions & 2 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -113,6 +117,7 @@ public function __construct(string $appName,
$this->activityHelper = $activityHelper;
$this->initialState = $initialState;
$this->templateManager = $templateManager;
$this->navigationManager = $navigationManager;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions apps/files/lib/SidebarNavigationManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files;

use OC\NavigationManager;

class SidebarNavigationManager extends NavigationManager {
protected function init() {
// don't load the normal navigation items
}
}
4 changes: 3 additions & 1 deletion apps/files_external/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
*/

use OCA\Files\SidebarNavigationManager;
use OCA\Files_External\Config\ConfigAdapter;

require_once __DIR__ . '/../3rdparty/autoload.php';
Expand All @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
namespace OCA\Files_Sharing\AppInfo;

use OC\AppFramework\Utility\SimpleContainer;
use OCA\Files\SidebarNavigationManager;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristophWurst @rullzer We should move this to the OCP namespace, or? A way to hook into the files app sidebar. Or should we say "it's fine, because files app is force enabled anyways"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be OCP ideally because otherwise we can never set any clear boundaries between public and private API

use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Files_Sharing\External\Manager;
Expand Down Expand Up @@ -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 = [];
Expand Down
Loading