]> source.dussan.org Git - nextcloud-server.git/commitdiff
Extract method to get all shares
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 25 Oct 2019 08:45:49 +0000 (10:45 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 25 Oct 2019 19:39:49 +0000 (21:39 +0200)
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
apps/files_sharing/lib/Controller/ShareAPIController.php

index 90d739c5bc12bd538d20827ce8148c77672dc338..c35faabfa12d3e927ff538588545cf52b98b3cf1 100644 (file)
@@ -621,23 +621,12 @@ class ShareAPIController extends OCSController {
                }
 
                $nodes = $folder->getDirectoryListing();
+
                /** @var \OCP\Share\IShare[] $shares */
-               $shares = [];
-               foreach ($nodes as $node) {
-
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $node, true, -1, 0));
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $node, true, -1, 0));
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $node, true, -1, 0));
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $node, true, -1, 0));
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, true, -1, 0));
-                       $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $node, true, -1, 0));
-                       if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
-                               $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, true, -1, 0));
-                       }
-                       if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
-                               $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $node, true, -1, 0));
-                       }
-               }
+               $shares = array_reduce($nodes, function($carry, $node) {
+                       $carry = array_merge($carry, $this->getAllShares($node, true));
+                       return $carry;
+               }, []);
 
                $formatted = $miniFormatted = [];
                $resharingRight = false;
@@ -728,24 +717,7 @@ class ShareAPIController extends OCSController {
                }
 
                // Get all shares
-               $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
-               $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
-               $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
-               $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
-               $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
-               $roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);
-
-               $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares);
-
-               if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
-                       $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
-                       $shares = array_merge($shares, $federatedShares);
-               }
-
-               if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
-                       $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
-                       $shares = array_merge($shares, $federatedShares);
-               }
+               $shares = $this->getAllShares($path, $reshares);
 
                $formatted = $miniFormatted = [];
                $resharingRight = false;
@@ -1318,4 +1290,41 @@ class ShareAPIController extends OCSController {
                return false;
        }
 
+       /**
+        * Get all the shares for the current user
+        *
+        * @param Node|null $path
+        * @param boolean $reshares
+        * @return void
+        */
+       private function getAllShares(?Node $path = null, bool $reshares = false) {
+               // Get all shares
+               $userShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
+               $groupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
+               $linkShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
+
+               // EMAIL SHARES
+               $mailShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
+
+               // CIRCLE SHARES
+               $circleShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0);
+
+               // TALK SHARES
+               $roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);
+
+               // FEDERATION
+               if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
+                       $federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
+               } else {
+                       $federatedShares = [];
+               }
+               if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
+                       $federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
+               } else {
+                       $federatedGroupShares = [];
+               }
+
+               return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $federatedShares, $federatedGroupShares);
+       }
+
 }