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 <coding@schilljs.com>
pull/52404/head
Joas Schilling 1 year ago
parent 94538c11c7
commit 4fc5eaeff0
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
  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