diff options
Diffstat (limited to 'lib/private/share20')
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 92 | ||||
-rw-r--r-- | lib/private/share20/ishareprovider.php | 10 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 39 |
3 files changed, 128 insertions, 13 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index d47919d21a3..d296760412c 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 81770a45874..a5a9d3b6708 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 2be8fb5174d..7d454b26f00 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); } /** |