From 3666c34a197adb75c6b488f877d5b3b2279d0dea Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 3 Dec 2015 10:51:41 +0100 Subject: [PATCH 1/8] [Sharing 2.0] Start with getShares --- apps/files_sharing/api/ocssharewrapper.php | 2 +- apps/files_sharing/api/share20ocs.php | 56 ++++++++++++ lib/private/share20/defaultshareprovider.php | 92 ++++++++++++++++++-- lib/private/share20/ishareprovider.php | 10 ++- lib/private/share20/manager.php | 39 +++++++-- 5 files changed, 185 insertions(+), 14 deletions(-) diff --git a/apps/files_sharing/api/ocssharewrapper.php b/apps/files_sharing/api/ocssharewrapper.php index a186a34cf6..cc52d47861 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 e4cc50d9c1..56cc50d34f 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 diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index d47919d21a..d296760412 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -240,15 +240,56 @@ class DefaultShareProvider implements IShareProvider { } /** - * Get all shares by the given user + * Get all shares by the given user. Sharetype and path can be used to filter. * * @param IUser $user * @param int $shareType + * @param \OCP\Files\File|\OCP\Files\Folder $path + * @param bool $reshares + * @param int $limit The maximum number of shares to be returned, -1 for all shares * @param int $offset - * @param int $limit * @return Share[] */ - public function getShares(IUser $user, $shareType, $offset, $limit) { + public function getSharesBy(IUser $user, $shareType, $path, $reshares, $limit, $offset) { + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('*') + ->from('share'); + + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); + + /** + * Reshares for this user are shares where they are the owner. + */ + if ($reshares === false) { + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID()))); + } else { + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())) + ) + ); + } + + if ($path !== null) { + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))); + } + + if ($limit !== -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($offset); + } + + $qb->orderBy('id'); + + $cursor = $qb->execute(); + $shares = []; + while($data = $cursor->fetch()) { + $shares[] = $this->createShare($data); + } + $cursor->closeCursor(); + + return $shares; } /** @@ -326,9 +367,50 @@ class DefaultShareProvider implements IShareProvider { * * @param IUser $user * @param int $shareType - * @param Share + * @param int $limit The maximum number of shares, -1 for all + * @param int $offset + * @return IShare[] + * @throws BackendError */ - public function getSharedWithMe(IUser $user, $shareType = null) { + public function getSharedWith(IUser $user, $shareType, $limit, $offset) { + $shares = []; + + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { + //Get shares directly w ith me + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('*') + ->from('share'); + + // Order by id + $qb->orderBy('id'); + + // Set limit and offset + if ($limit !== -1) { + $qb->setMaxResults($limit); + } + $qb->setFirstResult($offset); + + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID()))); + + $cursor = $qb->execute(); + + while($data = $cursor->fetch()) { + $shares[] = $this->createShare($data); + } + $cursor->closeCursor(); + + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + //TODO This can certianly be optimized at some point. But for now keep it simple and working + + //TODO Get group shares for group of $user + //TODO Filter out user modified group shares and replace but keep original share stuff + } else { + throw new BackendError(); + } + + + return $shares; } /** diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php index 81770a4587..a5a9d3b670 100644 --- a/lib/private/share20/ishareprovider.php +++ b/lib/private/share20/ishareprovider.php @@ -62,11 +62,13 @@ interface IShareProvider { * * @param IUser $user * @param int $shareType + * @param \OCP\Files\File|\OCP\Files\Folder $path + * @param bool $reshares + * @param int $limit The maximum number of shares to be returned, -1 for all shares * @param int $offset - * @param int $limit * @return Share[] */ - public function getShares(IUser $user, $shareType, $offset, $limit); + public function getSharesBy(IUser $user, $shareType, $path, $reshares, $limit, $offset); /** * Get share by id @@ -98,9 +100,11 @@ interface IShareProvider { * * @param IUser $user * @param int $shareType + * @param int $limit The max number of entries returned, -1 for all + * @param int $offset * @param Share */ - public function getSharedWithMe(IUser $user, $shareType = null); + public function getSharedWith(IUser $user, $shareType, $limit, $offset); /** * Get a share by token diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 2be8fb5174..7d454b26f0 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -605,14 +605,43 @@ class Manager { \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); } + /** - * Retrieve all shares by the current user + * Get shares shared by (initiated) by the provided user. * - * @param int $page - * @param int $perPage - * @return Share[] + * @param IUser $user + * @param int $shareType + * @param \OCP\Files\File|\OCP\Files\Folder $path + * @param bool $reshares + * @param int $limit The maximum number of returned results, -1 for all results + * @param int $offset + * @return IShare[] */ - public function getShares($page=0, $perPage=50) { + public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { + if ($path !== null && + !($path instanceof \OCP\Files\File) && + !($path instanceof \OCP\Files\Folder)) { + throw new \InvalidArgumentException('invalid path'); + } + + $provider = $this->factory->getProviderForType($shareType); + + return $provider->getSharesBy($user, $shareType, $path, $reshares, $limit, $offset); + } + + /** + * Get shares shared with $user. + * + * @param IUser $user + * @param int $shareType + * @param int $limit The maximum number of shares returned, -1 for all + * @param int $offset + * @return IShare[] + */ + public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) { + $provider = $this->factory->getProviderForType($shareType); + + return $provider->getSharedWith($user, $shareType, $limit, $offset); } /** From 01aa03341aa74b1c0b9493f7dce6509dbaa24ebd Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 15 Dec 2015 10:38:34 +0100 Subject: [PATCH 2/8] Renable intergration test --- build/integration/features/sharing-v1.feature | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 1287a2daf8..020cb0e032 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -231,23 +231,20 @@ Feature: sharing And User "user2" should be included in the response And User "user3" should not be included in the response -# Skip this test for now. Since the new shares do not create reshares -# TODO enable when getshares is updated -# -# Scenario: getting all shares of a file with reshares -# Given user "user0" exists -# And user "user1" exists -# And user "user2" exists -# And user "user3" exists -# And file "textfile0.txt" of user "user0" is shared with user "user1" -# And file "textfile0.txt" of user "user1" is shared with user "user2" -# And As an "user0" -# When sending "GET" to "/apps/files_sharing/api/v1/shares?reshares=true&path=textfile0.txt" -# Then the OCS status code should be "100" -# And the HTTP status code should be "200" -# And User "user1" should be included in the response -# And User "user2" should be included in the response -# And User "user3" should not be included in the response + Scenario: getting all shares of a file with reshares + Given user "user0" exists + And user "user1" exists + And user "user2" exists + And user "user3" exists + And file "textfile0.txt" of user "user0" is shared with user "user1" + And file "textfile0 (2).txt" of user "user1" is shared with user "user2" + And As an "user0" + When sending "GET" to "/apps/files_sharing/api/v1/shares?reshares=true&path=textfile0.txt" + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And User "user1" should be included in the response + And User "user2" should be included in the response + And User "user3" should not be included in the response Scenario: getting share info of a share Given user "user0" exists From 0c9f881e7d764ebf7c858ca894f3086091afb5c0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 19 Jan 2016 13:55:51 +0100 Subject: [PATCH 3/8] [Share 2.0] Resolve group shares --- lib/private/share20/defaultshareprovider.php | 75 ++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index d296760412..4d1a72f6a1 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -32,6 +32,8 @@ use OCP\Files\IRootFolder; use OCP\IDBConnection; use OCP\Files\Node; +use Doctrine\DBAL\Connection; + /** * Class DefaultShareProvider * @@ -373,10 +375,11 @@ class DefaultShareProvider implements IShareProvider { * @throws BackendError */ public function getSharedWith(IUser $user, $shareType, $limit, $offset) { + /** @var Share[] $shares */ $shares = []; if ($shareType === \OCP\Share::SHARE_TYPE_USER) { - //Get shares directly w ith me + //Get shares directly with this user $qb = $this->dbConn->getQueryBuilder(); $qb->select('*') ->from('share'); @@ -401,10 +404,47 @@ class DefaultShareProvider implements IShareProvider { $cursor->closeCursor(); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { - //TODO This can certianly be optimized at some point. But for now keep it simple and working + $allGroups = $this->groupManager->getUserGroups($user); - //TODO Get group shares for group of $user - //TODO Filter out user modified group shares and replace but keep original share stuff + $start = 0; + while(true) { + $groups = array_slice($allGroups, $start, 100); + $start += 100; + + if ($groups === []) { + break; + } + + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('*') + ->from('share') + ->orderBy('id') + ->setFirstResult(0); + + if ($limit !== -1) { + $qb->setMaxResults($limit); + } + + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); + + $qb->where('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)); + $qb->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( + $groups, + Connection::PARAM_STR_ARRAY + ))); + + $cursor = $qb->execute(); + while($data = $cursor->fetch()) { + $shares[] = $this->createShare($data); + } + $cursor->closeCursor(); + + /* + * Resolve all group shares to user specific shares + * TODO: Optmize this! + */ + $shares = array_map([$this, 'resolveGroupShare'], $shares); + } } else { throw new BackendError(); } @@ -536,4 +576,31 @@ class DefaultShareProvider implements IShareProvider { return $nodes[0]; } + /** + * Resolve a group share to a user specific share + * Thus if the user moved their group share make sure this is properly reflected here. + * + * @param Share $share + * @return Share + */ + private function resolveGroupShare(Share $share) { + $qb = $this->dbConn->getQueryBuilder(); + + $stmt = $qb->select('*') + ->from('share') + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) + ->execute(); + + $data = $stmt->fetch(); + $stmt->closeCursor(); + + if ($data !== false) { + $share->setPermissions($data['permissions']); + $share->setTarget($data['file_target']); + } + + return $share; + } + } \ No newline at end of file From 247b2ee0aa08664885aef2580b21c8b248b4424b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 19 Jan 2016 13:57:32 +0100 Subject: [PATCH 4/8] Add intergration test for shared_with me and group shares --- build/integration/features/sharing-v1.feature | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 020cb0e032..dedf2c388f 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -313,6 +313,19 @@ Feature: sharing And the HTTP status code should be "200" And last share_id is included in the answer + Scenario: Sharee can see the group share + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group0" exists + And user "user1" belongs to group "group0" + And file "textfile0.txt" of user "user0" is shared with group "group0" + And As an "user1" + When sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true" + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And last share_id is included in the answer + Scenario: User is not allowed to reshare file As an "admin" Given user "user0" exists From 0a9cd91e1d9baa8247fc2bbe1d02ede8340f2906 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 19 Jan 2016 14:35:16 +0100 Subject: [PATCH 5/8] [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(-) 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 * From 9b5ea18ce56fef3de8403be97e0961dc7a082370 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 20 Jan 2016 14:07:56 +0100 Subject: [PATCH 6/8] Add Unit tests for the default share provider --- lib/private/share20/defaultshareprovider.php | 30 +- .../lib/share20/defaultshareprovidertest.php | 438 ++++++++++++++++-- 2 files changed, 412 insertions(+), 56 deletions(-) diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index e3e5909e90..596addb1e6 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -246,13 +246,13 @@ class DefaultShareProvider implements 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) { $qb = $this->dbConn->getQueryBuilder(); $qb->select('*') ->from('share'); @@ -273,8 +273,8 @@ class DefaultShareProvider implements IShareProvider { ); } - if ($path !== null) { - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))); + if ($node !== null) { + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); } if ($limit !== -1) { @@ -422,12 +422,12 @@ class DefaultShareProvider implements IShareProvider { ->setFirstResult(0); if ($limit !== -1) { - $qb->setMaxResults($limit); + $qb->setMaxResults($limit - count($shares)); } $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); - $qb->where('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)); + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))); $qb->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( $groups, Connection::PARAM_STR_ARRAY @@ -435,16 +435,20 @@ class DefaultShareProvider implements IShareProvider { $cursor = $qb->execute(); while($data = $cursor->fetch()) { + if ($offset > 0) { + $offset--; + continue; + } $shares[] = $this->createShare($data); } $cursor->closeCursor(); - - /* - * Resolve all group shares to user specific shares - * TODO: Optmize this! - */ - $shares = array_map([$this, 'resolveGroupShare'], $shares); } + + /* + * Resolve all group shares to user specific shares + * TODO: Optmize this! + */ + $shares = array_map([$this, 'resolveGroupShare'], $shares); } else { throw new BackendError(); } diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 039692772a..812c6ecc27 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -37,13 +37,13 @@ class DefaultShareProviderTest extends \Test\TestCase { /** @var IDBConnection */ protected $dbConn; - /** @var IUserManager */ + /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ protected $userManager; - /** @var IGroupManager */ + /** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */ protected $groupManager; - /** @var IRootFolder */ + /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ protected $rootFolder; /** @var DefaultShareProvider */ @@ -92,16 +92,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $qb->execute(); - // Get the id - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('id') - ->from('share') - ->setMaxResults(1) - ->orderBy('id', 'DESC') - ->execute(); - $id = $cursor->fetch(); - $id = $id['id']; - $cursor->closeCursor(); + $id = $qb->getLastInsertId(); $sharedWith = $this->getMock('OCP\IUser'); $sharedBy = $this->getMock('OCP\IUser'); @@ -165,15 +156,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $qb->execute()); // Get the id - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('id') - ->from('share') - ->setMaxResults(1) - ->orderBy('id', 'DESC') - ->execute(); - $id = $cursor->fetch(); - $id = $id['id']; - $cursor->closeCursor(); + $id = $qb->getLastInsertId(); $sharedWith = $this->getMock('OCP\IGroup'); $sharedBy = $this->getMock('OCP\IUser'); @@ -242,16 +225,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - // Get the id - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('id') - ->from('share') - ->setMaxResults(1) - ->orderBy('id', 'DESC') - ->execute(); - $id = $cursor->fetch(); - $id = $id['id']; - $cursor->closeCursor(); + $id = $qb->getLastInsertId(); $sharedBy = $this->getMock('OCP\IUser'); $sharedBy->method('getUID')->willReturn('sharedBy'); @@ -311,17 +285,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - // Get the id - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('id') - ->from('share') - ->setMaxResults(1) - ->orderBy('id', 'DESC') - ->execute(); - $id = $cursor->fetch(); - $id = $id['id']; - $cursor->closeCursor(); - + $id = $qb->getLastInsertId(); $share = $this->getMock('OC\Share20\IShare'); $share->method('getId')->willReturn($id); @@ -771,4 +735,392 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testGetShareByTokenNotFound() { $this->provider->getShareByToken('invalidtoken'); } + + public function testGetSharedWithUser() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id = $qb->getLastInsertId(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith2'), + 'uid_owner' => $qb->expr()->literal('shareOwner2'), + 'uid_initiator' => $qb->expr()->literal('sharedBy2'), + 'item_type' => $qb->expr()->literal('file2'), + 'file_source' => $qb->expr()->literal(43), + 'file_target' => $qb->expr()->literal('myTarget2'), + 'permissions' => $qb->expr()->literal(14), + ]); + $this->assertEquals(1, $qb->execute()); + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('sharedWith'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['sharedWith', $user], + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + + $file = $this->getMock('\OCP\Files\File'); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_USER, 1 , 0); + $this->assertCount(1, $share); + + $share = $share[0]; + $this->assertEquals($id, $share->getId()); + $this->assertEquals($user, $share->getSharedWith()); + $this->assertEquals($owner, $share->getShareOwner()); + $this->assertEquals($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType()); + } + + public function testGetSharedWithGroup() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner2'), + 'uid_initiator' => $qb->expr()->literal('sharedBy2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(43), + 'file_target' => $qb->expr()->literal('myTarget2'), + 'permissions' => $qb->expr()->literal(14), + ]); + $this->assertEquals(1, $qb->execute()); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id = $qb->getLastInsertId(); + + $groups = []; + foreach(range(0, 100) as $i) { + $group = $this->getMock('\OCP\IGroup'); + $group->method('getGID')->willReturn('group'.$i); + $groups[] = $group; + } + + $group = $this->getMock('\OCP\IGroup'); + $group->method('getGID')->willReturn('sharedWith'); + $groups[] = $group; + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('sharedWith'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); + $this->groupManager->method('get')->with('sharedWith')->willReturn($group); + + $file = $this->getMock('\OCP\Files\File'); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, 20 , 1); + $this->assertCount(1, $share); + + $share = $share[0]; + $this->assertEquals($id, $share->getId()); + $this->assertEquals($group, $share->getSharedWith()); + $this->assertEquals($owner, $share->getShareOwner()); + $this->assertEquals($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType()); + } + + public function testGetSharedWithGroupUserModified() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id = $qb->getLastInsertId(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(2), + 'share_with' => $qb->expr()->literal('user'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('userTarget'), + 'permissions' => $qb->expr()->literal(0), + 'parent' => $qb->expr()->literal($id), + ]); + $this->assertEquals(1, $qb->execute()); + + $group = $this->getMock('\OCP\IGroup'); + $group->method('getGID')->willReturn('sharedWith'); + $groups = [$group]; + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('user'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); + $this->groupManager->method('get')->with('sharedWith')->willReturn($group); + + $file = $this->getMock('\OCP\Files\File'); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, -1, 0); + $this->assertCount(1, $share); + + $share = $share[0]; + $this->assertEquals($id, $share->getId()); + $this->assertEquals($group, $share->getSharedWith()); + $this->assertEquals($owner, $share->getShareOwner()); + $this->assertEquals($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType()); + $this->assertEquals(0, $share->getPermissions()); + $this->assertEquals('userTarget', $share->getTarget()); + } + + public function testGetSharesBy() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id = $qb->getLastInsertId(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('userTarget'), + 'permissions' => $qb->expr()->literal(0), + 'parent' => $qb->expr()->literal($id), + ]); + $this->assertEquals(1, $qb->execute()); + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('sharedWith'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['sharedWith', $user], + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + + $file = $this->getMock('\OCP\Files\File'); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $share = $this->provider->getSharesBy($initiator, \OCP\Share::SHARE_TYPE_USER, null, false, 1, 0); + $this->assertCount(1, $share); + + $share = $share[0]; + $this->assertEquals($id, $share->getId()); + $this->assertEquals($user, $share->getSharedWith()); + $this->assertEquals($owner, $share->getShareOwner()); + $this->assertEquals($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType()); + $this->assertEquals(13, $share->getPermissions()); + $this->assertEquals('myTarget', $share->getTarget()); + } + + public function testGetSharesNode() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id = $qb->getLastInsertId(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(43), + 'file_target' => $qb->expr()->literal('userTarget'), + 'permissions' => $qb->expr()->literal(0), + 'parent' => $qb->expr()->literal($id), + ]); + $this->assertEquals(1, $qb->execute()); + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('sharedWith'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['sharedWith', $user], + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + + $file = $this->getMock('\OCP\Files\File'); + $file->method('getId')->willReturn(42); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $share = $this->provider->getSharesBy($initiator, \OCP\Share::SHARE_TYPE_USER, $file, false, 1, 0); + $this->assertCount(1, $share); + + $share = $share[0]; + $this->assertEquals($id, $share->getId()); + $this->assertEquals($user, $share->getSharedWith()); + $this->assertEquals($owner, $share->getShareOwner()); + $this->assertEquals($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType()); + $this->assertEquals(13, $share->getPermissions()); + $this->assertEquals('myTarget', $share->getTarget()); + } + + public function testGetSharesReshare() { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('shareOwner'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + ]); + $this->assertEquals(1, $qb->execute()); + $id1 = $qb->getLastInsertId(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('sharedWith'), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('userTarget'), + 'permissions' => $qb->expr()->literal(0), + ]); + $this->assertEquals(1, $qb->execute()); + $id2 = $qb->getLastInsertId(); + + $user = $this->getMock('\OCP\IUser'); + $user->method('getUID')->willReturn('sharedWith'); + $owner = $this->getMock('\OCP\IUser'); + $owner->method('getUID')->willReturn('shareOwner'); + $initiator = $this->getMock('\OCP\IUser'); + $initiator->method('getUID')->willReturn('sharedBy'); + + $this->userManager->method('get')->willReturnMap([ + ['sharedWith', $user], + ['shareOwner', $owner], + ['sharedBy', $initiator], + ]); + + $file = $this->getMock('\OCP\Files\File'); + $file->method('getId')->willReturn(42); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); + $this->rootFolder->method('getById')->with(42)->willReturn([$file]); + + $shares = $this->provider->getSharesBy($owner, \OCP\Share::SHARE_TYPE_USER, null, true, -1, 0); + $this->assertCount(2, $shares); + + $share = $shares[0]; + $this->assertEquals($id1, $share->getId()); + $this->assertSame($user, $share->getSharedWith()); + $this->assertSame($owner, $share->getShareOwner()); + $this->assertSame($owner, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType()); + $this->assertEquals(13, $share->getPermissions()); + $this->assertEquals('myTarget', $share->getTarget()); + + $share = $shares[1]; + $this->assertEquals($id2, $share->getId()); + $this->assertSame($user, $share->getSharedWith()); + $this->assertSame($owner, $share->getShareOwner()); + $this->assertSame($initiator, $share->getSharedBy()); + $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType()); + $this->assertEquals(0, $share->getPermissions()); + $this->assertEquals('userTarget', $share->getTarget()); + } } From 3a582e88e599d53108bcd7a299a56202513f3bd5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 20 Jan 2016 14:17:25 +0100 Subject: [PATCH 7/8] 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(-) diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 2190582f3f..c2ff94db79 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 596addb1e6..e0b437bbcc 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 a5a9d3b670..36d0f10c7f 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 From 658959592d637c3dc8f8bfac8cba962273c72f4b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 21 Jan 2016 15:56:23 +0100 Subject: [PATCH 8/8] [Share 2.0] Fix displaying old shares proplery --- lib/private/share20/defaultshareprovider.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index e0b437bbcc..5d768a4bc4 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -263,7 +263,18 @@ class DefaultShareProvider implements IShareProvider { * Reshares for this user are shares where they are the owner. */ if ($reshares === false) { - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID()))); + //Special case for old shares created via the web UI + $or1 = $qb->expr()->andX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())), + $qb->expr()->isNull('uid_initiator') + ); + + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())), + $or1 + ) + ); } else { $qb->andWhere( $qb->expr()->orX(