diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 56cc50d34f..2190582f3f 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -342,6 +342,46 @@ class Share20OCS { 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) { + $userShares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); + $groupShares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); + $linkShares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); + //TODO: Add federated shares + + $shares = array_merge($shares, $userShares, $groupShares, $linkShares); + } + + $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); @@ -361,6 +401,10 @@ class Share20OCS { } } + if ($subfiles === 'true') { + return $this->getSharesInDir($path); + } + if ($reshares === 'true') { $reshares = true; } else { diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 4d1a72f6a1..e3e5909e90 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -279,9 +279,9 @@ class DefaultShareProvider implements IShareProvider { if ($limit !== -1) { $qb->setMaxResults($limit); - $qb->setFirstResult($offset); } + $qb->setFirstResult($offset); $qb->orderBy('id'); $cursor = $qb->execute(); diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 7d454b26f0..3935307b97 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -678,18 +678,6 @@ class Manager { public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { } - /** - * Get all shares that are shared with the current user - * - * @param int $shareType - * @param int $page - * @param int $perPage - * - * @return Share[] - */ - public function getSharedWithMe($shareType = null, $page=0, $perPage=50) { - } - /** * Get the share by token possible with password *