diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index ea124382d9a9e..8294fc92ec0cd 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -915,13 +915,12 @@ private function getSharesInDir(Node $folder): array { throw new OCSBadRequestException($this->l->t('Not a directory')); } - $nodes = $folder->getDirectoryListing(); - /** @var \OCP\Share\IShare[] $shares */ - $shares = array_reduce($nodes, function ($carry, $node) { - $carry = array_merge($carry, $this->getAllShares($node, true)); - return $carry; - }, []); + $shares = []; + $sharesInFolder = $this->shareManager->getSharesInFolder($this->currentUser, $folder, true); + foreach ($sharesInFolder as $key => $value) { + $shares = array_merge($shares, $value); + } // filter out duplicate shares $known = []; @@ -1999,49 +1998,6 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no return false; } - /** - * Get all the shares for the current user - * - * @param Node|null $path - * @param boolean $reshares - * @return IShare[] - */ - private function getAllShares(?Node $path = null, bool $reshares = false) { - // Get all shares - $userShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_USER, $path, $reshares, -1, 0); - $groupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_GROUP, $path, $reshares, -1, 0); - $linkShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_LINK, $path, $reshares, -1, 0); - - // EMAIL SHARES - $mailShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_EMAIL, $path, $reshares, -1, 0); - - // CIRCLE SHARES - $circleShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_CIRCLE, $path, $reshares, -1, 0); - - // TALK SHARES - $roomShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_ROOM, $path, $reshares, -1, 0); - - // DECK SHARES - $deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0); - - // SCIENCEMESH SHARES - $sciencemeshShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_SCIENCEMESH, $path, $reshares, -1, 0); - - // FEDERATION - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); - } else { - $federatedShares = []; - } - if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { - $federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); - } else { - $federatedGroupShares = []; - } - - return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $sciencemeshShares, $federatedShares, $federatedGroupShares); - } - /** * merging already formatted shares. diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 731650d8aee8a..c436ca8a0effe 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -1458,6 +1458,22 @@ function ($user, $shareType, $node) use ($shares) { ->method('outgoingServer2ServerGroupSharesAllowed') ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false); + $sharesWithoutTypes = []; + foreach ($shares as $file => $fileShares) { + $sharesWithoutTypes[$file] = []; + foreach ($fileShares as $shareType => $shareTypeShares) { + if ($shareType === ISHARE::TYPE_REMOTE or $shareType === ISHARE::TYPE_REMOTE_GROUP) { + if ($extraShareTypes[$shareType] ?? false) { + $sharesWithoutTypes[$file] = array_merge($sharesWithoutTypes[$file], $shareTypeShares); + } + } else { + $sharesWithoutTypes[$file] = array_merge($sharesWithoutTypes[$file], $shareTypeShares); + } + } + } + $this->shareManager + ->method('getSharesInFolder')->willReturn($sharesWithoutTypes); + $this->groupManager ->method('isInGroup') ->willReturnCallback( diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index b4ec16936f354..8f78a88d89736 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -674,13 +674,6 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t */ if ($reshares === false) { $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); - } else { - $qb->andWhere( - $qb->expr()->orX( - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) - ) - ); } // todo? maybe get these from the oc_mounts table