Merge pull request #52404 from nextcloud/bugfix/49973/allow-federated-filesharing-without-federation-app

fix(federation): Allow federation file sharing when federation app is…
pull/52429/head
Joas Schilling 6 months ago committed by GitHub
commit 0c3ebbfed5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      apps/cloud_federation_api/lib/Config.php
  2. 2
      apps/cloud_federation_api/lib/Controller/RequestHandlerController.php
  3. 16
      apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

@ -6,6 +6,7 @@
namespace OCA\CloudFederationAPI;
use OCP\Federation\ICloudFederationProviderManager;
use Psr\Log\LoggerInterface;
/**
* Class config
@ -18,6 +19,7 @@ class Config {
public function __construct(
private ICloudFederationProviderManager $cloudFederationProviderManager,
private LoggerInterface $logger,
) {
}
@ -32,6 +34,7 @@ class Config {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
return $provider->getSupportedShareTypes();
} catch (\Exception $e) {
$this->logger->error('Failed to create federation provider', ['exception' => $e]);
return [];
}
}

@ -452,7 +452,7 @@ class RequestHandlerController extends Controller {
*/
private function getHostFromFederationId(string $entry): string {
if (!str_contains($entry, '@')) {
throw new IncomingRequestException('entry ' . $entry . ' does not contains @');
throw new IncomingRequestException('entry ' . $entry . ' does not contain @');
}
$rightPart = substr($entry, strrpos($entry, '@') + 1);

@ -67,7 +67,6 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
private LoggerInterface $logger,
private IFilenameValidator $filenameValidator,
private readonly IProviderFactory $shareProviderFactory,
private TrustedServers $trustedServers,
) {
}
@ -156,6 +155,17 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
// get DisplayName about the owner of the share
$ownerDisplayName = $this->getUserDisplayName($ownerFederatedId);
$trustedServers = null;
if ($this->appManager->isEnabledForAnyone('federation')
&& class_exists(TrustedServers::class)) {
try {
$trustedServers = Server::get(TrustedServers::class);
} catch (\Throwable $e) {
$this->logger->debug('Failed to create TrustedServers', ['exception' => $e]);
}
}
if ($shareType === IShare::TYPE_USER) {
$event = $this->activityManager->generateEvent();
$event->setApp('files_sharing')
@ -167,7 +177,7 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
// If auto-accept is enabled, accept the share
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
$this->externalShareManager->acceptShare($shareId, $shareWith);
}
} else {
@ -183,7 +193,7 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
// If auto-accept is enabled, accept the share
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
$this->externalShareManager->acceptShare($shareId, $user->getUID());
}
}

Loading…
Cancel
Save