Skip to content

Commit

Permalink
Discovery, basic routes
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo authored and gitmate-bot committed Dec 5, 2018
1 parent f6c6633 commit a5a2f83
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/federatedfilesharing/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
<?php
/**
* @author Viktar Dubiniuk <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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'],
Expand All @@ -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'],
]
];
12 changes: 12 additions & 0 deletions apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
}
);
}

/**
Expand Down
138 changes: 138 additions & 0 deletions apps/federatedfilesharing/lib/Controller/OcmController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* @author Viktar Dubiniuk <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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/'
];
}

}
38 changes: 38 additions & 0 deletions ocm-provider/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* @author Viktar Dubiniuk <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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');
}

0 comments on commit a5a2f83

Please sign in to comment.