Repository navigation
Expose navigation entries as API endpoint - #8095
Conversation
|
Any reason not to expose this in the capabilities? |
|
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.
|
| use OCP\IRequest; | ||
| use OCP\IURLGenerator; | ||
|
|
||
| class NavigationController extends Controller { |
| if ($absolute) { | ||
| $this->rewriteToAbsoluteUrls($navigation); | ||
| } | ||
| return new JSONResponse($navigation); |
There was a problem hiding this comment.
return new DataResponse($navigation);
| if ($absolute) { | ||
| $this->rewriteToAbsoluteUrls($navigation); | ||
| } | ||
| return new JSONResponse($navigation); |
There was a problem hiding this comment.
return new DataResponse($navigation);
| * | ||
| * @param array $navigation | ||
| */ | ||
| private function rewriteToAbsoluteUrls(array &$navigation) { |
There was a problem hiding this comment.
I'd prefer return over by-reference
| ['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'], |
There was a problem hiding this comment.
should be OCS routes, everything else is not to be used by clients
fefea23 to
b665eea
Compare
Codecov Report
@@ 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
|
|
@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)? |
|
I'm fine with the url like that :) |
| * @param bool $absolute | ||
| * @return DataResponse | ||
| */ | ||
| public function getAppsNavigation(bool $absolute = false) { |
There was a problem hiding this comment.
You can add : DataResponse too
There was a problem hiding this comment.
Ah thanks, I somehow missed that.
a64c123 to
f91e852
Compare
f91e852 to
c7a965d
Compare
| */ | ||
| private function rewriteToAbsoluteUrls(array $navigation): array { | ||
| foreach ($navigation as &$entry) { | ||
| if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) { |
There was a problem hiding this comment.
Shouldn't we do the same check for the icon? So that they can also be used?
|
I rebased upon master and updated the autoloader. |
| public static function getNavigation() { | ||
| $entries = OC::$server->getNavigationManager()->getAll(); | ||
| return self::proceedNavigation($entries); | ||
| return OC::$server->getNavigationManager()->getAll(); |
There was a problem hiding this comment.
deprecate them so IDE's give warnings ;)
There was a problem hiding this comment.
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() { | |||
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
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]>
Signed-off-by: Julius Härtl <[email protected]>
6a8f3de to
a395d40
Compare
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]>
a395d40 to
5a23b35
Compare
|
Could we merge it @nickvergessen ? |
| * @return array | ||
| * @since 14.0.0 | ||
| */ | ||
| public function getAll(string $type = 'link'): array; |
| * @param $list | ||
| * @return mixed | ||
| */ | ||
| private function proceedNavigation($list) { |
There was a problem hiding this comment.
add type hint and return type, also in docs
Signed-off-by: Julius Härtl <[email protected]>
|
Just in case someone else also needs it - this is the correct way of doing the request: After the changes in the code, the first example given in the comments it is not valid anymore. |
|
@camilasan please use v2.php ;) That gives better http status codes. |
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