diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2015-09-26 09:55:59 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2015-10-02 07:40:04 +0200 |
commit | 7310c4166ab3f5f441a29af6e4c74b9222b13df7 (patch) | |
tree | b0b3bd8399286c8bf4124cd386a2c069aca85b72 /apps/files_sharing | |
parent | 4a620211412f9cf1b2fc9af8fd9edfbb73eb76ae (diff) | |
download | nextcloud-server-7310c4166ab3f5f441a29af6e4c74b9222b13df7.tar.gz nextcloud-server-7310c4166ab3f5f441a29af6e4c74b9222b13df7.zip |
Added '../remote_shares' endpoint
* list incoming remote shares at 'remote_shares'
* get per share info at 'remote_shares/<ID>'
* delete remote share with a DELETE to 'remote_shares/<ID>'
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/api/remote.php | 79 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/routes.php | 16 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 13 |
3 files changed, 104 insertions, 4 deletions
diff --git a/apps/files_sharing/api/remote.php b/apps/files_sharing/api/remote.php index 0f6d2dc265a..ab87820611c 100644 --- a/apps/files_sharing/api/remote.php +++ b/apps/files_sharing/api/remote.php @@ -27,9 +27,9 @@ use OCA\Files_Sharing\External\Manager; class Remote { /** - * Accept a remote share + * Get list of pending remote shares * - * @param array $params contains the shareID 'id' which should be accepted + * @param array $params empty * @return \OC_OCS_Result */ public static function getOpenShares($params) { @@ -90,4 +90,79 @@ class Remote { return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); } + + /** + * List accepted remote shares + * + * @param array $params + * @return \OC_OCS_Result + */ + public static function getShares($params) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \OC_User::getUser() + ); + + return new \OC_OCS_Result($externalManager->getAcceptedShares()); + } + + /** + * Get info of a remote share + * + * @param array $params contains the shareID 'id' + * @return \OC_OCS_Result + */ + public static function getShare($params) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \OC_User::getUser() + ); + + $shareInfo = $externalManager->getShare($params['id']); + + if ($shareInfo === false) { + return new \OC_OCS_Result(null, 404, 'share does not exist'); + } else { + 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) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \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'); + } + } } diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 8f7dc72f5d9..063b4d70a15 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -102,6 +102,22 @@ API::register('delete', array('\OCA\Files_Sharing\API\Remote', 'declineShare'), 'files_sharing'); +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/{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'); + + $sharees = new \OCA\Files_Sharing\API\Sharees(\OC::$server->getGroupManager(), \OC::$server->getUserManager(), \OC::$server->getContactsManager(), diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 8552b2fbd34..78d9581524d 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -180,9 +180,9 @@ class Manager { * @param int $id share id * @return mixed share of false */ - private function getShare($id) { + public function getShare($id) { $getShare = $this->connection->prepare(' - SELECT `remote`, `remote_id`, `share_token`, `name` + SELECT * FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); $result = $getShare->execute(array($id, $this->uid)); @@ -407,6 +407,15 @@ class Manager { } /** + * return a list of shares wich are accepted by the user + * + * @return array list of accepted server-to-server shares + */ + public function getAcceptedShares() { + return $this->getShares(true); + } + + /** * return a list of shares for the user * * @param bool|null $accepted True for accepted only, |