diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-09-13 10:00:53 +0200 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-10-14 11:58:47 +0200 |
commit | d78f8280e896f0c85a44e6f975adf6471ae1dea9 (patch) | |
tree | b753562063eecc7b9291e399e0643c091641903e /lib | |
parent | 7a48f8d92907feba985b0dd55e6c9d37a7040c80 (diff) | |
download | nextcloud-server-d78f8280e896f0c85a44e6f975adf6471ae1dea9.tar.gz nextcloud-server-d78f8280e896f0c85a44e6f975adf6471ae1dea9.zip |
fix(shares): Promote reshares into direct shares when share is deleted
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/Manager.php | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index e5e5166b4a9..dfb270eb6e3 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -783,6 +783,7 @@ class Manager implements IManager { * @param IShare $share * @return IShare The share object * @throws \InvalidArgumentException + * @throws GenericShareException */ public function updateShare(IShare $share) { $expirationDateUpdated = false; @@ -1040,7 +1041,8 @@ class Manager implements IManager { return $deletedShares; } - protected function deleteReshares(IShare $share): void { + /* Promote reshares into direct shares so that target user keeps access */ + protected function promoteReshares(IShare $share): void { try { $node = $share->getNode(); } catch (NotFoundException) { @@ -1058,7 +1060,7 @@ class Manager implements IManager { foreach ($users as $user) { /* Skip share owner */ - if ($user->getUID() === $share->getShareOwner()) { + if ($user->getUID() === $share->getShareOwner() || $user->getUID() === $share->getSharedBy()) { continue; } $userIds[] = $user->getUID(); @@ -1101,8 +1103,14 @@ class Manager implements IManager { try { $this->generalCreateChecks($child); } catch (GenericShareException $e) { - $this->logger->debug('Delete reshare because of exception '.$e->getMessage(), ['exception' => $e]); - $this->deleteShare($child); + /* The check is invalid, promote it to a direct share from the sharer of parent share */ + $this->logger->debug('Promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); + try { + $child->setSharedBy($share->getSharedBy()); + $this->updateShare($child); + } catch (GenericShareException|\InvalidArgumentException $e) { + $this->logger->warning('Failed to promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); + } } } } @@ -1132,8 +1140,8 @@ class Manager implements IManager { $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); - // Delete reshares of the deleted share - $this->deleteReshares($share); + // Promote reshares of the deleted share + $this->promoteReshares($share); } |