Skip to content

Commit a34738e

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 a34738e

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

apps/contactsinteraction/tests/Db/RecentContactMapperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected function setUp(): void {
2727

2828
$this->recentContactMapper = Server::get(RecentContactMapper::class);
2929
$this->time = Server::get(ITimeFactory::class);
30+
$this->recentContactMapper->deleteByUserId('admin');
3031
}
3132

3233
protected function tearDown(): void {

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: 63 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,65 @@ 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->getEmailValidatorWithStrictEmailCheck(),
2204+
$this->trustedServers,
2205+
$this->currentUser,
2206+
])
2207+
->onlyMethods(['canAccessShare', 'formatShare'])
2208+
->getMock();
2209+
2210+
$ocs->method('canAccessShare')->willReturn(true);
2211+
$ocs->method('formatShare')->with($share)->willReturn([
2212+
'id' => '42',
2213+
'share_type' => IShare::TYPE_REMOTE,
2214+
]);
2215+
2216+
$this->shareManager
2217+
->method('getShareById')
2218+
->willReturnCallback(function (string $id, string $recipient) use ($share) {
2219+
$this->assertSame($this->currentUser, $recipient);
2220+
if ($id === 'ocFederatedSharing:42') {
2221+
return $share;
2222+
}
2223+
2224+
throw new ShareNotFound();
2225+
});
2226+
2227+
$this->assertSame([
2228+
[
2229+
'id' => '42',
2230+
'share_type' => IShare::TYPE_REMOTE,
2231+
],
2232+
], $ocs->getShare('42')->getData());
2233+
}
2234+
21722235

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

0 commit comments

Comments
 (0)