diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-03-29 16:50:23 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-04-03 10:29:32 +0200 |
commit | b84fd7c3615c9d7b1830b6d51f6ad5b943d06b9f (patch) | |
tree | 2db691145f7ca15449a67d0b026a770f277561aa /lib/private | |
parent | 3cc0d15f92175f01744cef0840e32d9b5657db3b (diff) | |
download | nextcloud-server-b84fd7c3615c9d7b1830b6d51f6ad5b943d06b9f.tar.gz nextcloud-server-b84fd7c3615c9d7b1830b6d51f6ad5b943d06b9f.zip |
set expire date for all share types
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 3 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 70 |
2 files changed, 48 insertions, 25 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index cf7666f99e7..0d02123e001 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -202,6 +202,7 @@ class DefaultShareProvider implements IShareProvider { ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) ->execute(); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { $qb = $this->dbConn->getQueryBuilder(); @@ -212,6 +213,7 @@ class DefaultShareProvider implements IShareProvider { ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) ->execute(); /* @@ -224,6 +226,7 @@ class DefaultShareProvider implements IShareProvider { ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) ->execute(); /* diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 79429c44ffa..0dade2f7126 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -938,22 +938,11 @@ class Manager implements IManager { */ 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; @@ -985,6 +974,22 @@ class Manager implements IManager { $shares = $shares2; } + + // remove all shares which are already expired + foreach ($shares as $key => $share) { + try { + $this->checkExpireDate($share); + } catch (ShareNotFound $e) { + unset($shares[$key]); + try { + $this->deleteShare($share); + } catch (NotFoundException $e) { + //Ignore since this basically means the share is deleted + } + } + } + + return $shares; } @@ -998,7 +1003,23 @@ class Manager implements IManager { return []; } - return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); + + // remove all shares which are already expired + foreach ($shares as $key => $share) { + try { + $this->checkExpireDate($share); + } catch (ShareNotFound $e) { + unset($shares[$key]); + try { + $this->deleteShare($share); + } catch (NotFoundException $e) { + //Ignore since this basically means the share is deleted + } + } + } + + return $shares; } /** @@ -1019,13 +1040,7 @@ 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(); - } + $this->checkExpireDate($share); return $share; } @@ -1087,11 +1102,7 @@ class Manager implements IManager { throw new ShareNotFound(); } - if ($share->getExpirationDate() !== null && - $share->getExpirationDate() <= new \DateTime()) { - $this->deleteShare($share); - throw new ShareNotFound(); - } + $this->checkExpireDate($share); /* * Reduce the permissions for link shares if public upload is not enabled @@ -1104,6 +1115,15 @@ class Manager implements IManager { return $share; } + protected function checkExpireDate($share) { + if ($share->getExpirationDate() !== null && + $share->getExpirationDate() <= new \DateTime()) { + $this->deleteShare($share); + throw new ShareNotFound(); + } + + } + /** * Verify the password of a public share * |