diff options
-rw-r--r-- | core/Controller/NavigationController.php | 30 | ||||
-rw-r--r-- | core/routes.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/NavigationControllerTest.php | 10 |
3 files changed, 23 insertions, 21 deletions
diff --git a/core/Controller/NavigationController.php b/core/Controller/NavigationController.php index 98744171198..92f103c3a34 100644 --- a/core/Controller/NavigationController.php +++ b/core/Controller/NavigationController.php @@ -22,13 +22,13 @@ */ namespace OC\Core\Controller; -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; -class NavigationController extends Controller { +class NavigationController extends OCSController { /** @var INavigationManager */ private $navigationManager; @@ -47,14 +47,14 @@ class NavigationController extends Controller { * @NoCSRFRequired * * @param bool $absolute - * @return JSONResponse + * @return DataResponse */ - public function getAppsNavigation(bool $absolute = false) { - $navigation = $this->navigationManager->getAll('link'); + public function getAppsNavigation(bool $absolute = false): DataResponse { + $navigation = $this->navigationManager->getAll(); if ($absolute) { - $this->rewriteToAbsoluteUrls($navigation); + $navigation = $this->rewriteToAbsoluteUrls($navigation); } - return new JSONResponse($navigation); + return new DataResponse($navigation); } /** @@ -62,26 +62,28 @@ class NavigationController extends Controller { * @NoCSRFRequired * * @param bool $absolute - * @return JSONResponse + * @return DataResponse */ - public function getSettingsNavigation(bool $absolute = false) { + public function getSettingsNavigation(bool $absolute = false): DataResponse { $navigation = $this->navigationManager->getAll('settings'); if ($absolute) { - $this->rewriteToAbsoluteUrls($navigation); + $navigation = $this->rewriteToAbsoluteUrls($navigation); } - return new JSONResponse($navigation); + return new DataResponse($navigation); } /** * Rewrite href attribute of navigation entries to an absolute URL * * @param array $navigation + * @return array */ - private function rewriteToAbsoluteUrls(array &$navigation) { + private function rewriteToAbsoluteUrls(array $navigation): array { foreach ($navigation as &$entry) { - if (substr($entry['href'], 0, strlen($this->urlGenerator->getBaseUrl())) !== $this->urlGenerator->getBaseUrl()) { + if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) { $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']); } } + return $navigation; } } diff --git a/core/routes.php b/core/routes.php index 5fc58cbdfc0..97a8621fc39 100644 --- a/core/routes.php +++ b/core/routes.php @@ -59,8 +59,6 @@ $application->registerRoutes($this, [ ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], - ['name' => 'Navigation#getAppsNavigation', 'url' => '/core/navigation/apps', 'verb' => 'GET'], - ['name' => 'Navigation#getSettingsNavigation', 'url' => '/core/navigation/settings', 'verb' => 'GET'], ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], @@ -73,6 +71,8 @@ $application->registerRoutes($this, [ ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], + ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], + ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], ], ]); diff --git a/tests/Core/Controller/NavigationControllerTest.php b/tests/Core/Controller/NavigationControllerTest.php index 3a745b48678..9b1d33ab868 100644 --- a/tests/Core/Controller/NavigationControllerTest.php +++ b/tests/Core/Controller/NavigationControllerTest.php @@ -23,7 +23,7 @@ namespace Tests\Core\Controller; use OC\Core\Controller\NavigationController; -use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\DataResponse; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; @@ -78,11 +78,11 @@ class NavigationControllerTest extends TestCase { ->with('/index.php/apps/files') ->willReturn('http://localhost/index.php/apps/files'); $actual = $this->controller->getAppsNavigation($absolute); - $this->assertInstanceOf(JSONResponse::class, $actual); + $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']); } else { $actual = $this->controller->getAppsNavigation($absolute); - $this->assertInstanceOf(JSONResponse::class, $actual); + $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('/index.php/apps/files', $actual->getData()[0]['href']); } } @@ -102,11 +102,11 @@ class NavigationControllerTest extends TestCase { ->with('/index.php/settings/user') ->willReturn('http://localhost/index.php/settings/user'); $actual = $this->controller->getSettingsNavigation($absolute); - $this->assertInstanceOf(JSONResponse::class, $actual); + $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']); } else { $actual = $this->controller->getSettingsNavigation($absolute); - $this->assertInstanceOf(JSONResponse::class, $actual); + $this->assertInstanceOf(DataResponse::class, $actual); $this->assertEquals('/index.php/settings/user', $actual->getData()[0]['href']); } } |