From 8ca910976d08b1fafc519df90544f775f8bd8c38 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 28 Mar 2022 09:28:37 +0200 Subject: [PATCH] Update owner of subdir on move into/out of share When moving a directory into or out of a received share, make sure to also update the share owner column for shares that exist insie the directory. Signed-off-by: Vincent Petry --- apps/files_sharing/lib/Updater.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index ad194dde016..b110b2045f9 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -29,6 +29,7 @@ namespace OCA\Files_Sharing; use OC\Files\Mount\MountPoint; use OCP\Constants; use OCP\Share\IShare; +use OCP\Files\Folder; class Updater { @@ -62,10 +63,20 @@ class Updater { $shareManager = \OC::$server->getShareManager(); + // FIXME: should CIRCLES be included here ?? $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); + if ($src instanceof Folder) { + // also check children + $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false); + // flatten the result + foreach ($subShares as $subShare) { + $shares = array_merge($shares, array_values($subShare)); + } + } + // If the path we move is not a share we don't care if (empty($shares)) { return; @@ -82,6 +93,14 @@ class Updater { //Ownership is moved over foreach ($shares as $share) { + if ( + $share->getShareType() !== IShare::TYPE_USER && + $share->getShareType() !== IShare::TYPE_GROUP && + $share->getShareType() !== IShare::TYPE_ROOM + ) { + continue; + } + /** @var IShare $share */ if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) { $shareManager->deleteShare($share); -- 2.39.5