Skip to content

Commit b6729aa

Browse files
nickvergessenbackportbot[bot]
authored andcommitted
fix(federation): Allow federation file sharing when federation app is disabled
The app id might be misleading, the federation app is for syncing addressbooks with trusted servers. It is not always enabled and show not have to be. Signed-off-by: Joas Schilling <[email protected]>
1 parent f3ecf43 commit b6729aa

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

apps/cloud_federation_api/lib/Config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\CloudFederationAPI;
77

88
use OCP\Federation\ICloudFederationProviderManager;
9+
use Psr\Log\LoggerInterface;
910

1011
/**
1112
* Class config
@@ -18,6 +19,7 @@ class Config {
1819

1920
public function __construct(
2021
private ICloudFederationProviderManager $cloudFederationProviderManager,
22+
private LoggerInterface $logger,
2123
) {
2224
}
2325

@@ -32,6 +34,7 @@ public function getSupportedShareTypes($resourceType) {
3234
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
3335
return $provider->getSupportedShareTypes();
3436
} catch (\Exception $e) {
37+
$this->logger->error('Failed to create federation provider', ['exception' => $e]);
3538
return [];
3639
}
3740
}

apps/cloud_federation_api/lib/Controller/RequestHandlerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private function confirmNotificationEntry(?IIncomingSignedRequest $signedRequest
452452
*/
453453
private function getHostFromFederationId(string $entry): string {
454454
if (!str_contains($entry, '@')) {
455-
throw new IncomingRequestException('entry ' . $entry . ' does not contains @');
455+
throw new IncomingRequestException('entry ' . $entry . ' does not contain @');
456456
}
457457
$rightPart = substr($entry, strrpos($entry, '@') + 1);
458458

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function __construct(
6767
private LoggerInterface $logger,
6868
private IFilenameValidator $filenameValidator,
6969
private readonly IProviderFactory $shareProviderFactory,
70-
private TrustedServers $trustedServers,
7170
) {
7271
}
7372

@@ -156,6 +155,17 @@ public function shareReceived(ICloudFederationShare $share) {
156155
// get DisplayName about the owner of the share
157156
$ownerDisplayName = $this->getUserDisplayName($ownerFederatedId);
158157

158+
$trustedServers = null;
159+
if ($this->appManager->isEnabledForAnyone('federation')
160+
&& class_exists(TrustedServers::class)) {
161+
try {
162+
$trustedServers = Server::get(TrustedServers::class);
163+
} catch (\Throwable $e) {
164+
$this->logger->debug('Failed to create TrustedServers', ['exception' => $e]);
165+
}
166+
}
167+
168+
159169
if ($shareType === IShare::TYPE_USER) {
160170
$event = $this->activityManager->generateEvent();
161171
$event->setApp('files_sharing')
@@ -167,7 +177,7 @@ public function shareReceived(ICloudFederationShare $share) {
167177
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
168178

169179
// If auto-accept is enabled, accept the share
170-
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
180+
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
171181
$this->externalShareManager->acceptShare($shareId, $shareWith);
172182
}
173183
} else {
@@ -183,7 +193,7 @@ public function shareReceived(ICloudFederationShare $share) {
183193
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
184194

185195
// If auto-accept is enabled, accept the share
186-
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
196+
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
187197
$this->externalShareManager->acceptShare($shareId, $user->getUID());
188198
}
189199
}

0 commit comments

Comments
 (0)