Unverified Commit 394ba7dd authored by Thomas Müller's avatar Thomas Müller
Browse files

Move /cloud/user and /cloud/capabilities over to AppFramework

parent 371d191e
......@@ -30,6 +30,7 @@ namespace OC\Core;
use OC\AppFramework\Utility\SimpleContainer;
use OC\AppFramework\Utility\TimeFactory;
use OC\Core\Controller\AvatarController;
use OC\Core\Controller\CloudController;
use OC\Core\Controller\LoginController;
use OC\Core\Controller\LostController;
use OC\Core\Controller\OccController;
......@@ -126,6 +127,12 @@ class Application extends App {
$c->query('SecureRandom')
);
});
$container->registerService('CloudController', function(SimpleContainer $c) {
return new CloudController(
$c->query('AppName'),
$c->query('Request')
);
});
/**
* Core class wrappers
......
......@@ -22,11 +22,24 @@
*
*/
namespace OC\OCS;
namespace OC\Core\Controller;
class Cloud {
use OCP\AppFramework\OCSController;
use OCP\IRequest;
public static function getCapabilities() {
class CloudController extends OCSController {
public function __construct($appName, IRequest $request) {
parent::__construct($appName, $request);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return array
*/
public function getCapabilities() {
$result = [];
list($major, $minor, $micro) = \OCP\Util::getVersion();
$result['version'] = [
......@@ -39,16 +52,22 @@ class Cloud {
$result['capabilities'] = \OC::$server->getCapabilitiesManager()->getCapabilities();
return new Result($result);
return ['data' => $result];
}
public static function getCurrentUser() {
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return array
*/
public function getCurrentUser() {
$userObject = \OC::$server->getUserManager()->get(\OC_User::getUser());
$data = [
'id' => $userObject->getUID(),
'display-name' => $userObject->getDisplayName(),
'email' => $userObject->getEMailAddress(),
];
return new Result($data);
return ['data' => $data];
}
}
......@@ -53,6 +53,10 @@ $application->registerRoutes($this, [
['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
],
'ocs' => [
['name' => 'Cloud#getCapabilities', 'url' => '/cloud/capabilities', 'verb' => 'GET'],
['name' => 'Cloud#getCurrentUser', 'url' => '/cloud/user', 'verb' => 'GET'],
]
]);
// Post installation check
......
......@@ -164,6 +164,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
......
......@@ -186,7 +186,7 @@ class OC_App {
try {
// encapsulated here to avoid variable scope conflicts
require_once $app . '/appinfo/app.php';
} catch (Error $ex) {
} catch (Exception $ex) {
\OC::$server->getLogger()->logException($ex);
$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
if (!in_array($app, $blacklist)) {
......
<?php
/**
* @author Roeland Jago Douma <rullzer@owncloud.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @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 <http://www.gnu.org/licenses/>
*
*/
/**
* @deprecated Since 9.1.0 use \OC\OCS\Cloud
*/
class OC_OCS_Cloud extends \OC\OCS\Cloud {
}
......@@ -81,21 +81,6 @@ API::register(
'core',
API::USER_AUTH
);
// cloud
API::register(
'get',
'/cloud/capabilities',
['OC_OCS_Cloud', 'getCapabilities'],
'core',
API::USER_AUTH
);
API::register(
'get',
'/cloud/user',
['OC_OCS_Cloud', 'getCurrentUser'],
'core',
API::USER_AUTH
);
// Server-to-Server Sharing
if (\OC::$server->getAppManager()->isEnabledForUser('files_sharing')) {
......
......@@ -76,6 +76,7 @@ try {
if(!\OC::$server->getUserSession()->isLoggedIn()) {
OC::handleLogin(\OC::$server->getRequest());
}
OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
} catch (LoginException $e) {
OC_API::respond(new Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'), OC_API::requestedFormat());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment