Skip to content

Commit 922cf44

Browse files
committed
Move to OCS endpoint
Signed-off-by: Julius Härtl <[email protected]>
1 parent 8ecac56 commit 922cf44

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

core/Controller/NavigationController.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
*/
2323
namespace OC\Core\Controller;
2424

25-
use OCP\AppFramework\Controller;
26-
use OCP\AppFramework\Http\JSONResponse;
25+
use OCP\AppFramework\Http\DataResponse;
26+
use OCP\AppFramework\OCSController;
2727
use OCP\INavigationManager;
2828
use OCP\IRequest;
2929
use OCP\IURLGenerator;
3030

31-
class NavigationController extends Controller {
31+
class NavigationController extends OCSController {
3232

3333
/** @var INavigationManager */
3434
private $navigationManager;
@@ -47,41 +47,43 @@ public function __construct(string $appName, IRequest $request, INavigationManag
4747
* @NoCSRFRequired
4848
*
4949
* @param bool $absolute
50-
* @return JSONResponse
50+
* @return DataResponse
5151
*/
52-
public function getAppsNavigation(bool $absolute = false) {
53-
$navigation = $this->navigationManager->getAll('link');
52+
public function getAppsNavigation(bool $absolute = false): DataResponse {
53+
$navigation = $this->navigationManager->getAll();
5454
if ($absolute) {
55-
$this->rewriteToAbsoluteUrls($navigation);
55+
$navigation = $this->rewriteToAbsoluteUrls($navigation);
5656
}
57-
return new JSONResponse($navigation);
57+
return new DataResponse($navigation);
5858
}
5959

6060
/**
6161
* @NoAdminRequired
6262
* @NoCSRFRequired
6363
*
6464
* @param bool $absolute
65-
* @return JSONResponse
65+
* @return DataResponse
6666
*/
67-
public function getSettingsNavigation(bool $absolute = false) {
67+
public function getSettingsNavigation(bool $absolute = false): DataResponse {
6868
$navigation = $this->navigationManager->getAll('settings');
6969
if ($absolute) {
70-
$this->rewriteToAbsoluteUrls($navigation);
70+
$navigation = $this->rewriteToAbsoluteUrls($navigation);
7171
}
72-
return new JSONResponse($navigation);
72+
return new DataResponse($navigation);
7373
}
7474

7575
/**
7676
* Rewrite href attribute of navigation entries to an absolute URL
7777
*
7878
* @param array $navigation
79+
* @return array
7980
*/
80-
private function rewriteToAbsoluteUrls(array &$navigation) {
81+
private function rewriteToAbsoluteUrls(array $navigation): array {
8182
foreach ($navigation as &$entry) {
82-
if (substr($entry['href'], 0, strlen($this->urlGenerator->getBaseUrl())) !== $this->urlGenerator->getBaseUrl()) {
83+
if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
8384
$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
8485
}
8586
}
87+
return $navigation;
8688
}
8789
}

core/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
6060
['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
6161
['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
62-
['name' => 'Navigation#getAppsNavigation', 'url' => '/core/navigation/apps', 'verb' => 'GET'],
63-
['name' => 'Navigation#getSettingsNavigation', 'url' => '/core/navigation/settings', 'verb' => 'GET'],
6462
['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
6563
['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
6664
['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
@@ -73,6 +71,8 @@
7371
['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
7472
['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
7573
['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
74+
['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
75+
['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
7676
],
7777
]);
7878

tests/Core/Controller/NavigationControllerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace Tests\Core\Controller;
2424

2525
use OC\Core\Controller\NavigationController;
26-
use OCP\AppFramework\Http\JSONResponse;
26+
use OCP\AppFramework\Http\DataResponse;
2727
use OCP\INavigationManager;
2828
use OCP\IRequest;
2929
use OCP\IURLGenerator;
@@ -78,11 +78,11 @@ public function testGetAppNavigation($absolute) {
7878
->with('/index.php/apps/files')
7979
->willReturn('http://localhost/index.php/apps/files');
8080
$actual = $this->controller->getAppsNavigation($absolute);
81-
$this->assertInstanceOf(JSONResponse::class, $actual);
81+
$this->assertInstanceOf(DataResponse::class, $actual);
8282
$this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']);
8383
} else {
8484
$actual = $this->controller->getAppsNavigation($absolute);
85-
$this->assertInstanceOf(JSONResponse::class, $actual);
85+
$this->assertInstanceOf(DataResponse::class, $actual);
8686
$this->assertEquals('/index.php/apps/files', $actual->getData()[0]['href']);
8787
}
8888
}
@@ -102,11 +102,11 @@ public function testGetSettingsNavigation($absolute) {
102102
->with('/index.php/settings/user')
103103
->willReturn('http://localhost/index.php/settings/user');
104104
$actual = $this->controller->getSettingsNavigation($absolute);
105-
$this->assertInstanceOf(JSONResponse::class, $actual);
105+
$this->assertInstanceOf(DataResponse::class, $actual);
106106
$this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']);
107107
} else {
108108
$actual = $this->controller->getSettingsNavigation($absolute);
109-
$this->assertInstanceOf(JSONResponse::class, $actual);
109+
$this->assertInstanceOf(DataResponse::class, $actual);
110110
$this->assertEquals('/index.php/settings/user', $actual->getData()[0]['href']);
111111
}
112112
}

0 commit comments

Comments
 (0)