diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 0f1ad3bd5d557..53683a6d064d5 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -1854,14 +1854,14 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array $shares = array_merge($shares, $providerShares); } - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) { $federatedShares = $this->shareManager->getSharesBy( $this->userId, IShare::TYPE_REMOTE, $node, $reShares, -1, 0 ); $shares = array_merge($shares, $federatedShares); } - if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE_GROUP)) { $federatedShares = $this->shareManager->getSharesBy( $this->userId, IShare::TYPE_REMOTE_GROUP, $node, $reShares, -1, 0 ); @@ -2001,7 +2001,7 @@ private function getAllShares(?Node $path = null, bool $reshares = false) { } else { $federatedShares = []; } - if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $federatedGroupShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); } else { $federatedGroupShares = []; diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 28caea90ceae8..07654a6db0bd4 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -2169,6 +2169,65 @@ public function testCreateShareGroupNotAllowed(): void { $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup'); } + public function testGetFederatedShareWhenOutgoingFederationDisabled(): void { + $share = $this->createMock(IShare::class); + $share->method('getId')->willReturn('42'); + $share->method('getShareType')->willReturn(IShare::TYPE_REMOTE); + + /** @var ShareAPIController&MockObject $ocs */ + $ocs = $this->getMockBuilder(ShareAPIController::class) + ->setConstructorArgs([ + $this->appName, + $this->request, + $this->shareManager, + $this->groupManager, + $this->userManager, + $this->rootFolder, + $this->urlGenerator, + $this->l, + $this->config, + $this->appConfig, + $this->appManager, + $this->serverContainer, + $this->userStatusManager, + $this->previewManager, + $this->dateTimeZone, + $this->logger, + $this->factory, + $this->mailer, + $this->tagManager, + $this->getEmailValidatorWithStrictEmailCheck(), + $this->trustedServers, + $this->currentUser, + ]) + ->onlyMethods(['canAccessShare', 'formatShare']) + ->getMock(); + + $ocs->method('canAccessShare')->willReturn(true); + $ocs->method('formatShare')->with($share)->willReturn([ + 'id' => '42', + 'share_type' => IShare::TYPE_REMOTE, + ]); + + $this->shareManager + ->method('getShareById') + ->willReturnCallback(function (string $id, string $recipient) use ($share) { + $this->assertSame($this->currentUser, $recipient); + if ($id === 'ocFederatedSharing:42') { + return $share; + } + + throw new ShareNotFound(); + }); + + $this->assertSame([ + [ + 'id' => '42', + 'share_type' => IShare::TYPE_REMOTE, + ], + ], $ocs->getShare('42')->getData()); + } + public function testCreateShareLinkNoLinksAllowed(): void { $this->expectException(OCSNotFoundException::class);