diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-02 12:13:36 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-02 12:13:36 +0200 |
commit | daf9a63d43c9a7975b17ebee11e3fb92c431d3d7 (patch) | |
tree | c5997508f47241a977c00cee9a8c6b7debe42f5d /apps | |
parent | aaabe356b59b32a384514c5f8940119d9760cc6f (diff) | |
parent | c924b6740a523f45d0947a840c6934491a8f699e (diff) | |
download | nextcloud-server-daf9a63d43c9a7975b17ebee11e3fb92c431d3d7.tar.gz nextcloud-server-daf9a63d43c9a7975b17ebee11e3fb92c431d3d7.zip |
Merge pull request #19386 from owncloud/ocs_shareapi_extenstion
OCS endpoint to list remote shares
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/api/remote.php | 101 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/routes.php | 20 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 17 |
3 files changed, 131 insertions, 7 deletions
diff --git a/apps/files_sharing/api/remote.php b/apps/files_sharing/api/remote.php index 0f6d2dc265a..76f9babcd19 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,101 @@ class Remote { 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 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($shares['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) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \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) { + $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 { + $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) { + $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 375124cb730..3794df37992 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -89,19 +89,35 @@ API::register('delete', 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/{id}', + '/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/{id}', + '/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'); + + $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..2ba02f40d2f 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 `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` 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, @@ -415,7 +424,9 @@ class Manager { * @return array list of open server-to-server shares */ private function getShares($accepted) { - $query = 'SELECT * FROM `*PREFIX*share_external` WHERE `user` = ?'; + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` + FROM `*PREFIX*share_external` + WHERE `user` = ?'; $parameters = [$this->uid]; if (!is_null($accepted)) { $query .= ' AND `accepted` = ?'; |