summaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework/Routing
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-03-23 16:33:11 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-04-18 11:21:28 +0200
commit3f8168b6e5c0fc14709b713d9ca4943f9df70273 (patch)
tree4f8e0a487f6a1c50c041ac96da2f024b86ab1532 /lib/private/AppFramework/Routing
parent64196ddd19684b6a218428eeb6ee370d0514b68c (diff)
downloadnextcloud-server-3f8168b6e5c0fc14709b713d9ca4943f9df70273.tar.gz
nextcloud-server-3f8168b6e5c0fc14709b713d9ca4943f9df70273.zip
Allow some apps to have root URLs in their own routing file
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/AppFramework/Routing')
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php125
1 files changed, 48 insertions, 77 deletions
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php
index eb9991fbe69..58e677dd01a 100644
--- a/lib/private/AppFramework/Routing/RouteConfig.php
+++ b/lib/private/AppFramework/Routing/RouteConfig.php
@@ -56,6 +56,14 @@ class RouteConfig {
/** @var string[] */
private $controllerNameCache = [];
+ public const ROOT_URL_APPS = [
+ 'cloud_federation_api',
+ 'core',
+ 'files_sharing',
+ 'files',
+ 'spreed',
+ ];
+
/**
* @param \OC\AppFramework\DependencyInjection\DIContainer $container
* @param \OCP\Route\IRouter $router
@@ -98,42 +106,7 @@ class RouteConfig {
private function processOCS(array $routes): void {
$ocsRoutes = $routes['ocs'] ?? [];
foreach ($ocsRoutes as $ocsRoute) {
- $name = $ocsRoute['name'];
- $postfix = $ocsRoute['postfix'] ?? '';
- $root = $ocsRoute['root'] ?? '/apps/' . $this->appName;
-
- $url = $root . $ocsRoute['url'];
- $verb = strtoupper($ocsRoute['verb'] ?? 'GET');
-
- $split = explode('#', $name, 2);
- if (count($split) !== 2) {
- throw new \UnexpectedValueException('Invalid route name');
- }
- list($controller, $action) = $split;
-
- $controllerName = $this->buildControllerName($controller);
- $actionName = $this->buildActionName($action);
-
- $routeName = 'ocs.' . $this->appName . '.' . $controller . '.' . $action . $postfix;
-
- // register the route
- $handler = new RouteActionHandler($this->container, $controllerName, $actionName);
-
- $router = $this->router->create($routeName, $url)
- ->method($verb)
- ->action($handler);
-
- // optionally register requirements for route. This is used to
- // tell the route parser how url parameters should be matched
- if (array_key_exists('requirements', $ocsRoute)) {
- $router->requirements($ocsRoute['requirements']);
- }
-
- // optionally register defaults for route. This is used to
- // tell the route parser how url parameters should be default valued
- if (array_key_exists('defaults', $ocsRoute)) {
- $router->defaults($ocsRoute['defaults']);
- }
+ $this->processRoute($ocsRoute, 'ocs.');
}
}
@@ -145,53 +118,51 @@ class RouteConfig {
private function processSimpleRoutes(array $routes): void {
$simpleRoutes = $routes['routes'] ?? [];
foreach ($simpleRoutes as $simpleRoute) {
- $name = $simpleRoute['name'];
- $postfix = $simpleRoute['postfix'] ?? '';
+ $this->processRoute($simpleRoute);
+ }
+ }
- $url = $simpleRoute['url'];
- $verb = strtoupper($simpleRoute['verb'] ?? 'GET');
+ protected function processRoute(array $route, string $routeNamePrefix = ''): void {
+ $name = $route['name'];
+ $postfix = $route['postfix'] ?? '';
+ $defaultRoot = $this->appName === 'core' ? '' : '/apps/' . $this->appName;
+ $root = $route['root'] ?? $defaultRoot;
+ if ($routeNamePrefix === '' && !\in_array($this->appName, self::ROOT_URL_APPS, true)) {
+ // Only allow root URLS for some apps
+ $root = $defaultRoot;
+ }
- $split = explode('#', $name, 2);
- if (count($split) !== 2) {
- throw new \UnexpectedValueException('Invalid route name');
- }
- list($controller, $action) = $split;
-
- $controllerName = $this->buildControllerName($controller);
- $actionName = $this->buildActionName($action);
- $appName = $simpleRoute['app'] ?? $this->appName;
-
- if (isset($simpleRoute['app'])) {
- // Legacy routes that need to be globally available while they are handled by an app
- // E.g. '/f/{id}', '/s/{token}', '/call/{token}', …
- $controllerName = str_replace('controllerController', 'Controller', $controllerName);
- if ($controllerName === 'PublicpreviewController') {
- $controllerName = 'PublicPreviewController';
- } elseif ($controllerName === 'RequesthandlerController') {
- $controllerName = 'RequestHandlerController';
- }
- $controllerName = App::buildAppNamespace($appName) . '\\Controller\\' . $controllerName;
- }
+ $url = $root . $route['url'];
+ $verb = strtoupper($route['verb'] ?? 'GET');
+
+ $split = explode('#', $name, 2);
+ if (count($split) !== 2) {
+ throw new \UnexpectedValueException('Invalid route name');
+ }
+ list($controller, $action) = $split;
- $routeName = $appName . '.' . $controller . '.' . $action . $postfix;
+ $controllerName = $this->buildControllerName($controller);
+ $actionName = $this->buildActionName($action);
- // register the route
- $handler = new RouteActionHandler($this->container, $controllerName, $actionName);
- $router = $this->router->create($routeName, $url)
- ->method($verb)
- ->action($handler);
+ $routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix;
- // optionally register requirements for route. This is used to
- // tell the route parser how url parameters should be matched
- if (array_key_exists('requirements', $simpleRoute)) {
- $router->requirements($simpleRoute['requirements']);
- }
+ // register the route
+ $handler = new RouteActionHandler($this->container, $controllerName, $actionName);
- // optionally register defaults for route. This is used to
- // tell the route parser how url parameters should be default valued
- if (array_key_exists('defaults', $simpleRoute)) {
- $router->defaults($simpleRoute['defaults']);
- }
+ $router = $this->router->create($routeName, $url)
+ ->method($verb)
+ ->action($handler);
+
+ // optionally register requirements for route. This is used to
+ // tell the route parser how url parameters should be matched
+ if(array_key_exists('requirements', $route)) {
+ $router->requirements($route['requirements']);
+ }
+
+ // optionally register defaults for route. This is used to
+ // tell the route parser how url parameters should be default valued
+ if(array_key_exists('defaults', $route)) {
+ $router->defaults($route['defaults']);
}
}