Move remote_shares OCS endpoint to AppFramework
This commit is contained in:
parent
f5aafdc897
commit
ba104233b0
|
@ -77,6 +77,39 @@ $application->registerRoutes($this, [
|
||||||
'url' => '/api/v1/sharees',
|
'url' => '/api/v1/sharees',
|
||||||
'verb' => 'GET',
|
'verb' => 'GET',
|
||||||
],
|
],
|
||||||
|
/*
|
||||||
|
* Remote Shares
|
||||||
|
*/
|
||||||
|
[
|
||||||
|
'name' => 'Remote#getShares',
|
||||||
|
'url' => '/api/v1/remote_shares',
|
||||||
|
'verb' => 'GET',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Remote#getOpenShares',
|
||||||
|
'url' => '/api/v1/remote_shares/pending',
|
||||||
|
'verb' => 'GET',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Remote#acceptShare',
|
||||||
|
'url' => '/api/v1/remote_shares/pending/{id}',
|
||||||
|
'verb' => 'POST',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Remote#declineShare',
|
||||||
|
'url' => '/api/v1/remote_shares/pending/{id}',
|
||||||
|
'verb' => 'DELETE',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Remote#getShare',
|
||||||
|
'url' => '/api/v1/remote_shares/{id}',
|
||||||
|
'verb' => 'GET',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Remote#unshare',
|
||||||
|
'url' => '/api/v1/remote_shares/{id}',
|
||||||
|
'verb' => 'DELETE',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -96,33 +129,3 @@ $this->create('sharing_external_shareinfo', '/shareinfo')
|
||||||
// OCS API
|
// OCS API
|
||||||
|
|
||||||
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
|
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
|
||||||
|
|
||||||
API::register('get',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'getShares'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
||||||
API::register('get',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares/pending',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'getOpenShares'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
||||||
API::register('post',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares/pending/{id}',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'acceptShare'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
||||||
API::register('delete',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares/pending/{id}',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'declineShare'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
||||||
API::register('get',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares/{id}',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'getShare'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
||||||
API::register('delete',
|
|
||||||
'/apps/files_sharing/api/v1/remote_shares/{id}',
|
|
||||||
array('\OCA\Files_Sharing\API\Remote', 'unshare'),
|
|
||||||
'files_sharing');
|
|
||||||
|
|
|
@ -1,230 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
|
||||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
||||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
||||||
*
|
|
||||||
* @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\Files_Sharing\API;
|
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
|
||||||
use OCA\FederatedFileSharing\DiscoveryManager;
|
|
||||||
use OCA\Files_Sharing\External\Manager;
|
|
||||||
|
|
||||||
class Remote {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get list of pending remote shares
|
|
||||||
*
|
|
||||||
* @param array $params empty
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function getOpenShares($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
return new \OC_OCS_Result($externalManager->getOpenShares());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accept a remote share
|
|
||||||
*
|
|
||||||
* @param array $params contains the shareID 'id' which should be accepted
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function acceptShare($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($externalManager->acceptShare((int) $params['id'])) {
|
|
||||||
return new \OC_OCS_Result();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the user has no notification for something that does not exist anymore.
|
|
||||||
$externalManager->processNotification((int) $params['id']);
|
|
||||||
|
|
||||||
return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decline a remote share
|
|
||||||
*
|
|
||||||
* @param array $params contains the shareID 'id' which should be declined
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function declineShare($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($externalManager->declineShare((int) $params['id'])) {
|
|
||||||
return new \OC_OCS_Result();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the user has no notification for something that does not exist anymore.
|
|
||||||
$externalManager->processNotification((int) $params['id']);
|
|
||||||
|
|
||||||
return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $share Share with info from the share_external table
|
|
||||||
* @return array enriched share info with data from the filecache
|
|
||||||
*/
|
|
||||||
private static function extendShareInfo($share) {
|
|
||||||
$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
|
|
||||||
$info = $view->getFileInfo($share['mountpoint']);
|
|
||||||
|
|
||||||
$share['mimetype'] = $info->getMimetype();
|
|
||||||
$share['mtime'] = $info->getMtime();
|
|
||||||
$share['permissions'] = $info->getPermissions();
|
|
||||||
$share['type'] = $info->getType();
|
|
||||||
$share['file_id'] = $info->getId();
|
|
||||||
|
|
||||||
return $share;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List accepted remote shares
|
|
||||||
*
|
|
||||||
* @param array $params
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function getShares($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
$shares = $externalManager->getAcceptedShares();
|
|
||||||
|
|
||||||
$shares = array_map('self::extendShareInfo', $shares);
|
|
||||||
|
|
||||||
return new \OC_OCS_Result($shares);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get info of a remote share
|
|
||||||
*
|
|
||||||
* @param array $params contains the shareID 'id'
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function getShare($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
$shareInfo = $externalManager->getShare($params['id']);
|
|
||||||
|
|
||||||
if ($shareInfo === false) {
|
|
||||||
return new \OC_OCS_Result(null, 404, 'share does not exist');
|
|
||||||
} else {
|
|
||||||
$shareInfo = self::extendShareInfo($shareInfo);
|
|
||||||
return new \OC_OCS_Result($shareInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unshare a remote share
|
|
||||||
*
|
|
||||||
* @param array $params contains the shareID 'id' which should be unshared
|
|
||||||
* @return \OC_OCS_Result
|
|
||||||
*/
|
|
||||||
public static function unshare($params) {
|
|
||||||
$discoveryManager = new DiscoveryManager(
|
|
||||||
\OC::$server->getMemCacheFactory(),
|
|
||||||
\OC::$server->getHTTPClientService()
|
|
||||||
);
|
|
||||||
$externalManager = new Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
Filesystem::getMountManager(),
|
|
||||||
Filesystem::getLoader(),
|
|
||||||
\OC::$server->getHTTPClientService(),
|
|
||||||
\OC::$server->getNotificationManager(),
|
|
||||||
$discoveryManager,
|
|
||||||
\OC_User::getUser()
|
|
||||||
);
|
|
||||||
|
|
||||||
$shareInfo = $externalManager->getShare($params['id']);
|
|
||||||
|
|
||||||
if ($shareInfo === false) {
|
|
||||||
return new \OC_OCS_Result(null, 404, 'Share does not exist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
|
|
||||||
|
|
||||||
if ($externalManager->removeShare($mountPoint) === true) {
|
|
||||||
return new \OC_OCS_Result(null);
|
|
||||||
} else {
|
|
||||||
return new \OC_OCS_Result(null, 403, 'Could not unshare');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -111,6 +111,7 @@ class Application extends App {
|
||||||
$uid
|
$uid
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
$container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Middleware
|
* Middleware
|
||||||
|
|
|
@ -0,0 +1,183 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
|
*
|
||||||
|
* @author Joas Schilling <coding@schilljs.com>
|
||||||
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||||
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
|
*
|
||||||
|
* @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\Files_Sharing\Controller;
|
||||||
|
|
||||||
|
use OCA\Files_Sharing\External\Manager;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||||
|
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||||
|
use OCP\AppFramework\OCSController;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
class RemoteController extends OCSController {
|
||||||
|
|
||||||
|
/** @var Manager */
|
||||||
|
private $externalManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Remote constructor.
|
||||||
|
*
|
||||||
|
* @param string $appName
|
||||||
|
* @param IRequest $request
|
||||||
|
* @param Manager $externalManager
|
||||||
|
*/
|
||||||
|
public function __construct($appName,
|
||||||
|
IRequest $request,
|
||||||
|
Manager $externalManager) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
|
||||||
|
$this->externalManager = $externalManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Get list of pending remote shares
|
||||||
|
*
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function getOpenShares() {
|
||||||
|
return new DataResponse($this->externalManager->getOpenShares());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Accept a remote share
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return DataResponse
|
||||||
|
* @throws OCSNotFoundException
|
||||||
|
*/
|
||||||
|
public function acceptShare($id) {
|
||||||
|
if ($this->externalManager->acceptShare($id)) {
|
||||||
|
return new DataResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the user has no notification for something that does not exist anymore.
|
||||||
|
$this->externalManager->processNotification($id);
|
||||||
|
|
||||||
|
throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Decline a remote share
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return DataResponse
|
||||||
|
* @throws OCSNotFoundException
|
||||||
|
*/
|
||||||
|
public function declineShare($id) {
|
||||||
|
if ($this->externalManager->declineShare($id)) {
|
||||||
|
return new DataResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the user has no notification for something that does not exist anymore.
|
||||||
|
$this->externalManager->processNotification($id);
|
||||||
|
|
||||||
|
throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $share Share with info from the share_external table
|
||||||
|
* @return array enriched share info with data from the filecache
|
||||||
|
*/
|
||||||
|
private static function extendShareInfo($share) {
|
||||||
|
$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
|
||||||
|
$info = $view->getFileInfo($share['mountpoint']);
|
||||||
|
|
||||||
|
$share['mimetype'] = $info->getMimetype();
|
||||||
|
$share['mtime'] = $info->getMTime();
|
||||||
|
$share['permissions'] = $info->getPermissions();
|
||||||
|
$share['type'] = $info->getType();
|
||||||
|
$share['file_id'] = $info->getId();
|
||||||
|
|
||||||
|
return $share;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* List accepted remote shares
|
||||||
|
*
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function getShares() {
|
||||||
|
$shares = $this->externalManager->getAcceptedShares();
|
||||||
|
$shares = array_map('self::extendShareInfo', $shares);
|
||||||
|
|
||||||
|
return new DataResponse($shares);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Get info of a remote share
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return DataResponse
|
||||||
|
* @throws OCSNotFoundException
|
||||||
|
*/
|
||||||
|
public function getShare($id) {
|
||||||
|
$shareInfo = $this->externalManager->getShare($id);
|
||||||
|
|
||||||
|
if ($shareInfo === false) {
|
||||||
|
throw new OCSNotFoundException('share does not exist');
|
||||||
|
} else {
|
||||||
|
$shareInfo = self::extendShareInfo($shareInfo);
|
||||||
|
return new DataResponse($shareInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* Unshare a remote share
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return DataResponse
|
||||||
|
* @throws OCSNotFoundException
|
||||||
|
* @throws OCSForbiddenException
|
||||||
|
*/
|
||||||
|
public function unshare($id) {
|
||||||
|
$shareInfo = $this->externalManager->getShare($id);
|
||||||
|
|
||||||
|
if ($shareInfo === false) {
|
||||||
|
throw new OCSNotFoundException('Share does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
|
||||||
|
|
||||||
|
if ($this->externalManager->removeShare($mountPoint) === true) {
|
||||||
|
return new DataResponse();
|
||||||
|
} else {
|
||||||
|
throw new OCSForbiddenException('Could not unshare');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue