Skip to content
Closed
Prev Previous commit
Next Next commit
fix(shares): Promote reshares into direct shares when share is deleted
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and backportbot[bot] committed Dec 3, 2024
commit 3224047291a37e817c1b44fb13104c874414dcc4
20 changes: 14 additions & 6 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ protected function sendMailNotification(IL10N $l,
* @param IShare $share
* @return IShare The share object
* @throws \InvalidArgumentException
* @throws GenericShareException
*/
public function updateShare(IShare $share) {
$expirationDateUpdated = false;
Expand Down Expand Up @@ -1154,7 +1155,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 @@ -1172,7 +1174,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 @@ -1215,8 +1217,14 @@ 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);
/* 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()]);
}
}
}
}
Expand Down Expand Up @@ -1246,8 +1254,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