From 57967bbb3e7930b954e5ada6c2726ede40aeed47 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Mon, 23 Mar 2026 18:53:08 +0100 Subject: [PATCH 1/2] fix(ShareApiController): fix listing of remote shares for the owner Signed-off-by: Simon L. --- .../lib/Controller/ShareAPIController.php | 12 ++-- .../Controller/ShareAPIControllerTest.php | 63 +++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 0f1ad3bd5d557..688bd6470e88d 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -1729,8 +1729,8 @@ private function getShareById(string $id): IShare { 'deck' => IShare::TYPE_DECK, ]; - // Add federated sharing as a provider only if it's allowed - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { + // Include federated sharing whenever the provider is available for the user. + if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) { $providers['ocFederatedSharing'] = null; // No type check needed } @@ -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 ); @@ -1996,12 +1996,12 @@ private function getAllShares(?Node $path = null, bool $reshares = false) { $deckShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_DECK, $path, $reshares, -1, 0); // FEDERATION - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) { $federatedShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); } else { $federatedShares = []; } - if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { + if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE_GROUP)) { $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..a8b479ca537cd 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -1305,6 +1305,8 @@ public static function dataGetShares(): array { $file1EmailShareOwnerExpected, $file1CircleShareOwnerExpected, $file1RoomShareOwnerExpected, + $file1RemoteShareOwnerExpected, + $file1RemoteGroupShareOwnerExpected, ] ], [ @@ -1475,6 +1477,8 @@ public static function dataGetShares(): array { $file1EmailShareOwnerExpected, $file1CircleShareOwnerExpected, $file1RoomShareOwnerExpected, + $file1RemoteShareOwnerExpected, + $file1RemoteGroupShareOwnerExpected, ] ], [ @@ -2169,6 +2173,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); From 11b15397c212fa517aab252384e3d6918fc9b10a Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Thu, 26 Mar 2026 14:55:42 +0100 Subject: [PATCH 2/2] fixup! fix(ShareApiController): fix listing of remote shares for the owner Signed-off-by: Simon L. --- apps/files_sharing/lib/Controller/ShareAPIController.php | 8 ++++---- .../tests/Controller/ShareAPIControllerTest.php | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 688bd6470e88d..53683a6d064d5 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -1729,8 +1729,8 @@ private function getShareById(string $id): IShare { 'deck' => IShare::TYPE_DECK, ]; - // Include federated sharing whenever the provider is available for the user. - if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) { + // Add federated sharing as a provider only if it's allowed + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $providers['ocFederatedSharing'] = null; // No type check needed } @@ -1996,12 +1996,12 @@ private function getAllShares(?Node $path = null, bool $reshares = false) { $deckShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_DECK, $path, $reshares, -1, 0); // FEDERATION - if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) { + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $federatedShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); } else { $federatedShares = []; } - if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE_GROUP)) { + 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 a8b479ca537cd..07654a6db0bd4 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -1305,8 +1305,6 @@ public static function dataGetShares(): array { $file1EmailShareOwnerExpected, $file1CircleShareOwnerExpected, $file1RoomShareOwnerExpected, - $file1RemoteShareOwnerExpected, - $file1RemoteGroupShareOwnerExpected, ] ], [ @@ -1477,8 +1475,6 @@ public static function dataGetShares(): array { $file1EmailShareOwnerExpected, $file1CircleShareOwnerExpected, $file1RoomShareOwnerExpected, - $file1RemoteShareOwnerExpected, - $file1RemoteGroupShareOwnerExpected, ] ], [