summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/api
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-01 15:05:04 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-03 09:30:49 +0200
commit2118713477207b28d2d2b3abb95467c61fac69ec (patch)
treea114f7d45e4bc006570075a3c95ca3c1b6b329fc /apps/files_sharing/api
parentdf303b910a3f4f7e836f9ab7630426a25456e77a (diff)
downloadnextcloud-server-2118713477207b28d2d2b3abb95467c61fac69ec.tar.gz
nextcloud-server-2118713477207b28d2d2b3abb95467c61fac69ec.zip
Add OCS api to get, accept and decline remote shares
Diffstat (limited to 'apps/files_sharing/api')
-rw-r--r--apps/files_sharing/api/local.php5
-rw-r--r--apps/files_sharing/api/remote.php91
2 files changed, 95 insertions, 1 deletions
diff --git a/apps/files_sharing/api/local.php b/apps/files_sharing/api/local.php
index 1a943891691..b0ddba9fa11 100644
--- a/apps/files_sharing/api/local.php
+++ b/apps/files_sharing/api/local.php
@@ -260,6 +260,7 @@ class Local {
return new \OC_OCS_Result(null, 400, "please specify a file or folder path");
}
$itemSource = self::getFileId($path);
+ $itemSourceName = $itemSource;
$itemType = self::getItemType($path);
if($itemSource === null) {
@@ -272,6 +273,7 @@ class Local {
switch($shareType) {
case \OCP\Share::SHARE_TYPE_REMOTE:
$shareWith = rtrim($shareWith, '/');
+ $itemSourceName = basename($path);
case \OCP\Share::SHARE_TYPE_USER:
case \OCP\Share::SHARE_TYPE_GROUP:
$permissions = isset($_POST['permissions']) ? (int)$_POST['permissions'] : 31;
@@ -303,7 +305,8 @@ class Local {
$itemSource,
$shareType,
$shareWith,
- $permissions
+ $permissions,
+ $itemSourceName
);
} catch (HintException $e) {
return new \OC_OCS_Result(null, 400, $e->getHint());
diff --git a/apps/files_sharing/api/remote.php b/apps/files_sharing/api/remote.php
new file mode 100644
index 00000000000..f6cb0a29d8b
--- /dev/null
+++ b/apps/files_sharing/api/remote.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @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\Files_Sharing\External\Manager;
+
+class Remote {
+
+ /**
+ * Accept a remote share
+ *
+ * @param array $params contains the shareID 'id' which should be accepted
+ * @return \OC_OCS_Result
+ */
+ public static function getOpenShares($params) {
+ $externalManager = new Manager(
+ \OC::$server->getDatabaseConnection(),
+ Filesystem::getMountManager(),
+ Filesystem::getLoader(),
+ \OC::$server->getHTTPHelper(),
+ \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) {
+ $externalManager = new Manager(
+ \OC::$server->getDatabaseConnection(),
+ Filesystem::getMountManager(),
+ Filesystem::getLoader(),
+ \OC::$server->getHTTPHelper(),
+ \OC_User::getUser()
+ );
+
+ if ($externalManager->acceptShare($params['id'])) {
+ return new \OC_OCS_Result();
+ }
+
+ 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) {
+ $externalManager = new Manager(
+ \OC::$server->getDatabaseConnection(),
+ Filesystem::getMountManager(),
+ Filesystem::getLoader(),
+ \OC::$server->getHTTPHelper(),
+ \OC_User::getUser()
+ );
+
+ if ($externalManager->declineShare($params['id'])) {
+ return new \OC_OCS_Result();
+ }
+
+ return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
+ }
+
+}