Move to OCS endpoint

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-02-01 12:18:24 +01:00
parent 8ecac56543
commit 922cf44c81
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
3 changed files with 23 additions and 21 deletions

View file

@ -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;
}
}

View file

@ -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'],
],
]);

View file

@ -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']);
}
}