diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 07:58:36 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 07:58:36 +0100 |
commit | 766ba1cd5fac2019e73810b157bbf0bd3fdab1cf (patch) | |
tree | 246f3f59a170207039c41c2d68d8491d1ea0d686 /apps | |
parent | b74cdb7da3bd7e3e91b674a32e197d8c3d432ea8 (diff) | |
parent | 658959592d637c3dc8f8bfac8cba962273c72f4b (diff) | |
download | nextcloud-server-766ba1cd5fac2019e73810b157bbf0bd3fdab1cf.tar.gz nextcloud-server-766ba1cd5fac2019e73810b157bbf0bd3fdab1cf.zip |
Merge pull request #21532 from owncloud/share2.0_getShares
[Share 2.0] get shares
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/api/ocssharewrapper.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/api/share20ocs.php | 98 |
2 files changed, 99 insertions, 1 deletions
diff --git a/apps/files_sharing/api/ocssharewrapper.php b/apps/files_sharing/api/ocssharewrapper.php index a186a34cf6a..cc52d478615 100644 --- a/apps/files_sharing/api/ocssharewrapper.php +++ b/apps/files_sharing/api/ocssharewrapper.php @@ -37,7 +37,7 @@ class OCSShareWrapper { } public function getAllShares($params) { - return \OCA\Files_Sharing\API\Local::getAllShares($params); + return $this->getShare20OCS()->getShares(); } public function createShare() { diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index e4cc50d9c1a..c2ff94db790 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -327,6 +327,104 @@ class Share20OCS { return new \OC_OCS_Result($share); } + private function getSharedWithMe() { + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, -1, 0); + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, -1, 0); + + $shares = array_merge($userShares, $groupShares); + + $formatted = []; + foreach ($shares as $share) { + $formatted[] = $this->formatShare($share); + } + + return new \OC_OCS_Result($formatted); + } + + /** + * @param \OCP\Files\Folder $folder + * @return \OC_OCS_Result + */ + private function getSharesInDir($folder) { + if (!($folder instanceof \OCP\Files\Folder)) { + return new \OC_OCS_Result(null, 400, "not a directory"); + } + + $nodes = $folder->getDirectoryListing(); + /** @var IShare[] $shares */ + $shares = []; + foreach ($nodes as $node) { + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); + //TODO: Add federated shares + + } + + $formatted = []; + foreach ($shares as $share) { + $formatted[] = $this->formatShare($share); + } + + return new \OC_OCS_Result($formatted); + } + + /** + * The getShares function. + * + * - Get shares by the current user + * - Get shares by the current user and reshares (?reshares=true) + * - Get shares with the current user (?shared_with_me=true) + * - Get shares for a specific path (?path=...) + * - Get all shares in a folder (?subfiles=true&path=..) + * + * @return \OC_OCS_Result + */ + public function getShares() { + $sharedWithMe = $this->request->getParam('shared_with_me', null); + $reshares = $this->request->getParam('reshares', null); + $subfiles = $this->request->getParam('subfiles'); + $path = $this->request->getParam('path', null); + + if ($sharedWithMe === 'true') { + return $this->getSharedWithMe(); + } + + if ($path !== null) { + $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); + try { + $path = $userFolder->get($path); + } catch (\OCP\Files\NotFoundException $e) { + return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist'); + } + } + + if ($subfiles === 'true') { + return $this->getSharesInDir($path); + } + + if ($reshares === 'true') { + $reshares = true; + } else { + $reshares = false; + } + + // Get all shares + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); + //TODO: Add federated shares + + $shares = array_merge($userShares, $groupShares, $linkShares); + + $formatted = []; + foreach ($shares as $share) { + $formatted[] = $this->formatShare($share); + } + + return new \OC_OCS_Result($formatted); + } + /** * @param IShare $share * @return bool |