]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update owner of subdir on move into/out of share
authorVincent Petry <vincent@nextcloud.com>
Mon, 28 Mar 2022 07:28:37 +0000 (09:28 +0200)
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>
Tue, 26 Jul 2022 12:17:46 +0000 (12:17 +0000)
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 <vincent@nextcloud.com>
apps/files_sharing/lib/Updater.php

index ad194dde016106edf1f1adb6e6261877c5a95293..b110b2045f9d9827c3de997a82851ca0669cedf7 100644 (file)
@@ -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);