Skip to content

Commit

Permalink
fix(shares): Promote reshares into direct shares when share is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Sep 13, 2024
1 parent 1527836 commit 796988f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ public function createShare(IShare $share) {
* @param IShare $share
* @return IShare The share object
* @throws \InvalidArgumentException
* @throws GenericShareException
*/
public function updateShare(IShare $share) {
$expirationDateUpdated = false;
Expand Down Expand Up @@ -1011,7 +1012,8 @@ protected function deleteChildren(IShare $share) {
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) {
Expand All @@ -1029,7 +1031,7 @@ protected function deleteReshares(IShare $share): void {

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();
Expand Down Expand Up @@ -1072,8 +1074,13 @@ protected function deleteReshares(IShare $share): void {
try {
$this->generalCreateChecks($child);
} catch (GenericShareException $e) {
$this->logger->debug('Delete reshare because of exception '.$e->getMessage(), ['exception' => $e]);
$this->deleteShare($child);
$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()]);
}
}
}
}
Expand Down Expand Up @@ -1103,8 +1110,8 @@ public function deleteShare(IShare $share) {

$this->dispatcher->dispatchTyped(new ShareDeletedEvent($share));

// Delete reshares of the deleted share
$this->deleteReshares($share);
// Promote reshares of the deleted share
$this->promoteReshares($share);
}


Expand Down

0 comments on commit 796988f

Please sign in to comment.