diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-29 15:26:04 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-29 15:36:23 +0100 |
commit | a24e7f655885b5047e73036acb2f1706803a2b65 (patch) | |
tree | 368b0e20962529da9a1fe6d0a48c0842945ebde8 /lib | |
parent | 8ad45dad38c2c502ac1fae48e4bc12ec3dcfd565 (diff) | |
download | nextcloud-server-a24e7f655885b5047e73036acb2f1706803a2b65.tar.gz nextcloud-server-a24e7f655885b5047e73036acb2f1706803a2b65.zip |
Add path filter to OCS Share API ?shared_with_me=true
This allows all clients to quickly get the share info for a given path.
Instead of returning everything and filtering it then manually on the
client side.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 23 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 13 | ||||
-rw-r--r-- | lib/public/share/imanager.php | 4 | ||||
-rw-r--r-- | lib/public/share/ishareprovider.php | 4 |
4 files changed, 23 insertions, 21 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 35b3f71f3de..0fa1552a1e7 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -518,16 +518,9 @@ class DefaultShareProvider implements IShareProvider { } /** - * Get shared with the given user - * - * @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[] - * @throws BackendError + * @inheritdoc */ - public function getSharedWith(IUser $user, $shareType, $limit, $offset) { + public function getSharedWith(IUser $user, $shareType, $node, $limit, $offset) { /** @var Share[] $shares */ $shares = []; @@ -549,6 +542,11 @@ class DefaultShareProvider implements IShareProvider { $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()))); + // Filter by node if provided + if ($node !== null) { + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); + } + $cursor = $qb->execute(); while($data = $cursor->fetch()) { @@ -581,9 +579,14 @@ class DefaultShareProvider implements IShareProvider { $qb->setMaxResults($limit - count($shares)); } + // Filter by node if provided + if ($node !== null) { + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); + } + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))); + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))); $qb->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( $groups, IQueryBuilder::PARAM_STR_ARRAY diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index d6245f4beac..ad5fed93904 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -21,6 +21,7 @@ namespace OC\Share20; +use OCP\Files\Node; use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OC\Share20\Exception\BackendError; @@ -722,18 +723,12 @@ class Manager implements IManager { } /** - * 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 \OCP\Share\IShare[] + * @inheritdoc */ - public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) { + public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0) { $provider = $this->factory->getProviderForType($shareType); - return $provider->getSharedWith($user, $shareType, $limit, $offset); + return $provider->getSharedWith($user, $shareType, $node, $limit, $offset); } /** diff --git a/lib/public/share/imanager.php b/lib/public/share/imanager.php index 6531c14a857..b2d9953e9ef 100644 --- a/lib/public/share/imanager.php +++ b/lib/public/share/imanager.php @@ -88,15 +88,17 @@ interface IManager { /** * Get shares shared with $user. + * Filter by $node if provided * * @param IUser $user * @param int $shareType + * @param File|Folder|null $node * @param int $limit The maximum number of shares returned, -1 for all * @param int $offset * @return IShare[] * @since 9.0.0 */ - public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0); + public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0); /** * Retrieve a share by the share id diff --git a/lib/public/share/ishareprovider.php b/lib/public/share/ishareprovider.php index 50964c88dd6..8507462cbed 100644 --- a/lib/public/share/ishareprovider.php +++ b/lib/public/share/ishareprovider.php @@ -23,6 +23,7 @@ namespace OCP\Share; use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\BackendError; +use OCP\Files\Node; use OCP\IUser; /** @@ -116,12 +117,13 @@ interface IShareProvider { * * @param IUser $user get shares where this user is the recipient * @param int $shareType + * @param Node|null $node * @param int $limit The max number of entries returned, -1 for all * @param int $offset * @return \OCP\Share\IShare[] * @since 9.0.0 */ - public function getSharedWith(IUser $user, $shareType, $limit, $offset); + public function getSharedWith(IUser $user, $shareType, $node, $limit, $offset); /** * Get a share by token |