summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/api/share20ocs.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-03-07 16:10:27 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-03-07 16:14:57 +0100
commit218d04214289784c56037b6756bb64c436c94172 (patch)
tree88ad56b0033834fb587613cdd0f0ba5cbaae104a /apps/files_sharing/api/share20ocs.php
parent19dc02b8e0dceda97a83739b62fd8e4b67ac1b78 (diff)
downloadnextcloud-server-218d04214289784c56037b6756bb64c436c94172.tar.gz
nextcloud-server-218d04214289784c56037b6756bb64c436c94172.zip
Move common code to function
The code to get a share by id is somewhat messy. And was duplicated. Now this is done is a separate function
Diffstat (limited to 'apps/files_sharing/api/share20ocs.php')
-rw-r--r--apps/files_sharing/api/share20ocs.php87
1 files changed, 31 insertions, 56 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index 4abd821f2ae..ef7b79669e3 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -155,27 +155,10 @@ 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('ocinternal:'.$id);
+ $share = $this->getShareById($id);
} catch (ShareNotFound $e) {
- // Ignore for now
- //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- if ($share === null) {
- if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- try {
- $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
- } catch (ShareNotFound $e) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
+ return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
}
if ($this->canAccessShare($share)) {
@@ -198,26 +181,10 @@ class Share20OCS {
*/
public function deleteShare($id) {
// Try both our default and our federated provider
- $share = null;
-
try {
- $share = $this->shareManager->getShareById('ocinternal:' . $id);
+ $share = $this->getShareById($id);
} catch (ShareNotFound $e) {
- //Ignore for now
- //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- // Could not find the share as internal share... maybe it is a federated share
- if ($share === null) {
- if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- try {
- $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
- } catch (ShareNotFound $e) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
+ return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
}
if (!$this->canAccessShare($share)) {
@@ -505,27 +472,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function updateShare($id) {
- // Try both our default and our federated provider
- $share = null;
-
try {
- $share = $this->shareManager->getShareById('ocinternal:' . $id);
+ $share = $this->getShareById($id);
} catch (ShareNotFound $e) {
- //Ignore for now
- //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- // Could not find the share as internal share... maybe it is a federated share
- if ($share === null) {
- if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
-
- try {
- $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
- } catch (ShareNotFound $e) {
- return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
- }
+ return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
}
if (!$this->canAccessShare($share)) {
@@ -688,4 +638,29 @@ class Share20OCS {
return $date;
}
+
+ /**
+ * Since we have multiple providers but the OCS Share API v1 does
+ * not support this we need to check all backends.
+ *
+ * @param string $id
+ * @return \OCP\Share\IShare
+ * @throws ShareNotFound
+ */
+ private function getShareById($id) {
+ $share = null;
+
+ // First check if it is an internal share.
+ try {
+ $share = $this->shareManager->getShareById('ocinternal:'.$id);
+ } catch (ShareNotFound $e) {
+ if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
+ throw new ShareNotFound();
+ }
+
+ $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
+ }
+
+ return $share;
+ }
}