summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorLuka Trovic <luka@nextcloud.com>2024-08-07 11:13:35 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-12-19 14:16:47 +0000
commitdfbaa103f95ca58df0680e47bde10c72e51ca200 (patch)
treed758d39f4d15e0cca90ce0b909e754533f579e13 /lib/private
parent8de467c60ea59a2a7b5564d829e29758c10c7fca (diff)
downloadnextcloud-server-dfbaa103f95ca58df0680e47bde10c72e51ca200.tar.gz
nextcloud-server-dfbaa103f95ca58df0680e47bde10c72e51ca200.zip
fix: delete re-shares when deleting the parent share
Note: Removed part about fix command from original PR Signed-off-by: Luka Trovic <luka@nextcloud.com> Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> (cherry picked from commit 42181c2f490025860e22907255b6917583c798af)
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Share20/Manager.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index ada5e447400..6722de547da 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -52,6 +52,7 @@ use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Node;
+use OCP\Files\NotFoundException;
use OCP\HintException;
use OCP\IConfig;
use OCP\IDateTimeZone;
@@ -1163,6 +1164,71 @@ class Manager implements IManager {
return $deletedShares;
}
+ public function deleteReshare(IShare $share) {
+ // Skip if node not found
+ try {
+ $node = $share->getNode();
+ } catch (NotFoundException) {
+ return;
+ }
+
+ $userIds = [];
+
+ if ($share->getShareType() === IShare::TYPE_USER) {
+ $userIds[] = $share->getSharedWith();
+ }
+
+ if ($share->getShareType() === IShare::TYPE_GROUP) {
+ $group = $this->groupManager->get($share->getSharedWith());
+ $users = $group->getUsers();
+
+ foreach ($users as $user) {
+ // Skip if share owner is member of shared group
+ if ($user->getUID() === $share->getShareOwner()) {
+ continue;
+ }
+ $userIds[] = $user->getUID();
+ }
+ }
+
+ $reshareRecords = [];
+ $shareTypes = [
+ IShare::TYPE_GROUP,
+ IShare::TYPE_USER,
+ IShare::TYPE_LINK,
+ IShare::TYPE_REMOTE,
+ IShare::TYPE_EMAIL
+ ];
+
+ foreach ($userIds as $userId) {
+ foreach ($shareTypes as $shareType) {
+ $provider = $this->factory->getProviderForType($shareType);
+ $shares = $provider->getSharesBy($userId, $shareType, $node, false, -1, 0);
+ foreach ($shares as $child) {
+ $reshareRecords[] = $child;
+ }
+ }
+
+ if ($share->getNodeType() === 'folder') {
+ $sharesInFolder = $this->getSharesInFolder($userId, $node, true);
+
+ foreach ($sharesInFolder as $shares) {
+ foreach ($shares as $child) {
+ $reshareRecords[] = $child;
+ }
+ }
+ }
+ }
+
+ foreach ($reshareRecords as $child) {
+ try {
+ $this->generalCreateChecks($child);
+ } catch (GenericShareException $e) {
+ $this->deleteShare($child);
+ }
+ }
+ }
+
/**
* Delete a share
*
@@ -1186,6 +1252,9 @@ 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));
}