diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-05 20:00:07 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-06 13:31:54 +0100 |
commit | 8486d617645a5ef75da34df10ed663ef77bed257 (patch) | |
tree | 5d42cc3c1b68139827e8cb0f90447664050b784f /lib | |
parent | 3028ec5440a3c4d448bbaf8a6b246391bea22317 (diff) | |
download | nextcloud-server-8486d617645a5ef75da34df10ed663ef77bed257.tar.gz nextcloud-server-8486d617645a5ef75da34df10ed663ef77bed257.zip |
getSharesBy should also expire link shares
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share20/manager.php | 48 | ||||
-rw-r--r-- | lib/public/share/ishareprovider.php | 2 |
2 files changed, 48 insertions, 2 deletions
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index c4fec31fb85..7d0017bf6f7 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -778,7 +778,53 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($shareType); - return $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); + + /* + * Work around so we don't return expired shares but still follow + * proper pagination. + */ + if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { + $shares2 = []; + $today = new \DateTime(); + + while(true) { + $added = 0; + foreach ($shares as $share) { + // Check if the share is expired and if so delete it + if ($share->getExpirationDate() !== null && + $share->getExpirationDate() <= $today + ) { + $this->deleteShare($share); + continue; + } + $added++; + $shares2[] = $share; + + if (count($shares2) === $limit) { + break; + } + } + + if (count($shares2) === $limit) { + break; + } + + $offset += $added; + + // Fetch again $limit shares + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); + + // No more shares means we are done + if (empty($shares)) { + break; + } + } + + $shares = $shares2; + } + + return $shares; } /** diff --git a/lib/public/share/ishareprovider.php b/lib/public/share/ishareprovider.php index 25fa76369ab..b339ce63d34 100644 --- a/lib/public/share/ishareprovider.php +++ b/lib/public/share/ishareprovider.php @@ -101,7 +101,7 @@ interface IShareProvider { * @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 \OCP\Share\IShare Share[] + * @return \OCP\Share\IShare[] * @since 9.0.0 */ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); |