]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add argument to getSharesInFolder enable deep share lookup 31728/head
authorLouis Chemineau <louis@chmn.me>
Thu, 23 Jun 2022 14:32:52 +0000 (16:32 +0200)
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>
Tue, 26 Jul 2022 12:17:46 +0000 (12:17 +0000)
Signed-off-by: Louis Chemineau <louis@chmn.me>
apps/federatedfilesharing/lib/FederatedShareProvider.php
apps/files_sharing/lib/Updater.php
apps/sharebymail/lib/ShareByMailProvider.php
lib/private/Share20/DefaultShareProvider.php
lib/private/Share20/Manager.php
lib/public/Share/IManager.php
lib/public/Share/IShareProvider.php

index 52b10cd9315f3271291c6dcdfd0783a59cede5ef..d504a3e2acc2ce9b512ed5b3d40a61504fd63919 100644 (file)
@@ -638,7 +638,7 @@ class FederatedShareProvider implements IShareProvider {
        }
 
 
-       public function getSharesInFolder($userId, Folder $node, $reshares) {
+       public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
                $qb = $this->dbConnection->getQueryBuilder();
                $qb->select('*')
                        ->from('share', 's')
@@ -664,8 +664,13 @@ class FederatedShareProvider implements IShareProvider {
                        );
                }
 
-               $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
-               $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+               $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
+
+               if ($shallow) {
+                       $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+               } else {
+                       $qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
+               }
 
                $qb->orderBy('id');
 
index 071d4d3cca9bc38169378f7984ea6c2a5249a8c7..59e06e60299828d9ee2a1a37e1ef75b1b8095947 100644 (file)
@@ -69,7 +69,7 @@ class Updater {
                $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1));
 
                if ($src instanceof Folder) {
-                       $subShares = $shareManager->getSharesInFolderRecursive($userFolder->getOwner()->getUID(), $src, false);
+                       $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false);
                        foreach ($subShares as $subShare) {
                                $shares = array_merge($shares, array_values($subShare));
                        }
index ee14e354c5284850ef2b756a83e42b3985f8e657..01dd3b428d17972b1ff852ad7f6b00db351f1d9a 100644 (file)
@@ -75,7 +75,6 @@ use OCP\Share\IShareProvider;
  * @package OCA\ShareByMail
  */
 class ShareByMailProvider implements IShareProvider {
-
        private IConfig $config;
 
        /** @var  IDBConnection */
@@ -1159,7 +1158,7 @@ class ShareByMailProvider implements IShareProvider {
                return $data;
        }
 
-       public function getSharesInFolder($userId, Folder $node, $reshares) {
+       public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
                $qb = $this->dbConnection->getQueryBuilder();
                $qb->select('*')
                        ->from('share', 's')
@@ -1185,8 +1184,13 @@ class ShareByMailProvider implements IShareProvider {
                        );
                }
 
-               $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
-               $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+               $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
+
+               if ($shallow) {
+                       $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+               } else {
+                       $qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
+               }
 
                $qb->orderBy('id');
 
index 74f3e953a720336c52acf446e444a813ae1be513..7719a1e6be3c1748e73ac4a5c5eb6cb82f434248 100644 (file)
@@ -641,7 +641,7 @@ class DefaultShareProvider implements IShareProvider {
                return $share;
        }
 
-       public function getSharesInFolder($userId, Folder $node, $reshares) {
+       public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
                $qb = $this->dbConn->getQueryBuilder();
                $qb->select('s.*',
                                'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
@@ -682,12 +682,21 @@ class DefaultShareProvider implements IShareProvider {
                }, $childMountNodes);
 
                $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
-               $qb->andWhere(
-                       $qb->expr()->orX(
-                               $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
-                               $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
-                       )
-               );
+               if ($shallow) {
+                       $qb->andWhere(
+                               $qb->expr()->orX(
+                                       $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
+                                       $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
+                               )
+                       );
+               } else {
+                       $qb->andWhere(
+                               $qb->expr()->orX(
+                                       $qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConn->escapeLikeParameter($node->getInternalPath()) . '/%')),
+                                       $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
+                               )
+                       );
+               }
 
                $qb->orderBy('id');
 
index fd1a27af8cfb24cca0a87379e04ae885e7e64ffc..46f256df54d199e7406752ec33a223aa87c3a1ef 100644 (file)
@@ -1303,11 +1303,11 @@ class Manager implements IManager {
                return $provider->move($share, $recipientId);
        }
 
-       public function getSharesInFolder($userId, Folder $node, $reshares = false) {
+       public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) {
                $providers = $this->factory->getAllProviders();
 
-               return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) {
-                       $newShares = $provider->getSharesInFolder($userId, $node, $reshares);
+               return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares, $shallow) {
+                       $newShares = $provider->getSharesInFolder($userId, $node, $reshares, $shallow);
                        foreach ($newShares as $fid => $data) {
                                if (!isset($shares[$fid])) {
                                        $shares[$fid] = [];
@@ -1319,24 +1319,6 @@ class Manager implements IManager {
                }, []);
        }
 
-       public function getSharesInFolderRecursive(string $userId, Folder $node, $reshares = false) {
-               $shares = $this->getSharesInFolder($userId, $node, $reshares);
-
-               foreach ($node->getDirectoryListing() as $subnode) {
-                       if (!$subnode instanceof Folder) {
-                               continue;
-                       }
-
-                       $subShares = $this->getSharesInFolderRecursive($userId, $subnode, $reshares);
-
-                       foreach ($subShares as $fileId => $subSharesForFile) {
-                               $shares[$fileId] = array_merge($shares[$fileId] ?? [], $subSharesForFile);
-                       }
-               }
-
-               return $shares;
-       }
-
        /**
         * @inheritdoc
         */
index b1c980733fb7abf9e3ae93fb763848ddb4f5791c..0810acc673ac2e995b873debc2330e6e811425bb 100644 (file)
@@ -135,18 +135,11 @@ interface IManager {
         * @param string $userId
         * @param Folder $node
         * @param bool $reshares
+        * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
         * @return IShare[][] [$fileId => IShare[], ...]
         * @since 11.0.0
         */
-       public function getSharesInFolder($userId, Folder $node, $reshares = false);
-
-       /**
-        * Recursively get all shares shared by (initiated) by the provided user in a folder.
-        *
-        * @return IShare[][] [$fileId => IShare[], ...]
-        * @since 11.0.0
-        */
-       public function getSharesInFolderRecursive(string $userId, Folder $node, bool $reshares = false);
+       public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true);
 
        /**
         * Get shares shared by (initiated) by the provided user.
index 6af513360fe2a5ae7d56ccf016da1e1ff4c6280a..c549592d6f6297f51ed4798e56503e7059b805d0 100644 (file)
@@ -123,10 +123,11 @@ interface IShareProvider {
         * @param string $userId
         * @param Folder $node
         * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
+        * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
         * @return \OCP\Share\IShare[][]
         * @since 11.0.0
         */
-       public function getSharesInFolder($userId, Folder $node, $reshares);
+       public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true);
 
        /**
         * Get all shares by the given user