Skip to content

Commit

Permalink
Added '../remote_shares' endpoint
Browse files Browse the repository at this point in the history
list incoming remote shares
  • Loading branch information
rullzer committed Sep 28, 2015
1 parent cbf8ee5 commit 8a9cec6
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
79 changes: 77 additions & 2 deletions apps/files_sharing/api/remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
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) {
Expand Down Expand Up @@ -90,4 +90,79 @@ public static function declineShare($params) {

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');
}
}
}
16 changes: 16 additions & 0 deletions apps/files_sharing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ function() {
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(),
Expand Down
13 changes: 11 additions & 2 deletions apps/files_sharing/lib/external/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ private function setupMounts() {
* @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));
Expand Down Expand Up @@ -406,6 +406,15 @@ public function getOpenShares() {
return $this->getShares(false);
}

/**
* 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
*
Expand Down

0 comments on commit 8a9cec6

Please sign in to comment.