summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-08 09:41:20 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-08 09:41:20 +0100
commit2ebf512412401fd291f96e24505b693812433c3a (patch)
tree6a16481b68d437e2299fc80f50e8372d47048c0a /apps
parent21b6bd321d5c8b2757fbd6040d7186226dbf6e48 (diff)
parentb1dae2a4b9a8b5a4f0d39bf968b750b183b41e7e (diff)
downloadnextcloud-server-2ebf512412401fd291f96e24505b693812433c3a.tar.gz
nextcloud-server-2ebf512412401fd291f96e24505b693812433c3a.zip
Merge pull request #22915 from owncloud/cleanup_ocs_share_api
Cleanup OCS Share Api
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/api/share20ocs.php94
1 files changed, 37 insertions, 57 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index 4abd821f2ae..0c9e5473d9c 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -33,6 +33,11 @@ use OCP\Share\IManager;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\Exceptions\GenericShareException;
+/**
+ * Class Share20OCS
+ *
+ * @package OCA\Files_Sharing\API
+ */
class Share20OCS {
/** @var IManager */
@@ -155,27 +160,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 +186,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)) {
@@ -354,7 +326,7 @@ class Share20OCS {
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
- return new \OC_OCS_Result(null, 403, 'Sharing '.$path.' failed, because the backend does not allow shares from type '.$shareType);
+ return new \OC_OCS_Result(null, 403, 'Sharing '.$path->getPath().' failed, because the backend does not allow shares from type '.$shareType);
}
$share->setSharedWith($shareWith);
@@ -505,27 +477,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 +643,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;
+ }
}