Merge pull request #22915 from owncloud/cleanup_ocs_share_api

Cleanup OCS Share Api
This commit is contained in:
Thomas Müller 2016-03-08 09:41:20 +01:00
commit 2ebf512412
1 changed files with 37 additions and 57 deletions

View File

@ -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;
}
}