From a5a2f839afde431ebb559b62c05899ce57469b63 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Thu, 2 Aug 2018 19:06:34 +0300 Subject: [PATCH] Discovery, basic routes --- apps/federatedfilesharing/appinfo/routes.php | 30 ++++ .../lib/AppInfo/Application.php | 12 ++ .../lib/Controller/OcmController.php | 138 ++++++++++++++++++ ocm-provider/index.php | 38 +++++ 4 files changed, 218 insertions(+) create mode 100644 apps/federatedfilesharing/lib/Controller/OcmController.php create mode 100644 ocm-provider/index.php diff --git a/apps/federatedfilesharing/appinfo/routes.php b/apps/federatedfilesharing/appinfo/routes.php index ae7f98f187d1..a954bd0cd269 100644 --- a/apps/federatedfilesharing/appinfo/routes.php +++ b/apps/federatedfilesharing/appinfo/routes.php @@ -1,7 +1,27 @@ + * + * @copyright Copyright (c) 2018, 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 + * + */ return [ 'ocs' => [ + // ocm 0.3 ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], @@ -10,5 +30,15 @@ ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], + + // ocm 1.0-proposal1 + ['root' => '/', 'name' => 'OcmController#discovery', 'url' => '/ocm-provider', 'verb' => 'GET'], + ], + + 'routes' => [ + // ocm 1.0-proposal1 + ['name' => 'ocm#index', 'url' => '/', 'verb' => 'GET'], + ['name' => 'ocm#createShare', 'url' => '/shares', 'verb' => 'POST'], + ['name' => 'ocm#processNotification', 'url' => '/notifications', 'verb' => 'POST'], ] ]; diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index 90b8e4cc3127..817c350f5237 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -22,6 +22,7 @@ namespace OCA\FederatedFileSharing\AppInfo; use OCA\FederatedFileSharing\AddressHandler; +use OCA\FederatedFileSharing\Controller\OcmController; use OCA\FederatedFileSharing\DiscoveryManager; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\FedShareManager; @@ -105,6 +106,17 @@ function ($c) use ($server) { ); } ); + + $container->registerService( + 'OcmController', + function ($c) use ($server) { + return new OcmController( + $c->query('AppName'), + $c->query('Request'), + $server->getURLGenerator() + ); + } + ); } /** diff --git a/apps/federatedfilesharing/lib/Controller/OcmController.php b/apps/federatedfilesharing/lib/Controller/OcmController.php new file mode 100644 index 000000000000..85076ec749c1 --- /dev/null +++ b/apps/federatedfilesharing/lib/Controller/OcmController.php @@ -0,0 +1,138 @@ + + * + * @copyright Copyright (c) 2018, 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 + * + */ + +namespace OCA\FederatedFileSharing\Controller; + +use OCP\AppFramework\Controller; +use OCP\IRequest; +use OCP\IURLGenerator; + +/** + * Class OcmController + * + * @package OCA\FederatedFileSharing\Controller + */ +class OcmController extends Controller { + const API_VERSION = '1.0-proposal1'; + + protected $urlGenerator; + + public function __construct($appName, + IRequest $request, + IURLGenerator $urlGenerator) { + parent::__construct($appName, $request); + + $this->urlGenerator = $urlGenerator; + } + + /** + * @NoCSRFRequired + * @PublicPage + * + * EndPoint discovery + * Responds to /ocm-provider/ requests + * + * @return array + */ + public function discovery() { + return [ + 'enabled' => true, + 'apiVersion' => self::API_VERSION, + 'endPoint' => $this->urlGenerator->linkToRouteAbsolute( + "{$this->appName}.ocm.index" + ), + 'shareTypes' => [ + 'name' => 'file', + 'protocols' => $this->getProtocols() + ] + ]; + } + + /** + * @NoCSRFRequired + * @PublicPage + * + * + * + * @param string $shareWith identifier of the user or group to share the resource with + * @param string $name name of the shared resource + * @param string $description share description (optional) + * @param string $providerId Identifier of the resource at the provider side + * @param string $owner identifier of the user that owns the resource + * @param string $ownerDisplayName display name of the owner + * @param string $sender Provider specific identifier of the user that wants to share the resource + * @param string $senderDisplayName Display name of the user that wants to share the resource + * @param string $shareType Share type (user or group share) + * @param string $resourceType only 'file' is supported atm + * @param array $protocol + * [ + * 'name' => (string) protocol name. Only 'webdav' is supported atm, + * 'options' => [ + * protocol specific options + * only `webdav` options are supported atm + * e.g. `uri`, `access_token`, `password`, `permissions` etc. + * + * For backward compatibility the webdav protocol will use + * the 'sharedSecret" as username and password + * ] + * + */ + public function createShare($shareWith, + $name, + $description, + $providerId, + $owner, + $ownerDisplayName, + $sender, + $senderDisplayName, + $shareType, + $resourceType, + $protocol + + ) { + // TODO: implement + } + + /** + * @param string $notificationType notification type (SHARE_REMOVED, etc) + * @param string $resourceType only 'file' is supported atm + * @param string $providerId Identifier of the resource at the provider side + * @param array $notification + * [ + * optional additional parameters, depending on the notification and the resource type + * + * ] + */ + public function processNotification($notificationType, + $resourceType, + $providerId, + $notification + ) { + // TODO: implement + } + + protected function getProtocols() { + return [ + 'webdav' => '/public.php/webdav/' + ]; + } + +} diff --git a/ocm-provider/index.php b/ocm-provider/index.php new file mode 100644 index 000000000000..a71ec5b9cf6c --- /dev/null +++ b/ocm-provider/index.php @@ -0,0 +1,38 @@ + + * + * @copyright Copyright (c) 2018, 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 + * + */ + +require_once __DIR__ . '/../lib/base.php'; + +$server = \OC::$server; + +$isFederationEnabled = $server->getAppManager() + ->isEnabledForUser('federatedfilesharing'); +if ($isFederationEnabled) { + \OC_App::loadApp('federatedfilesharing'); + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); + $federatedSharingApp->dispatch('OcmController', 'discovery'); +} else { + $output = new \OC\AppFramework\Http\Output(''); + $output->setHttpResponseCode( + \OCP\AppFramework\Http::STATUS_NOT_IMPLEMENTED + ); + $output->setOutput('501 Not Implemented'); +}