summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-13 13:02:23 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-13 16:35:15 +0100
commitcbd3050f4c5d0c98cc627cfab5d1ab8b85f1ae7c (patch)
tree50e58fd40b41fc11f4d669591b9d816fe0e06716 /apps/files_sharing
parent67b7ebccd134d68329fae201669924118a4d98fc (diff)
downloadnextcloud-server-cbd3050f4c5d0c98cc627cfab5d1ab8b85f1ae7c.tar.gz
nextcloud-server-cbd3050f4c5d0c98cc627cfab5d1ab8b85f1ae7c.zip
[Share 2.0] Use full share id (providerId:shareId)
Now that we support multiple managers we communicate shares to the outside as 'providerId:shareId'. This makes sures that id's are unique when references from the OCS API. However, since we do not want to break the OCS API v1 we need to somewhat hack around this. When we switch to OCS API v2 (which we should when we support more custom providers). We will change the id to always be the fullShareId.
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/api/share20ocs.php31
-rw-r--r--apps/files_sharing/tests/api/share20ocstest.php20
2 files changed, 36 insertions, 15 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index f81eb071a37..c698dccefb8 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -142,10 +142,20 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function getShare($id) {
+ // Try both our default, and our federated provider..
+ $share = null;
+
+ // First check if it is an internal share.
try {
- $share = $this->shareManager->getShareById($id);
+ $share = $this->shareManager->getShareById('ocinternal:'.$id);
} catch (\OC\Share20\Exception\ShareNotFound $e) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
+ // Ignore for now
+ //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
+ }
+
+ if ($share === null) {
+ //For now federated shares are handled by the old endpoint.
+ return \OCA\Files_Sharing\API\Local::getShare(['id' => $id]);
}
if ($this->canAccessShare($share)) {
@@ -163,18 +173,19 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function deleteShare($id) {
+ // Try both our default and our federated provider
+ $share = null;
+
try {
- $share = $this->shareManager->getShareById($id);
+ $share = $this->shareManager->getShareById('ocinternal:' . $id);
} catch (\OC\Share20\Exception\ShareNotFound $e) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
+ //Ignore for now
+ //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
}
- /*
- * FIXME
- * User the old code path for remote shares until we have our remoteshareprovider
- */
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
- \OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]);
+ // Could not find the share as internal share... maybe it is a federated share
+ if ($share === null) {
+ return \OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]);
}
if (!$this->canAccessShare($share)) {
diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php
index b594d253eb2..81166b9e3c4 100644
--- a/apps/files_sharing/tests/api/share20ocstest.php
+++ b/apps/files_sharing/tests/api/share20ocstest.php
@@ -82,7 +82,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
- ->with(42)
+ ->with('ocinternal:42')
->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
$expected = new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
@@ -95,7 +95,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
- ->with(42)
+ ->with('ocinternal:42')
->willReturn($share);
$this->shareManager
->expects($this->once())
@@ -114,7 +114,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
- ->with(42)
+ ->with('ocinternal:42')
->willReturn($share);
$this->shareManager
->expects($this->once())
@@ -125,16 +125,20 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertEquals($expected, $this->ocs->deleteShare(42));
}
+ /*
+ * FIXME: Enable once we have a federated Share Provider
+
public function testGetGetShareNotExists() {
$this->shareManager
->expects($this->once())
->method('getShareById')
- ->with(42)
+ ->with('ocinternal:42')
->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
$expected = new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
$this->assertEquals($expected, $this->ocs->getShare(42));
}
+ */
public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $token=null,
@@ -155,6 +159,12 @@ class Share20OCSTest extends \Test\TestCase {
$share->method('getToken')->willReturn($token);
$share->method('getPassword')->willReturn($password);
+ if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
+ $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
+ $shareType === \OCP\Share::SHARE_TYPE_LINK) {
+ $share->method('getFullId')->willReturn('ocinternal:'.$id);
+ }
+
return $share;
}
@@ -345,7 +355,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
- ->with($share->getId())
+ ->with($share->getFullId())
->willReturn($share);
$userFolder = $this->getMock('OCP\Files\Folder');