]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow ocs/v2.php/cloud/... routes 691/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 1 Aug 2016 14:37:48 +0000 (16:37 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 8 Aug 2016 13:01:26 +0000 (15:01 +0200)
One of the possibilities of the old OCS API is that you can define the
url yourself.

This PR makes this possible again by adding an optional root elemenet to
the route. Routes are thus:

.../ocs/v2.php/<root>/<url>

By default <root> = apps/<app>

This will allow for example the provisioning API etc to be in
../ovs/v2/php/cloud/users

lib/private/AppFramework/Routing/RouteConfig.php
lib/private/Route/Router.php
tests/lib/AppFramework/Routing/RoutingTest.php

index 066c0da1138ac25cab829c66bbebabdcb0a8f6aa..e94f2e50c1d753bf1a337528659552f1e7728bd1 100644 (file)
@@ -86,7 +86,13 @@ class RouteConfig {
                                $postfix = $ocsRoute['postfix'];
                        }
 
-                       $url = $ocsRoute['url'];
+                       if (isset($ocsRoute['root'])) {
+                               $root = $ocsRoute['root'];
+                       } else {
+                               $root = '/apps/'.$this->appName;
+                       }
+
+                       $url = $root . $ocsRoute['url'];
                        $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET';
 
                        $split = explode('#', $name, 2);
index ac42c4025c20c1835946bf938bde2272073695c8..9df74184448e19d6ebf43551d91d2d4c50c4fb64 100644 (file)
@@ -154,7 +154,7 @@ class Router implements IRouter {
 
                                // Also add the OCS collection
                                $collection = $this->getCollection($app.'.ocs');
-                               $collection->addPrefix('/ocsapp/apps/' . $app);
+                               $collection->addPrefix('/ocsapp');
                                $this->root->addCollection($collection);
                        }
                }
index 6c8b0f40133b3f20aa9a0c7953a344bc08617e0c..d395584d01116b31aa9fc6ee6952f4e5a81ebff8 100644 (file)
@@ -24,7 +24,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open');
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
        }
 
        public function testSimpleRouteWithMissingVerb()
@@ -42,7 +42,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open');
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
        }
 
        public function testSimpleRouteWithLowercaseVerb()
@@ -60,7 +60,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open');
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
        }
 
        public function testSimpleRouteWithRequirements()
@@ -78,7 +78,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
        }
 
        public function testSimpleRouteWithDefaults()
@@ -97,7 +97,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
        }
 
        public function testSimpleRouteWithPostfix()
@@ -115,7 +115,7 @@ class RoutingTest extends \Test\TestCase
                        ]
                ];
 
-               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
+               $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
        }
 
        /**
@@ -175,7 +175,7 @@ class RoutingTest extends \Test\TestCase
                        ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
                ]];
 
-               $this->assertSimpleOCSRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent');
+               $this->assertSimpleOCSRoute($routes, 'admin_folders.open_current', 'DELETE', '/apps/app1/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent');
        }
 
        public function testResource()