Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,8 @@ private function getShareById(string $id): IShare {
'sciencemesh' => IShare::TYPE_SCIENCEMESH,
];

// 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
}

Expand Down Expand Up @@ -1888,14 +1888,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
);
Expand Down Expand Up @@ -2033,12 +2033,12 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
$sciencemeshShares = $this->shareManager->getSharesBy($this->userId, IShare::TYPE_SCIENCEMESH, $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 = [];
Expand Down
62 changes: 62 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ public function dataGetShares() {
$file1EmailShareOwnerExpected,
$file1CircleShareOwnerExpected,
$file1RoomShareOwnerExpected,
$file1RemoteShareOwnerExpected,
$file1RemoteGroupShareOwnerExpected,
]
],
[
Expand Down Expand Up @@ -1433,6 +1435,8 @@ public function dataGetShares() {
$file1EmailShareOwnerExpected,
$file1CircleShareOwnerExpected,
$file1RoomShareOwnerExpected,
$file1RemoteShareOwnerExpected,
$file1RemoteGroupShareOwnerExpected,
]
],
[
Expand Down Expand Up @@ -2068,6 +2072,64 @@ 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->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);
Expand Down
Loading