diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-08 09:59:00 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-08 09:59:00 +0100 |
commit | 62b5948ff5745e29d4c8739f416a6a599cb6e3b4 (patch) | |
tree | 0dc004ea28f76c803ae8c1f2e85083c61f22a5c7 /lib | |
parent | 83b4e2c8d117bc2b2aaaa2d2af8cda1fe35da290 (diff) | |
parent | 46faf6d3ca437c8795af79f1851b4bd6b4a92280 (diff) | |
download | nextcloud-server-62b5948ff5745e29d4c8739f416a6a599cb6e3b4.tar.gz nextcloud-server-62b5948ff5745e29d4c8739f416a6a599cb6e3b4.zip |
Merge pull request #22156 from owncloud/share2_unshare_ifexpired
Delete a link share if it is expired on access
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share20/manager.php | 67 | ||||
-rw-r--r-- | lib/public/share/ishareprovider.php | 2 |
2 files changed, 66 insertions, 3 deletions
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index d65fb927f9b..33085410e1d 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -22,6 +22,7 @@ namespace OC\Share20; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; use OCP\IUserManager; use OCP\Share\IManager; use OCP\Share\IProviderFactory; @@ -778,7 +779,57 @@ 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 + ) { + try { + $this->deleteShare($share); + } catch (NotFoundException $e) { + //Ignore since this basically means the share is deleted + } + 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; } /** @@ -803,6 +854,14 @@ class Manager implements IManager { $share = $provider->getShareById($id, $recipient); + // Validate link shares expiration date + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && + $share->getExpirationDate() !== null && + $share->getExpirationDate() <= new \DateTime()) { + $this->deleteShare($share); + throw new ShareNotFound(); + } + return $share; } @@ -831,7 +890,11 @@ class Manager implements IManager { $share = $provider->getShareByToken($token); - //TODO check if share expired + if ($share->getExpirationDate() !== null && + $share->getExpirationDate() <= new \DateTime()) { + $this->deleteShare($share); + throw new ShareNotFound(); + } return $share; } 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); |