diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-08-22 17:03:07 +0200 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-10-14 11:58:47 +0200 |
commit | 7e9bc7c8cf981b4931cd4a75b674c662eddc4bb9 (patch) | |
tree | c01c1cb75ac99149313a6114954095bad950227f /lib | |
parent | 42181c2f490025860e22907255b6917583c798af (diff) | |
download | nextcloud-server-7e9bc7c8cf981b4931cd4a75b674c662eddc4bb9.tar.gz nextcloud-server-7e9bc7c8cf981b4931cd4a75b674c662eddc4bb9.zip |
fix: Tidy up code for reshare deletion
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/Manager.php | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 96dd88c6793..e5e5166b4a9 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1040,31 +1040,32 @@ class Manager implements IManager { return $deletedShares; } - public function deleteReshare(IShare $share) { - // Skip if node not found + protected function deleteReshares(IShare $share): void { try { $node = $share->getNode(); } catch (NotFoundException) { + /* Skip if node not found */ return; } $userIds = []; - if ($share->getShareType() === IShare::TYPE_USER) { + if ($share->getShareType() === IShare::TYPE_USER) { $userIds[] = $share->getSharedWith(); - } - - if ($share->getShareType() === IShare::TYPE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { $group = $this->groupManager->get($share->getSharedWith()); - $users = $group->getUsers(); + $users = $group?->getUsers() ?? []; foreach ($users as $user) { - // Skip if share owner is member of shared group + /* Skip share owner */ if ($user->getUID() === $share->getShareOwner()) { continue; } $userIds[] = $user->getUID(); } + } else { + /* We only support user and group shares */ + return; } $reshareRecords = []; @@ -1073,7 +1074,7 @@ class Manager implements IManager { IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, - IShare::TYPE_EMAIL + IShare::TYPE_EMAIL, ]; foreach ($userIds as $userId) { @@ -1085,8 +1086,8 @@ class Manager implements IManager { } } - if ($share->getNodeType() === 'folder') { - $sharesInFolder = $this->getSharesInFolder($userId, $node, true); + if ($node instanceof Folder) { + $sharesInFolder = $this->getSharesInFolder($userId, $node, false); foreach ($sharesInFolder as $shares) { foreach ($shares as $child) { @@ -1100,6 +1101,7 @@ 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); } } @@ -1128,10 +1130,10 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($share->getShareType()); $provider->delete($share); - // Delete shares that shared by the "share with user/group" - $this->deleteReshare($share); - $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); + + // Delete reshares of the deleted share + $this->deleteReshares($share); } |