summaryrefslogtreecommitdiffstats
path: root/lib/private/share20
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-20 14:07:56 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-21 16:06:12 +0100
commit9b5ea18ce56fef3de8403be97e0961dc7a082370 (patch)
treec09a47dbb1a0d0e38377b95098e6f92fa7693336 /lib/private/share20
parent0a9cd91e1d9baa8247fc2bbe1d02ede8340f2906 (diff)
downloadnextcloud-server-9b5ea18ce56fef3de8403be97e0961dc7a082370.tar.gz
nextcloud-server-9b5ea18ce56fef3de8403be97e0961dc7a082370.zip
Add Unit tests for the default share provider
Diffstat (limited to 'lib/private/share20')
-rw-r--r--lib/private/share20/defaultshareprovider.php30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index e3e5909e901..596addb1e67 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();
}