From 575875e8d03e1396bcdb1fac75a7c6076fd92287 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 9 Aug 2016 10:21:20 +0200 Subject: [PATCH 1/4] Allow OCS routes in Core and Settings --- core/Controller/OCSController.php | 44 +++++++++++++++++++++++++++++++ lib/private/Route/Router.php | 5 ++++ 2 files changed, 49 insertions(+) create mode 100644 core/Controller/OCSController.php diff --git a/core/Controller/OCSController.php b/core/Controller/OCSController.php new file mode 100644 index 0000000000..278a16186b --- /dev/null +++ b/core/Controller/OCSController.php @@ -0,0 +1,44 @@ +capabilitiesManager = $capabilitiesManager; + } + + public function getCapabilities() { + $result = []; + list($major, $minor, $micro) = \OCP\Util::getVersion(); + $result['version'] = array( + 'major' => $major, + 'minor' => $minor, + 'micro' => $micro, + 'string' => \OC_Util::getVersionString(), + 'edition' => \OC_Util::getEditionString(), + ); + + $result['capabilities'] = $this->capabilitiesManager->getCapabilities(); + + return new DataResponse(['data' => $result]); + } +} \ No newline at end of file diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index 9df7418444..59f403d66e 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -163,6 +163,11 @@ class Router implements IRouter { $this->useCollection('root'); require_once __DIR__ . '/../../../settings/routes.php'; require_once __DIR__ . '/../../../core/routes.php'; + + // Also add the OCS collection + $collection = $this->getCollection('root.ocs'); + $collection->addPrefix('/ocsapp'); + $this->root->addCollection($collection); } if ($this->loaded) { // include ocs routes, must be loaded last for /ocs prefix From 02449c83365fae8d5a47b001b18605478122bd86 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 9 Aug 2016 10:21:51 +0200 Subject: [PATCH 2/4] Move getCapabilities over to Core --- core/Application.php | 3 +++ core/Controller/OCSController.php | 27 +++++++++++++++++++++++++-- core/routes.php | 3 +++ lib/private/OCS/Cloud.php | 16 ---------------- ocs/routes.php | 7 ------- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/Application.php b/core/Application.php index a0deaff2b9..e8c924432d 100644 --- a/core/Application.php +++ b/core/Application.php @@ -186,6 +186,9 @@ class Application extends App { $container->registerService('TwoFactorAuthManager', function(SimpleContainer $c) { return $c->query('ServerContainer')->getTwoFactorAuthManager(); }); + $container->registerService('OC\CapabilitiesManager', function(SimpleContainer $c) { + return $c->query('ServerContainer')->getCapabilitiesManager(); + }); } } diff --git a/core/Controller/OCSController.php b/core/Controller/OCSController.php index 278a16186b..750ab37eb8 100644 --- a/core/Controller/OCSController.php +++ b/core/Controller/OCSController.php @@ -1,5 +1,24 @@ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ namespace OC\Core\Controller; use OC\CapabilitiesManager; @@ -26,6 +45,10 @@ class OCSController extends \OCP\AppFramework\OCSController { $this->capabilitiesManager = $capabilitiesManager; } + /** + * @NoAdminRequired + * @return DataResponse + */ public function getCapabilities() { $result = []; list($major, $minor, $micro) = \OCP\Util::getVersion(); @@ -41,4 +64,4 @@ class OCSController extends \OCP\AppFramework\OCSController { return new DataResponse(['data' => $result]); } -} \ No newline at end of file +} diff --git a/core/routes.php b/core/routes.php index 98454946d4..92ce4440ec 100644 --- a/core/routes.php +++ b/core/routes.php @@ -53,6 +53,9 @@ $application->registerRoutes($this, [ ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], ], + 'ocs' => [ + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], + ], ]); // Post installation check diff --git a/lib/private/OCS/Cloud.php b/lib/private/OCS/Cloud.php index 84fcfe6e51..3a00fa3756 100644 --- a/lib/private/OCS/Cloud.php +++ b/lib/private/OCS/Cloud.php @@ -27,22 +27,6 @@ namespace OC\OCS; class Cloud { - public static function getCapabilities() { - $result = array(); - list($major, $minor, $micro) = \OCP\Util::getVersion(); - $result['version'] = array( - 'major' => $major, - 'minor' => $minor, - 'micro' => $micro, - 'string' => \OC_Util::getVersionString(), - 'edition' => \OC_Util::getEditionString(), - ); - - $result['capabilities'] = \OC::$server->getCapabilitiesManager()->getCapabilities(); - - return new Result($result); - } - public static function getCurrentUser() { $userObject = \OC::$server->getUserManager()->get(\OC_User::getUser()); $data = array( diff --git a/ocs/routes.php b/ocs/routes.php index 0606fe3e30..bb24c79eba 100644 --- a/ocs/routes.php +++ b/ocs/routes.php @@ -84,13 +84,6 @@ API::register( API::USER_AUTH ); // cloud -API::register( - 'get', - '/cloud/capabilities', - array('OC_OCS_Cloud', 'getCapabilities'), - 'core', - API::USER_AUTH - ); API::register( 'get', '/cloud/user', From 69da896785cf3baab583577b119310c1a2938a64 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 9 Aug 2016 11:27:55 +0200 Subject: [PATCH 3/4] Move /cloud/user to Core app --- core/Controller/OCSController.php | 23 ++++++++++++++++++++++- core/routes.php | 1 + ocs/routes.php | 8 -------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/Controller/OCSController.php b/core/Controller/OCSController.php index 750ab37eb8..d5783ae32e 100644 --- a/core/Controller/OCSController.php +++ b/core/Controller/OCSController.php @@ -24,25 +24,32 @@ namespace OC\Core\Controller; use OC\CapabilitiesManager; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +use OCP\IUserSession; class OCSController extends \OCP\AppFramework\OCSController { /** @var CapabilitiesManager */ private $capabilitiesManager; + /** @var IUserSession */ + private $userSession; + /** * OCSController constructor. * * @param string $appName * @param IRequest $request * @param CapabilitiesManager $capabilitiesManager + * @param IUserSession $userSession */ public function __construct($appName, IRequest $request, - CapabilitiesManager $capabilitiesManager) { + CapabilitiesManager $capabilitiesManager, + IUserSession $userSession) { parent::__construct($appName, $request); $this->capabilitiesManager = $capabilitiesManager; + $this->userSession = $userSession; } /** @@ -64,4 +71,18 @@ class OCSController extends \OCP\AppFramework\OCSController { return new DataResponse(['data' => $result]); } + + /** + * @NoAdminRequired + * @return DataResponse + */ + public function getCurrentUser() { + $userObject = $this->userSession->getUser(); + $data = [ + 'id' => $userObject->getUID(), + 'display-name' => $userObject->getDisplayName(), + 'email' => $userObject->getEMailAddress(), + ]; + return new DataResponse(['data' => $data]); + } } diff --git a/core/routes.php b/core/routes.php index 92ce4440ec..b4868c14cf 100644 --- a/core/routes.php +++ b/core/routes.php @@ -55,6 +55,7 @@ $application->registerRoutes($this, [ ], 'ocs' => [ ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], + ['root' => '/cloud', 'name' => 'OCS#getCurrentUser', 'url' => '/user', 'verb' => 'GET'], ], ]); diff --git a/ocs/routes.php b/ocs/routes.php index bb24c79eba..ae2ef05adc 100644 --- a/ocs/routes.php +++ b/ocs/routes.php @@ -83,14 +83,6 @@ API::register( 'core', API::USER_AUTH ); -// cloud -API::register( - 'get', - '/cloud/user', - array('OC_OCS_Cloud', 'getCurrentUser'), - 'core', - API::USER_AUTH -); // Server-to-Server Sharing if (\OC::$server->getAppManager()->isEnabledForUser('files_sharing')) { From e2f54559d663667554394f2ddaedad5c9114ec76 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 9 Aug 2016 11:29:54 +0200 Subject: [PATCH 4/4] Remove OC_OCS_Cloud and OC\OCS\Cloud --- lib/private/OCS/Cloud.php | 39 -------------------------------- lib/private/legacy/ocs/cloud.php | 28 ----------------------- 2 files changed, 67 deletions(-) delete mode 100644 lib/private/OCS/Cloud.php delete mode 100644 lib/private/legacy/ocs/cloud.php diff --git a/lib/private/OCS/Cloud.php b/lib/private/OCS/Cloud.php deleted file mode 100644 index 3a00fa3756..0000000000 --- a/lib/private/OCS/Cloud.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @author Roeland Jago Douma - * @author Thomas Müller - * @author Tom Needham - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OC\OCS; - -class Cloud { - - public static function getCurrentUser() { - $userObject = \OC::$server->getUserManager()->get(\OC_User::getUser()); - $data = array( - 'id' => $userObject->getUID(), - 'display-name' => $userObject->getDisplayName(), - 'email' => $userObject->getEMailAddress(), - ); - return new Result($data); - } -} diff --git a/lib/private/legacy/ocs/cloud.php b/lib/private/legacy/ocs/cloud.php deleted file mode 100644 index 1115295830..0000000000 --- a/lib/private/legacy/ocs/cloud.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @author Thomas Müller - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -/** - * @deprecated Since 9.1.0 use \OC\OCS\Cloud - */ -class OC_OCS_Cloud extends \OC\OCS\Cloud { -}