Skip to content

Commit 8f650fe

Browse files
authored
Merge pull request #20114 from nextcloud/techdebt/noid/allow-some-apps-to-have-root-urls
Allow some apps to have root URLs in their own routing file
2 parents 613f0f2 + 1b93d5f commit 8f650fe

14 files changed

Lines changed: 229 additions & 273 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
return [
25+
'routes' => [
26+
[
27+
'name' => 'RequestHandler#addShare',
28+
'url' => '/ocm/shares',
29+
'verb' => 'POST',
30+
'root' => '',
31+
],
32+
[
33+
'name' => 'RequestHandler#receiveNotification',
34+
'url' => '/ocm/notifications',
35+
'verb' => 'POST',
36+
'root' => '',
37+
],
38+
],
39+
];

apps/files/appinfo/routes.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
$this,
4242
[
4343
'routes' => [
44+
[
45+
'name' => 'View#showFile',
46+
'url' => '/f/{fileid}',
47+
'verb' => 'GET',
48+
'root' => '',
49+
],
50+
4451
[
4552
'name' => 'API#getThumbnail',
4653
'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
@@ -146,7 +153,7 @@
146153

147154
/** @var $this \OC\Route\Router */
148155

149-
$this->create('files_ajax_download', 'ajax/download.php')
156+
$this->create('files_ajax_download', 'apps/files/ajax/download.php')
150157
->actionInclude('files/ajax/download.php');
151-
$this->create('files_ajax_list', 'ajax/list.php')
158+
$this->create('files_ajax_list', 'apps/files/ajax/list.php')
152159
->actionInclude('files/ajax/list.php');

apps/files_external/appinfo/routes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
]
6161
);
6262

63-
$this->create('files_external_oauth1', 'ajax/oauth1.php')
63+
$this->create('files_external_oauth1', 'apps/files_external/ajax/oauth1.php')
6464
->actionInclude('files_external/ajax/oauth1.php');
65-
$this->create('files_external_oauth2', 'ajax/oauth2.php')
65+
$this->create('files_external_oauth2', 'apps/files_external/ajax/oauth2.php')
6666
->actionInclude('files_external/ajax/oauth2.php');
6767

6868

69-
$this->create('files_external_list_applicable', '/applicable')
69+
$this->create('files_external_list_applicable', '/apps/files_external/applicable')
7070
->actionInclude('files_external/ajax/applicable.php');

apps/files_sharing/appinfo/routes.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@
3030
'ExternalShares' => ['url' => '/api/externalShares'],
3131
],
3232
'routes' => [
33+
[
34+
'name' => 'Share#showShare',
35+
'url' => '/s/{token}',
36+
'verb' => 'GET',
37+
'root' => '',
38+
],
39+
[
40+
'name' => 'Share#showAuthenticate',
41+
'url' => '/s/{token}/authenticate/{redirect}',
42+
'verb' => 'GET',
43+
'root' => '',
44+
],
45+
[
46+
'name' => 'Share#authenticate',
47+
'url' => '/s/{token}/authenticate/{redirect}',
48+
'verb' => 'POST',
49+
'root' => '',
50+
],
51+
[
52+
'name' => 'Share#downloadShare',
53+
'url' => '/s/{token}/download',
54+
'verb' => 'GET',
55+
'root' => '',
56+
],
57+
[
58+
'name' => 'PublicPreview#directLink',
59+
'url' => '/s/{token}/preview',
60+
'verb' => 'GET',
61+
'root' => '',
62+
],
63+
3364
[
3465
'name' => 'externalShares#testRemote',
3566
'url' => '/testremote',

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
use OC\AppFramework\Utility\SimpleContainer;
3636
use OCA\Files_Sharing\Capabilities;
37-
use OCA\Files_Sharing\Controller\ExternalSharesController;
38-
use OCA\Files_Sharing\Controller\ShareController;
3937
use OCA\Files_Sharing\External\Manager;
4038
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
4139
use OCA\Files_Sharing\Listener\LoadSidebarListener;
@@ -51,10 +49,7 @@
5149
use OCA\Files\Event\LoadAdditionalScriptsEvent;
5250
use OCA\Files\Event\LoadSidebar;
5351
use OCP\AppFramework\App;
54-
use OCP\AppFramework\Utility\IControllerMethodReflector;
55-
use OCP\Defaults;
5652
use OCP\EventDispatcher\IEventDispatcher;
57-
use OCP\Federation\ICloudIdManager;
5853
use OCP\Files\Config\IMountProviderCollection;
5954
use OCP\Group\Events\UserAddedEvent;
6055
use OCP\IContainer;
@@ -80,48 +75,10 @@ public function __construct(array $urlParams = []) {
8075
$mountProviderCollection = $server->getMountProviderCollection();
8176
$notifications = $server->getNotificationManager();
8277

83-
/**
84-
* Controllers
85-
*/
86-
$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
87-
$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
88-
return new ShareController(
89-
$c->query('AppName'),
90-
$c->query('Request'),
91-
$server->getConfig(),
92-
$server->getURLGenerator(),
93-
$server->getUserManager(),
94-
$server->getLogger(),
95-
$server->getActivityManager(),
96-
$server->getShareManager(),
97-
$server->getSession(),
98-
$server->getPreviewManager(),
99-
$server->getRootFolder(),
100-
$federatedSharingApp->getFederatedShareProvider(),
101-
$server->getEventDispatcher(),
102-
$server->getL10N($c->query('AppName')),
103-
$server->query(Defaults::class)
104-
);
105-
});
106-
$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
107-
return new ExternalSharesController(
108-
$c->query('AppName'),
109-
$c->query('Request'),
110-
$c->query('ExternalManager'),
111-
$c->query('HttpClientService')
112-
);
113-
});
114-
11578
/**
11679
* Core class wrappers
11780
*/
118-
$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
119-
return $server->getHTTPClientService();
120-
});
121-
$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
122-
return $server->getCloudIdManager();
123-
});
124-
$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
81+
$container->registerService(Manager::class, function (SimpleContainer $c) use ($server) {
12582
$user = $server->getUserSession()->getUser();
12683
$uid = $user ? $user->getUID() : null;
12784
return new \OCA\Files_Sharing\External\Manager(
@@ -138,50 +95,21 @@ public function __construct(array $urlParams = []) {
13895
$uid
13996
);
14097
});
141-
$container->registerAlias(Manager::class, 'ExternalManager');
14298

14399
/**
144100
* Middleware
145101
*/
146-
$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
147-
return new SharingCheckMiddleware(
148-
$c->query('AppName'),
149-
$server->getConfig(),
150-
$server->getAppManager(),
151-
$server->query(IControllerMethodReflector::class),
152-
$server->getShareManager(),
153-
$server->getRequest()
154-
);
155-
});
156-
157-
$container->registerService(ShareInfoMiddleware::class, function () use ($server) {
158-
return new ShareInfoMiddleware(
159-
$server->getShareManager()
160-
);
161-
});
162-
163-
// Execute middlewares
164-
$container->registerMiddleWare('SharingCheckMiddleware');
102+
$container->registerMiddleWare(SharingCheckMiddleware::class);
165103
$container->registerMiddleWare(OCSShareAPIMiddleware::class);
166104
$container->registerMiddleWare(ShareInfoMiddleware::class);
167105

168-
$container->registerService('MountProvider', function (IContainer $c) {
169-
/** @var \OCP\IServerContainer $server */
170-
$server = $c->query('ServerContainer');
171-
return new MountProvider(
172-
$server->getConfig(),
173-
$server->getShareManager(),
174-
$server->getLogger()
175-
);
176-
});
177-
178106
$container->registerService('ExternalMountProvider', function (IContainer $c) {
179107
/** @var \OCP\IServerContainer $server */
180108
$server = $c->query('ServerContainer');
181109
return new \OCA\Files_Sharing\External\MountProvider(
182110
$server->getDatabaseConnection(),
183111
function () use ($c) {
184-
return $c->query('ExternalManager');
112+
return $c->query(Manager::class);
185113
},
186114
$server->getCloudIdManager()
187115
);
@@ -205,7 +133,7 @@ function () use ($c) {
205133
}
206134

207135
protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) {
208-
$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
136+
$mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class));
209137
$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
210138
}
211139

apps/files_versions/appinfo/routes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
]);
4141

4242
/** @var $this \OCP\Route\IRouter */
43-
$this->create('files_versions_download', 'download.php')
43+
$this->create('files_versions_download', 'apps/files_versions/download.php')
4444
->actionInclude('files_versions/download.php');
45-
$this->create('files_versions_ajax_getVersions', 'ajax/getVersions.php')
45+
$this->create('files_versions_ajax_getVersions', 'apps/files_versions/ajax/getVersions.php')
4646
->actionInclude('files_versions/ajax/getVersions.php');
47-
$this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php')
47+
$this->create('files_versions_ajax_rollbackVersion', 'apps/files_versions/ajax/rollbackVersion.php')
4848
->actionInclude('files_versions/ajax/rollbackVersion.php');

apps/testing/appinfo/app.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* @copyright Copyright (c) 2016, ownCloud GmbH.
46
*
@@ -21,4 +23,4 @@
2123
*
2224
*/
2325

24-
$app = new \OCA\Testing\AppInfo\Application();
26+
$app = \OC::$server->query(\OCA\Testing\AppInfo\Application::class);

apps/user_ldap/appinfo/routes.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
*/
2929

3030
/** @var $this \OCP\Route\IRouter */
31-
$this->create('user_ldap_ajax_clearMappings', 'ajax/clearMappings.php')
31+
$this->create('user_ldap_ajax_clearMappings', 'apps/user_ldap/ajax/clearMappings.php')
3232
->actionInclude('user_ldap/ajax/clearMappings.php');
33-
$this->create('user_ldap_ajax_deleteConfiguration', 'ajax/deleteConfiguration.php')
33+
$this->create('user_ldap_ajax_deleteConfiguration', 'apps/user_ldap/ajax/deleteConfiguration.php')
3434
->actionInclude('user_ldap/ajax/deleteConfiguration.php');
35-
$this->create('user_ldap_ajax_getConfiguration', 'ajax/getConfiguration.php')
35+
$this->create('user_ldap_ajax_getConfiguration', 'apps/user_ldap/ajax/getConfiguration.php')
3636
->actionInclude('user_ldap/ajax/getConfiguration.php');
37-
$this->create('user_ldap_ajax_getNewServerConfigPrefix', 'ajax/getNewServerConfigPrefix.php')
37+
$this->create('user_ldap_ajax_getNewServerConfigPrefix', 'apps/user_ldap/ajax/getNewServerConfigPrefix.php')
3838
->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php');
39-
$this->create('user_ldap_ajax_setConfiguration', 'ajax/setConfiguration.php')
39+
$this->create('user_ldap_ajax_setConfiguration', 'apps/user_ldap/ajax/setConfiguration.php')
4040
->actionInclude('user_ldap/ajax/setConfiguration.php');
41-
$this->create('user_ldap_ajax_testConfiguration', 'ajax/testConfiguration.php')
41+
$this->create('user_ldap_ajax_testConfiguration', 'apps/user_ldap/ajax/testConfiguration.php')
4242
->actionInclude('user_ldap/ajax/testConfiguration.php');
43-
$this->create('user_ldap_ajax_wizard', 'ajax/wizard.php')
43+
$this->create('user_ldap_ajax_wizard', 'apps/user_ldap/ajax/wizard.php')
4444
->actionInclude('user_ldap/ajax/wizard.php');
4545

4646
$application = new \OCP\AppFramework\App('user_ldap');

core/routes.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@
8989
// Logins for passwordless auth
9090
['name' => 'WebAuthn#startAuthentication', 'url' => 'login/webauthn/start', 'verb' => 'POST'],
9191
['name' => 'WebAuthn#finishAuthentication', 'url' => 'login/webauthn/finish', 'verb' => 'POST'],
92-
93-
// Legacy routes that need to be globally available while they are handled by an app
94-
['name' => 'viewcontroller#showFile', 'url' => '/f/{fileid}', 'verb' => 'GET', 'app' => 'files'],
95-
['name' => 'sharecontroller#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'],
96-
['name' => 'sharecontroller#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'],
97-
['name' => 'sharecontroller#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'],
98-
['name' => 'sharecontroller#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'],
99-
['name' => 'publicpreview#directLink', 'url' => '/s/{token}/preview', 'verb' => 'GET', 'app' => 'files_sharing'],
100-
['name' => 'requesthandlercontroller#addShare', 'url' => '/ocm/shares', 'verb' => 'POST', 'app' => 'cloud_federation_api'],
101-
['name' => 'requesthandlercontroller#receiveNotification', 'url' => '/ocm/notifications', 'verb' => 'POST', 'app' => 'cloud_federation_api'],
102-
['name' => 'pagecontroller#showCall', 'url' => '/call/{token}', 'verb' => 'GET', 'app' => 'spreed'],
103-
['name' => 'pagecontroller#authenticatePassword', 'url' => '/call/{token}', 'verb' => 'POST', 'app' => 'spreed'],
10492
],
10593
'ocs' => [
10694
['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],

0 commit comments

Comments
 (0)