diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-07-05 13:31:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-05 13:31:58 +0200 |
commit | cbfcfb236f3e8ace6c64ab5a654b9a331a3ce1c0 (patch) | |
tree | b86e43db95907d58f56fdb885316a01fdbfa7bac /lib | |
parent | 86d9528bc93402a18a3202bb3ff17c812b94402e (diff) | |
parent | f39dfc7ab8ced56de4935a56d87334b211df9b5e (diff) | |
download | nextcloud-server-cbfcfb236f3e8ace6c64ab5a654b9a331a3ce1c0.tar.gz nextcloud-server-cbfcfb236f3e8ace6c64ab5a654b9a331a3ce1c0.zip |
Merge pull request #9909 from nextcloud/feature/2192/allow_group_share_undeletion
Add API to undelete delete group shares
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 37 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 27 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 29 | ||||
-rw-r--r-- | lib/public/Share/IShareProvider.php | 14 |
4 files changed, 107 insertions, 0 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 3c56b24707c..5e52156d1d0 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -31,6 +31,7 @@ namespace OC\Share20; use OC\Files\Cache\Cache; use OCP\Files\Folder; +use OCP\Share\IShare; use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; @@ -412,6 +413,41 @@ class DefaultShareProvider implements IShareProvider { /** * @inheritdoc + * + * For now this only works for group shares + * If this gets implemented for normal shares we have to extend it + */ + public function restore(IShare $share, string $recipient): IShare { + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('permissions') + ->from('share') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($share->getId())) + ); + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + $originalPermission = $data['permissions']; + + $qb = $this->dbConn->getQueryBuilder(); + $qb->update('share') + ->set('permissions', $qb->createNamedParameter($originalPermission)) + ->where( + $qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent())) + )->andWhere( + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) + )->andWhere( + $qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)) + ); + + $qb->execute(); + + return $this->getShareById($share->getId(), $recipient); + } + + /** + * @inheritdoc */ public function move(\OCP\Share\IShare $share, $recipient) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { @@ -922,6 +958,7 @@ class DefaultShareProvider implements IShareProvider { while($data = $stmt->fetch()) { $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); $shareMap[$data['parent']]->setTarget($data['file_target']); + $shareMap[$data['parent']]->setParent($data['parent']); } $stmt->closeCursor(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index cddd8c8d92b..5116351a6bc 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -61,6 +61,7 @@ use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share\IProviderFactory; +use OCP\Share\IShare; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; use OCP\Share\IShareProvider; @@ -978,6 +979,13 @@ class Manager implements IManager { $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); } + public function restoreShare(IShare $share, string $recipientId): IShare { + list($providerId, ) = $this->splitFullId($share->getFullId()); + $provider = $this->factory->getProvider($providerId); + + return $provider->restore($share, $recipientId); + } + /** * @inheritdoc */ @@ -1124,6 +1132,25 @@ class Manager implements IManager { /** * @inheritdoc */ + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); + + // Only get deleted shares + $shares = array_filter($shares, function(IShare $share) { + return $share->getPermissions() === 0; + }); + + // Only get shares where the owner still exists + $shares = array_filter($shares, function (IShare $share) { + return $this->userManager->userExists($share->getShareOwner()); + }); + + return $shares; + } + + /** + * @inheritdoc + */ public function getShareById($id, $recipient = null) { if ($id === null) { throw new ShareNotFound(); diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 493db5e5149..d4fc3e14749 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -29,6 +29,7 @@ namespace OCP\Share; use OCP\Files\Folder; use OCP\Files\Node; +use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; /** @@ -84,6 +85,20 @@ interface IManager { public function deleteFromSelf(IShare $share, $recipientId); /** + * Restore the share when it has been deleted + * Certain share types can be restored when they have been deleted + * but the provider should properly handle this\ + * + * @param IShare $share The share to restore + * @param string $recipientId The user to restore the share for + * @return IShare The restored share object + * @throws GenericShareException In case restoring the share failed + * + * @since 14.0.0 + */ + public function restoreShare(IShare $share, string $recipientId): IShare; + + /** * Move the share as a recipient of the share. * This is updating the share target. So where the recipient has the share mounted. * @@ -135,6 +150,20 @@ interface IManager { public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); /** + * Get deleted shares shared with $user. + * Filter by $node if provided + * + * @param string $userId + * @param int $shareType + * @param Node|null $node + * @param int $limit The maximum number of shares returned, -1 for all + * @param int $offset + * @return IShare[] + * @since 14.0.0 + */ + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); + + /** * Retrieve a share by the share id. * If the recipient is set make sure to retrieve the file for that user. * This makes sure that if a user has moved/deleted a group share this diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php index 4a1ac9b8b8d..6731bf8882b 100644 --- a/lib/public/Share/IShareProvider.php +++ b/lib/public/Share/IShareProvider.php @@ -25,6 +25,8 @@ namespace OCP\Share; use OCP\Files\Folder; +use OCP\Share\Exceptions\GenericShareException; +use OCP\Share\Exceptions\ShareNotFound; use OCP\Files\Node; /** @@ -81,6 +83,18 @@ interface IShareProvider { public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); /** + * Restore a share for a given recipient. The implementation could be provider independant. + * + * @param IShare $share + * @param string $recipient + * @return IShare The restored share object + * + * @since 14.0.0 + * @throws GenericShareException In case the share could not be restored + */ + public function restore(IShare $share, string $recipient): IShare; + + /** * Move a share as a recipient. * This is updating the share target. Thus the mount point of the recipient. * This may require special handling. If a user moves a group share |