Skip to content

Expose navigation entries as API endpoint - #8095

Merged
MorrisJobke merged 11 commits into
masterfrom
webapps-capabilities
Feb 15, 2018
Merged

MorrisJobke merged 11 commits into
masterfrom
webapps-capabilities

Conversation

@juliusknorr

Copy link
Copy Markdown
Member

This PR adds new endpoints to get the navigation entries for the app and settings menu, as discussed in #7893. This will make it possible for clients to fetch the list of available "web apps" but also use this in apps management to update the app menu when installing/uninstalling an app. I'll do that in a separate PR once this is merged.

@camilasan

Example request: apps
$ curl http://admin:admin@localhost:8140/index.php/core/navigation/apps 
[
  {
    "id": "files",
    "order": "0",
    "href": "/index.php/apps/files/",
    "icon": "/apps/files/img/app.svg",
    "type": "link",
    "name": "Dateien",
    "active": false,
    "classes": ""
  },
  {
    "id": "activity",
    "order": "1",
    "href": "/index.php/apps/activity/",
    "icon": "/apps/activity/img/activity.svg",
    "type": "link",
    "name": "Aktivität",
    "active": false,
    "classes": ""
  },
  {
    "id": "gallery",
    "order": 2,
    "href": "/index.php/apps/gallery/",
    "icon": "/apps/gallery/img/app.svg",
    "name": "Galerie",
    "active": false,
    "classes": "",
    "type": "link"
  },
  {
    "id": "deck",
    "order": 10,
    "href": "/index.php/apps/deck/",
    "icon": "/apps-extra/deck/img/deck.svg",
    "name": "Deck",
    "active": false,
    "classes": "",
    "type": "link"
  }
]

@rullzer

rullzer commented Jan 29, 2018

Copy link
Copy Markdown
Member

Any reason not to expose this in the capabilities?

@juliusknorr

Copy link
Copy Markdown
Member Author

Quoting @nickvergessen from #7893, and I think it makes sense to have a separate endpoint which can also be used for the apps management as well.

Not abuse the capabilities even more

use OCP\IRequest;
use OCP\IURLGenerator;

class NavigationController extends Controller {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use OCSController please

if ($absolute) {
$this->rewriteToAbsoluteUrls($navigation);
}
return new JSONResponse($navigation);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return new DataResponse($navigation);

if ($absolute) {
$this->rewriteToAbsoluteUrls($navigation);
}
return new JSONResponse($navigation);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return new DataResponse($navigation);

*
* @param array $navigation
*/
private function rewriteToAbsoluteUrls(array &$navigation) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer return over by-reference

Comment thread core/routes.php Outdated
['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'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be OCS routes, everything else is not to be used by clients

@juliusknorr juliusknorr added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jan 29, 2018
@codecov

codecov Bot commented Feb 1, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #8095 into master will increase coverage by 0.08%.
The diff coverage is 72.34%.

@@             Coverage Diff              @@
##             master    #8095      +/-   ##
============================================
+ Coverage     51.69%   51.78%   +0.08%     
- Complexity    25386    25395       +9     
============================================
  Files          1599     1600       +1     
  Lines         95109    95130      +21     
  Branches       1376     1376              
============================================
+ Hits          49163    49259      +96     
+ Misses        45946    45871      -75
Impacted Files Coverage Δ Complexity Δ
core/routes.php 0% <ø> (ø) 0 <0> (ø) ⬇️
lib/private/TemplateLayout.php 0% <0%> (ø) 48 <0> (ø) ⬇️
lib/private/legacy/app.php 57.86% <0%> (+1.95%) 199 <0> (-8) ⬇️
settings/ajax/navigationdetect.php 0% <0%> (ø) 0 <0> (ø) ⬇️
core/Controller/NavigationController.php 100% <100%> (ø) 9 <9> (?)
lib/private/NavigationManager.php 77.55% <61.9%> (-1.84%) 51 <12> (+8)
lib/private/Files/ObjectStore/Swift.php 49.61% <0%> (+49.61%) 45% <0%> (ø) ⬇️

@juliusknorr

Copy link
Copy Markdown
Member Author

@nickvergessen Migrated it to be an OCSController. Any opinions about the endpoint naming? Should we add it to the /cloud OCS root? Or just have a separate core one (as it is currently)?

@juliusknorr juliusknorr added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Feb 1, 2018
@rullzer

rullzer commented Feb 1, 2018

Copy link
Copy Markdown
Member

I'm fine with the url like that :)

* @param bool $absolute
* @return DataResponse
*/
public function getAppsNavigation(bool $absolute = false) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can add : DataResponse too

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah thanks, I somehow missed that.

@juliusknorr
juliusknorr force-pushed the webapps-capabilities branch 2 times, most recently from a64c123 to f91e852 Compare February 1, 2018 15:34
@rullzer
rullzer force-pushed the webapps-capabilities branch from f91e852 to c7a965d Compare February 8, 2018 20:08
*/
private function rewriteToAbsoluteUrls(array $navigation): array {
foreach ($navigation as &$entry) {
if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we do the same check for the icon? So that they can also be used?

@rullzer

rullzer commented Feb 8, 2018

Copy link
Copy Markdown
Member

I rebased upon master and updated the autoloader.

@rullzer rullzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool stuff!

public static function getNavigation() {
$entries = OC::$server->getNavigationManager()->getAll();
return self::proceedNavigation($entries);
return OC::$server->getNavigationManager()->getAll();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

deprecate them so IDE's give warnings ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed and also replaced the usage of those methods in the server.

@@ -631,8 +605,7 @@ public static function getNavigation() {
* entries are sorted by the key 'order' ascending.
*/
public static function getSettingsNavigation() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

juliusknorr and others added 6 commits February 12, 2018 17:22
They might be useful when requesting the navigation from the clients

Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Roeland Jago Douma <[email protected]>
@juliusknorr

Copy link
Copy Markdown
Member Author

Shouldn't we do the same check for the icon? So that they can also be used?

Sorry, I missed that comment. Not the icon url will also be absolute if requested. Ready for review now.

Signed-off-by: Julius Härtl <[email protected]>
@camilasan

Copy link
Copy Markdown
Member

Could we merge it @nickvergessen ?

* @return array
* @since 14.0.0
*/
public function getAll(string $type = 'link'): array;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does not match docs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 Fixed

Comment thread lib/private/NavigationManager.php Outdated
* @param $list
* @return mixed
*/
private function proceedNavigation($list) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add type hint and return type, also in docs

@MorrisJobke
MorrisJobke merged commit 14bc9b1 into master Feb 15, 2018
@MorrisJobke
MorrisJobke deleted the webapps-capabilities branch February 15, 2018 15:55
@camilasan

camilasan commented Feb 19, 2018 •

Copy link
Copy Markdown
Member

Just in case someone else also needs it - this is the correct way of doing the request:

$ curl http://user:password@localhost/nextcloud/ocs/v2.php/core/navigation/apps

After the changes in the code, the first example given in the comments it is not valid anymore.

@rullzer

rullzer commented Feb 19, 2018

Copy link
Copy Markdown
Member

@camilasan please use v2.php ;) That gives better http status codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants