aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-09-13 10:00:53 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-12-20 06:15:32 +0000
commitc647d6c6613ab47db20cef937d4eb934915e9ef9 (patch)
tree1c956a79459ab58ba026698c89c77eea9c11854d
parent58b64ad5672098334fbb6cdffec8efbbab0abb80 (diff)
downloadnextcloud-server-c647d6c6613ab47db20cef937d4eb934915e9ef9.tar.gz
nextcloud-server-c647d6c6613ab47db20cef937d4eb934915e9ef9.zip
fix(shares): Promote reshares into direct shares when share is deleted
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--lib/private/Share20/Manager.php19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 5c049791768..b3bea14de8d 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1156,7 +1156,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) {
@@ -1174,7 +1175,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();
@@ -1217,8 +1218,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()]);
+ }
}
}
}
@@ -1248,8 +1255,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);
}