From 3666c34a197adb75c6b488f877d5b3b2279d0dea Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 3 Dec 2015 10:51:41 +0100 Subject: [Sharing 2.0] Start with getShares --- apps/files_sharing/api/ocssharewrapper.php | 2 +- apps/files_sharing/api/share20ocs.php | 56 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'apps') 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..56cc50d34fa 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -327,6 +327,62 @@ 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); + //TODO add federated provider + + $shares = array_merge($userShares, $groupShares); + + $formatted = []; + foreach ($shares as $share) { + $formatted[] = $this->formatShare($share); + } + + return new \OC_OCS_Result($formatted); + } + + 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 ($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 -- cgit v1.2.3 From 0a9cd91e1d9baa8247fc2bbe1d02ede8340f2906 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 19 Jan 2016 14:35:16 +0100 Subject: [Share 2.0] Add subfiles=x --- apps/files_sharing/api/share20ocs.php | 44 ++++++++++++++++++++++++++++ lib/private/share20/defaultshareprovider.php | 2 +- lib/private/share20/manager.php | 12 -------- 3 files changed, 45 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 56cc50d34fa..2190582f3f4 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 4d1a72f6a13..e3e5909e901 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 7d454b26f00..3935307b977 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 * -- cgit v1.2.3 From 3a582e88e599d53108bcd7a299a56202513f3bd5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 20 Jan 2016 14:17:25 +0100 Subject: Comments from Vincent --- apps/files_sharing/api/share20ocs.php | 8 +++----- lib/private/share20/defaultshareprovider.php | 8 ++++---- lib/private/share20/ishareprovider.php | 8 ++++---- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 2190582f3f4..c2ff94db790 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -330,7 +330,6 @@ class Share20OCS { 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); - //TODO add federated provider $shares = array_merge($userShares, $groupShares); @@ -355,12 +354,11 @@ class Share20OCS { /** @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)); + $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 - $shares = array_merge($shares, $userShares, $groupShares, $linkShares); } $formatted = []; diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 596addb1e67..e0b437bbcc7 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -367,8 +367,8 @@ class DefaultShareProvider implements IShareProvider { /** * Get shared with the given user * - * @param IUser $user - * @param int $shareType + * @param IUser $user get shares where this user is the recipient + * @param int $shareType \OCP\Share::SHARE_TYPE_USER or \OCP\Share::SHARE_TYPE_GROUP are supported * @param int $limit The maximum number of shares, -1 for all * @param int $offset * @return IShare[] @@ -450,7 +450,7 @@ class DefaultShareProvider implements IShareProvider { */ $shares = array_map([$this, 'resolveGroupShare'], $shares); } else { - throw new BackendError(); + throw new BackendError('Invalid backend'); } @@ -585,7 +585,7 @@ class DefaultShareProvider implements IShareProvider { * Thus if the user moved their group share make sure this is properly reflected here. * * @param Share $share - * @return Share + * @return Share Returns the updated share if one was found else return the original share. */ private function resolveGroupShare(Share $share) { $qb = $this->dbConn->getQueryBuilder(); diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php index a5a9d3b6708..36d0f10c7f1 100644 --- a/lib/private/share20/ishareprovider.php +++ b/lib/private/share20/ishareprovider.php @@ -62,13 +62,13 @@ interface IShareProvider { * * @param IUser $user * @param int $shareType - * @param \OCP\Files\File|\OCP\Files\Folder $path - * @param bool $reshares + * @param \OCP\Files\File|\OCP\Files\Folder $node + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator * @param int $limit The maximum number of shares to be returned, -1 for all shares * @param int $offset * @return Share[] */ - public function getSharesBy(IUser $user, $shareType, $path, $reshares, $limit, $offset); + public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset); /** * Get share by id @@ -98,7 +98,7 @@ interface IShareProvider { /** * Get shared with the given user * - * @param IUser $user + * @param IUser $user get shares where this user is the recipient * @param int $shareType * @param int $limit The max number of entries returned, -1 for all * @param int $offset -- cgit v1.2.3