Skip to content

Commit 9c68477

Browse files
committed
fix(ShareApiController): fix listing of remote shares for the owner
Signed-off-by: Simon L. <szaimen@e.mail.de>
1 parent 8032ad8 commit 9c68477

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ private function getShareById(string $id): IShare {
17291729
'deck' => IShare::TYPE_DECK,
17301730
];
17311731

1732-
// Add federated sharing as a provider only if it's allowed
1733-
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
1732+
// Include federated sharing whenever the provider is available for the user.
1733+
if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) {
17341734
$providers['ocFederatedSharing'] = null; // No type check needed
17351735
}
17361736

@@ -1854,14 +1854,14 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
18541854
$shares = array_merge($shares, $providerShares);
18551855
}
18561856

1857-
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
1857+
if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) {
18581858
$federatedShares = $this->shareManager->getSharesBy(
18591859
$this->userId, IShare::TYPE_REMOTE, $node, $reShares, -1, 0
18601860
);
18611861
$shares = array_merge($shares, $federatedShares);
18621862
}
18631863

1864-
if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
1864+
if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE_GROUP)) {
18651865
$federatedShares = $this->shareManager->getSharesBy(
18661866
$this->userId, IShare::TYPE_REMOTE_GROUP, $node, $reShares, -1, 0
18671867
);
@@ -1996,12 +1996,12 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
19961996
$deckShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_DECK, $path, $reshares, -1, 0);
19971997

19981998
// FEDERATION
1999-
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
1999+
if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE)) {
20002000
$federatedShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_REMOTE, $path, $reshares, -1, 0);
20012001
} else {
20022002
$federatedShares = [];
20032003
}
2004-
if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
2004+
if ($this->shareManager->shareProviderExists(IShare::TYPE_REMOTE_GROUP)) {
20052005
$federatedGroupShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
20062006
} else {
20072007
$federatedGroupShares = [];

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,8 @@ public static function dataGetShares(): array {
13051305
$file1EmailShareOwnerExpected,
13061306
$file1CircleShareOwnerExpected,
13071307
$file1RoomShareOwnerExpected,
1308+
$file1RemoteShareOwnerExpected,
1309+
$file1RemoteGroupShareOwnerExpected,
13081310
]
13091311
],
13101312
[
@@ -1475,6 +1477,8 @@ public static function dataGetShares(): array {
14751477
$file1EmailShareOwnerExpected,
14761478
$file1CircleShareOwnerExpected,
14771479
$file1RoomShareOwnerExpected,
1480+
$file1RemoteShareOwnerExpected,
1481+
$file1RemoteGroupShareOwnerExpected,
14781482
]
14791483
],
14801484
[
@@ -2169,6 +2173,64 @@ public function testCreateShareGroupNotAllowed(): void {
21692173
$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup');
21702174
}
21712175

2176+
public function testGetFederatedShareWhenOutgoingFederationDisabled(): void {
2177+
$share = $this->createMock(IShare::class);
2178+
$share->method('getId')->willReturn('42');
2179+
$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
2180+
2181+
/** @var ShareAPIController&MockObject $ocs */
2182+
$ocs = $this->getMockBuilder(ShareAPIController::class)
2183+
->setConstructorArgs([
2184+
$this->appName,
2185+
$this->request,
2186+
$this->shareManager,
2187+
$this->groupManager,
2188+
$this->userManager,
2189+
$this->rootFolder,
2190+
$this->urlGenerator,
2191+
$this->l,
2192+
$this->config,
2193+
$this->appConfig,
2194+
$this->appManager,
2195+
$this->serverContainer,
2196+
$this->userStatusManager,
2197+
$this->previewManager,
2198+
$this->dateTimeZone,
2199+
$this->logger,
2200+
$this->factory,
2201+
$this->mailer,
2202+
$this->tagManager,
2203+
$this->trustedServers,
2204+
$this->currentUser,
2205+
])
2206+
->onlyMethods(['canAccessShare', 'formatShare'])
2207+
->getMock();
2208+
2209+
$ocs->method('canAccessShare')->willReturn(true);
2210+
$ocs->method('formatShare')->with($share)->willReturn([
2211+
'id' => '42',
2212+
'share_type' => IShare::TYPE_REMOTE,
2213+
]);
2214+
2215+
$this->shareManager
2216+
->method('getShareById')
2217+
->willReturnCallback(function (string $id, string $recipient) use ($share) {
2218+
$this->assertSame($this->currentUser, $recipient);
2219+
if ($id === 'ocFederatedSharing:42') {
2220+
return $share;
2221+
}
2222+
2223+
throw new ShareNotFound();
2224+
});
2225+
2226+
$this->assertSame([
2227+
[
2228+
'id' => '42',
2229+
'share_type' => IShare::TYPE_REMOTE,
2230+
],
2231+
], $ocs->getShare('42')->getData());
2232+
}
2233+
21722234

21732235
public function testCreateShareLinkNoLinksAllowed(): void {
21742236
$this->expectException(OCSNotFoundException::class);

0 commit comments

Comments
 (0)